summaryrefslogtreecommitdiffstats
path: root/sca-java-1.x/branches/sca-android/modules
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-11-11 23:05:59 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2009-11-11 23:05:59 +0000
commit5e520b1b65c79cd828057cb628b9367acb266880 (patch)
tree645361ececb1a50c2fe0260beca5c1169d0e197b /sca-java-1.x/branches/sca-android/modules
parent00c625535fe93a57d605c8988147b77207d43fad (diff)
Moving 1.x branches
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835117 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-1.x/branches/sca-android/modules')
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/pom.xml141
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java905
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java143
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeModelResolver.java95
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java373
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java229
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeModelResolver.java83
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java1219
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConfiguredOperationProcessor.java109
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java97
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java140
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeModelResolver.java83
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java273
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java256
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicyAttachPointProcessor.java266
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor21
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor21
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver20
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties29
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java148
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java145
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java207
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java88
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAttributeTestCase.java108
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java161
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java97
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java61
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestPolicyProcessor.java73
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestReadWriteUnkonwnElement.java60
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingFactoryImpl.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingImpl.java213
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java147
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java160
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteNamespacesTestCase.java91
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite59
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorComponent.constrainingType34
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorExtended.composite54
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorImpl.componentType31
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/JavaScriptReference.composite37
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/NestedCalculator.composite29
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/RMIBindingTest.composite43
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllCalculator.composite128
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite56
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllPolicyCalculator.composite129
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/another_test_definitions.xml97
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/test_definitions.xml175
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/LICENSE244
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/NOTICE12
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/pom.xml49
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-all.xsd33
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-binding-ejb.xsd43
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-binding-jms.xsd139
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-binding-sca.xsd23
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-binding-webservice.xsd26
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-contributions.xsd45
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-core.xsd348
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-definitions.xsd25
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-bpel.xsd43
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-composite.xsd23
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-cpp.xsd53
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-ejb.xsd25
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-java.xsd24
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-spring.xsd24
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-web.xsd24
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-interface-cpp.xsd40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-interface-java.xsd23
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-interface-wsdl.xsd23
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-policy.xsd77
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca.xsd24
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-atom.xsd41
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-dwr.xsd40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-http.xsd40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-jsonrpc.xsd40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-notification.xsd42
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rmi.xsd43
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rss.xsd41
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-data-helper.xsd44
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-das.xsd46
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-data-xml.xsd45
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-node.xsd43
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-notification.xsd42
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-osgi.xsd43
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-resource.xsd42
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-script.xsd43
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-widget.xsd42
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-xquery.xsd42
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca.xsd46
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/pom.xml76
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractContract.java77
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractProperty.java124
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractReference.java43
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractService.java28
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AssemblyFactory.java155
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Base.java43
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Binding.java63
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Component.java132
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentProperty.java88
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.java83
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentService.java59
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentType.java77
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Composite.java110
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeReference.java37
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeService.java56
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ConfiguredOperation.java61
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ConstrainingType.java72
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Contract.java95
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultAssemblyFactory.java31
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultEndpointFactory.java32
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint.java167
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointFactory.java37
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extensible.java37
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Implementation.java27
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Multiplicity.java49
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OperationsConfigurator.java33
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OptimizableBinding.java66
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Property.java41
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.java74
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABinding.java27
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABindingFactory.java36
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Service.java29
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Wire.java67
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/AutomaticBinding.java39
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilder.java42
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilderExtension.java44
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ComponentPreProcessor.java33
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilder.java40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderException.java45
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultEndpointBuilder.java34
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DomainBuilder.java80
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/EndpointBuilder.java40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java1337
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java1149
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingConfigurationUtil.java146
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentConfigurationBuilderImpl.java68
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java71
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionWireBuilderImpl.java165
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java44
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceBindingBuilderImpl.java76
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java99
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java68
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java223
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeCloneBuilderImpl.java118
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java110
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePolicyBuilderImpl.java47
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePromotionBuilderImpl.java46
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java224
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java96
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java71
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceConfigurationBuilderImpl.java194
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServicePromotionBuilderImpl.java77
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointBuilderImpl.java127
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyConfigurationException.java38
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyConfigurationUtil.java752
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtil.java273
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ProblemImpl.java132
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java213
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceConfigurationUtil.java264
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ServiceConfigurationUtil.java88
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractPropertyImpl.java114
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractReferenceImpl.java46
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractServiceImpl.java36
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AssemblyFactoryImpl.java121
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/BaseImpl.java45
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CallbackImpl.java82
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java174
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java93
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.java113
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentServiceImpl.java71
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentTypeImpl.java115
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeImpl.java153
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeReferenceImpl.java51
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeServiceImpl.java62
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConfiguredOperationImpl.java93
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConstrainingTypeImpl.java105
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ContractImpl.java96
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointFactoryImpl.java41
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointImpl.java154
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensibleImpl.java44
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ImplementationImpl.java75
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/PropertyImpl.java59
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.java133
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ServiceImpl.java107
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/WireImpl.java96
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.AssemblyFactory18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.EndpointFactory18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/resources/assembly-validation-messages.properties62
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/main/resources/assembly-validation-messages_it.properties30
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/AssemblyFactoryTestCase.java209
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestBinding.java56
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestImplementation.java61
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterface.java42
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterfaceContract.java41
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestOperation.java30
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.java128
-rw-r--r--sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtilTestCase.java229
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca-xml/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca-xml/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca-xml/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca-xml/pom.xml77
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/main/java/org/apache/tuscany/sca/binding/sca/xml/SCABindingProcessor.java133
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor19
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java108
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/WriteTestCase.java77
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/test/resources/Calculator.composite59
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/test/resources/CalculatorServiceImpl.componentType33
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca/pom.xml93
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/DistributedSCABinding.java37
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/SCABindingDefinitionsProvider.java73
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/DistributedSCABindingImpl.java116
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RemoteBindingHelper.java43
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProvider.java61
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProviderFactory.java62
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java236
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAServiceBindingProvider.java154
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingFactoryImpl.java40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.java223
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingInvoker.java71
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.SCABindingFactory18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory19
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider19
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/resources/org/apache/tuscany/sca/binding/sca/definitions.xml26
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca/src/test/java/org/apace/tuscany/sca/binding/sca/SCABindingTestCase.java113
-rw-r--r--sca-java-1.x/branches/sca-android/modules/binding-sca/src/test/resources/Calculator.composite52
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/pom.xml76
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/FolderContributionProcessor.java156
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/JarContributionProcessor.java123
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryImpl.java399
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java584
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImpl.java120
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/FileHelper.java701
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/IOHelper.java190
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessor19
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/resources/contribution-impl-validation-messages.properties28
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/FolderContributionPackageProcessorTestCase.java46
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/JarContributionPackageProcessorTestCase.java55
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java114
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverTestCase.java86
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java126
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java58
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContributionRepositoryTestCase.java81
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/PackageTypeDescriberImplTestCase.java63
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/resources/deployables/sample-calculator.jarbin0 -> 26901 bytes
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/resources/repository/sample-calculator.jarbin0 -> 29164 bytes
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/resources/test.composite22
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/resources/test.ext0
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/pom.xml77
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultJavaImportExportFactory.java30
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaExport.java43
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImport.java58
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImportExportFactory.java42
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java161
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java158
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ContributionClassLoader.java385
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportImpl.java58
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportModelResolver.java76
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java143
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportFactoryImpl.java41
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportListener.java157
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportImpl.java110
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportModelResolver.java62
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java148
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.JavaImportExportFactory18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor19
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/resources/contribution-java-validation-messages.properties22
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java70
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ContributionClassLoaderTestCase.java262
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java103
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java105
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-java/src/test/resources/deployables/sample-calculator.jarbin0 -> 26901 bytes
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-xml/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-xml/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-xml/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-xml/pom.xml70
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionGeneratedMetadataDocumentProcessor.java50
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java131
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java217
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionModelResolver.java72
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor19
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor20
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties23
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java141
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/pom.xml69
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.java86
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Constants.java30
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContentType.java40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java116
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionFactory.java73
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionMetadata.java55
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultContributionFactory.java32
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultExport.java30
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultImport.java30
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultModelFactoryExtensionPoint.java130
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DeployedArtifact.java29
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Export.java47
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Import.java56
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ModelFactoryExtensionPoint.java54
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/PackageType.java42
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.java103
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionFactoryImpl.java67
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java154
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionMetadataImpl.java64
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultExportImpl.java45
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultImportImpl.java55
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java48
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessorExtensionPoint.java58
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java539
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java66
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.java129
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java388
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java327
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java242
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultUnknownElementProcessor.java272
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java313
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidationSchemaExtensionPoint.java95
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensiblePackageProcessor.java99
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java256
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java224
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java143
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessor.java70
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessorExtensionPoint.java50
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java61
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java29
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessor.java63
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessorExtensionPoint.java29
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java51
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessorExtensionPoint.java29
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLInputFactory.java42
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLStreamReader.java388
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidationSchemaExtensionPoint.java52
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ClassReference.java107
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultDelegatingModelResolver.java68
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportAllModelResolver.java80
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportModelResolver.java69
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java66
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java114
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java201
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.java69
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolverExtensionPoint.java52
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ResolverExtension.java45
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ResourceReference.java103
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScanner.java65
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScannerExtensionPoint.java50
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/DefaultContributionScannerExtensionPoint.java125
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionException.java45
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionListener.java58
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionListenerExtensionPoint.java44
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionReadException.java94
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRepository.java128
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionResolveException.java41
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRuntimeException.java44
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionService.java137
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionWriteException.java61
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/DefaultContributionListenerExtensionPoint.java118
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ExtensibleContributionListener.java77
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/TypeDescriber.java38
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnrecognizedElementException.java48
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedContentTypeException.java42
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedPackageTypeException.java39
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.ContributionFactory18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ContributionPostProcessorExtensionPoint18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessorExtensionPoint18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.scanner.ContributionScannerExtensionPoint18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListenerExtensionPoint18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/contribution-validation-messages.properties31
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-databinding/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-databinding/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-databinding/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-databinding/pom.xml108
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java102
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java210
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Array2ArrayTransformer.java110
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReference2XMLStreamReader.java75
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceDataBinding.java43
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceTypeHelper.java75
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceXMLAdapter.java61
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java114
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java279
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java257
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/XMLStreamReader2CallableReference.java100
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java195
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java264
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.java268
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java89
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/transformers/IDLTransformerTestCaseFIXME.java229
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/pom.xml116
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/doc/Context Model.emx673
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ComponentContextFactory.java38
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ContextFactoryExtensionPoint.java50
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPoint.java114
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/PropertyValueFactory.java40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/RequestContextFactory.java33
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/DefaultEndpointResolverFactoryExtensionPoint.java180
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolver.java55
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolverFactory.java44
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolverFactoryExtensionPoint.java57
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/Event.java33
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventFilter.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventPublisher.java55
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/RuntimeEventListener.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/TrueFilter.java37
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/DataExchangeSemantics.java34
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Interceptor.java40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.java112
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Invoker.java36
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Message.java124
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/MessageFactory.java36
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Phase.java59
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/management/ManagementService.java39
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BindingProviderFactory.java60
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java362
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultSCADefinitionsProviderExtensionPoint.java91
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProvider.java68
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProviderFactory.java42
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyImplementor.java38
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProvider.java41
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProviderFactory.java63
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactory.java36
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactoryExtensionPoint.java63
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ReferenceBindingProvider.java76
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProvider.java33
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProviderException.java30
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProviderExtensionPoint.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ServiceBindingProvider.java63
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultWireProcessorExtensionPoint.java63
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReference.java93
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ReferenceParameters.java69
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponent.java83
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java104
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java119
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.java138
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.java101
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessor.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessorExtensionPoint.java53
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/DuplicateRecordException.java56
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/RecoveryListener.java46
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/Store.java96
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreException.java57
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreExpirationEvent.java71
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreMonitor.java71
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreReadException.java56
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreWriteException.java56
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/NotificationListener.java67
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkScheduler.java58
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkSchedulerException.java59
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.context.ContextFactoryExtensionPoint18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.endpointresolver.EndpointResolverFactoryExtensionPoint18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProviderExtensionPoint19
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/test/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPointTestCase.java208
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core-spi/src/test/java/org/apache/tuscany/sca/event/TrueFilterTestCase.java63
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/pom.xml107
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ActivationException.java37
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivator.java154
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivatorImpl.java1101
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointReferenceImpl.java186
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointWireImpl.java167
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ReferenceParameterProcessor.java101
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ReferenceParametersImpl.java139
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java53
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentImpl.java111
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentReferenceImpl.java155
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentServiceImpl.java163
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java378
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java605
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java320
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java403
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/DefaultComponentContextFactory.java70
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/InstanceWrapper.java48
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/RequestContextImpl.java105
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ServiceReferenceImpl.java133
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationListener.java40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManager.java71
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManagerImpl.java216
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationState.java29
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversation.java66
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversationImpl.java265
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/BaseEventPublisher.java89
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStart.java54
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStop.java53
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationEnd.java53
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationStart.java52
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionEnd.java53
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionStart.java52
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestEnd.java45
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestStart.java45
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/factory/ObjectCreationException.java47
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/factory/ObjectFactory.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java63
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java57
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceImpl.java268
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceObjectFactory.java48
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.java47
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java151
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/DefaultProxyFactoryExtensionPoint.java74
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleProxyFactory.java113
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleWireProcessor.java44
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java190
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java110
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java516
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyFactory.java103
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageFactoryImpl.java36
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java109
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NoMethodForOperationException.java43
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java194
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseManager.java248
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseSorter.java236
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyCreationException.java48
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java87
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactoryExtensionPoint.java53
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java245
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/TargetInvocationException.java45
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java72
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.java54
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java200
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java77
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainerFactory.java37
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java290
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainerFactory.java44
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainer.java83
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainerFactory.java41
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.java86
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainerFactory.java37
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/Scope.java66
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeContainer.java159
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeContainerFactory.java32
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistry.java43
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistryImpl.java62
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopedImplementationProvider.java65
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopedRuntimeComponent.java40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.java55
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainerFactory.java37
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetDestructionException.java44
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetInitializationException.java44
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetNotFoundException.java44
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetResolutionException.java44
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/store/MemoryStore.java195
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237Work.java65
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237WorkScheduler.java198
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java235
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEventImpl.java76
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItemImpl.java169
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor19
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.conversation.ConversationManager18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.invocation.MessageFactory18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.work.WorkScheduler18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistryTestCase.java52
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/event/BaseEventPublisherTestCase.java98
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/event/EventTestCase.java69
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseManagerTestCase.java51
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseSorterTestCase.java63
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainerTestCase.java69
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/store/MemoryStoreTestCase.java165
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java62
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java93
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.java74
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/FailingWork.java50
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyFailingRunnable.java43
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyRunnable.java71
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyRunnerListener.java154
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/Jsr237WorkSchedulerTestCase.java240
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TestWorkListener.java156
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManagerTestCase.java243
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TimeDelayWork.java87
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/scope/ScopeTestCase.java61
-rw-r--r--sca-java-1.x/branches/sca-android/modules/core/src/test/resources/META-INF/services/org.apache.tuscany.sca.invocation.PhaseTest22
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/LICENSE244
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/pom.xml108
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBinding.java104
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBindingExtensionPoint.java74
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipe.java46
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipeTransformer.java29
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java268
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultTransformerExtensionPoint.java306
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.java68
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PullTransformer.java38
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PushTransformer.java36
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/SimpleTypeMapper.java46
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationContext.java95
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationException.java65
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Transformer.java51
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformerExtensionPoint.java81
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/WrapperHandler.java78
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/XMLTypeHelper.java68
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataBinding.java56
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataType.java43
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/externalizable/ExternalizableDataBinding.java40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseDataBinding.java133
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseTransformer.java52
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java163
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DirectedGraph.java452
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Group2GroupTransformer.java94
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/GroupDataBinding.java103
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Java2SimpleTypeTransformer.java70
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java182
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/PipedTransformer.java70
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleType2JavaTransformer.java89
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleTypeMapperImpl.java401
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/TransformationContextImpl.java113
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/XSDDataTypeConverter.java945
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/DOMNode2JavaBeanTransformer.java97
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/Java2XMLMapperException.java69
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2DOMNodeTransformer.java79
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLStreamReaderTransformer.java68
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLTransformer.java262
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java139
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaExceptionDataBinding.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/SimpleJavaDataBinding.java79
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaBeanTransformer.java329
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaMapperException.java76
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/DataTypeHelper.java165
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/LRUCache.java88
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/BeanXMLStreamReaderImpl.java296
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMDataBinding.java72
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMWrapperHandler.java141
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXMLStreamReader.java36
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXmlNodeImpl.java156
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DelegatingNamespaceContext.java310
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2Node.java67
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2SAX.java65
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2Node.java69
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2SAX.java64
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValueArrayStreamReader.java403
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValuePairStreamReader.java347
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NamedProperty.java59
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NilElementStreamReader.java279
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2OutputStream.java68
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2SimpleJavaType.java45
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2SourceTransformer.java61
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2String.java62
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2Writer.java67
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2XMLStreamReader.java64
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2Node.java67
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2SAX.java60
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOM.java246
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOMPipe.java81
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SimpleJavaType2Node.java71
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SimpleXmlNodeImpl.java112
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2NodeTransformer.java69
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2ResultTransformer.java63
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2StringTransformer.java68
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAX2SAXAdapter.java256
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAXDataBinding.java54
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAXHelper.java86
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StreamDataPipe.java65
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2Node.java60
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2SAX.java61
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2SourceTransformer.java62
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2XMLStreamReader.java55
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/WrappingXMLStreamReader.java100
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Writer2ReaderDataPipe.java63
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLDocumentStreamReader.java482
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLFragmentStreamReader.java53
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLFragmentStreamReaderImpl.java857
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLGroupDataBinding.java57
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamReader2Node.java75
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamReader2SAX.java70
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamReader2String.java57
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamSerializer.java287
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamable.java37
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStringDataBinding.java51
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlNode.java69
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlNodeIterator.java355
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderImpl.java531
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding25
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBindingExtensionPoint18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer26
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.TransformerExtensionPoint18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DOMHelperTestCase.java58
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DataBindingExtensionTestCase.java86
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/SimpleTypeMapperExtensionTestCase.java124
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/TransformerExtensionTestCase.java77
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/XSDDataTypeConverterTestCase.java64
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingRegistryImplTestCase.java103
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingTestCase.java49
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DirectedGraphTestCase.java125
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/MediatorImplTestCase.java122
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/TransformerRegistryImplTestCase.java109
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/XMLDocumentStreamReaderTestCase.java57
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/BeanXMLStreamReaderTestCase.java192
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DOM2StAXTestCase.java108
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DataPipeTestCase.java93
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/JavaBean2XMLStreamReaderTestCase.java144
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/Node2StringTestCase.java39
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/PushTransformationTestCase.java86
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/StAXHelperTestCase.java55
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/TraxTransformerTestCase.java101
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderTestCase.java199
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/test/resources/org/apache/tuscany/sca/databinding/impl/ipo.xsd136
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/test/resources/org/apache/tuscany/sca/databinding/impl/order.wsdl76
-rw-r--r--sca-java-1.x/branches/sca-android/modules/databinding/src/test/resources/org/apache/tuscany/sca/databinding/xml/foo.xml22
-rw-r--r--sca-java-1.x/branches/sca-android/modules/definitions-xml/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/definitions-xml/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/definitions-xml/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/definitions-xml/pom.xml82
-rw-r--r--sca-java-1.x/branches/sca-android/modules/definitions-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/SCADefinitionsDocumentProcessor.java197
-rw-r--r--sca-java-1.x/branches/sca-android/modules/definitions-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/SCADefinitionsProcessor.java257
-rw-r--r--sca-java-1.x/branches/sca-android/modules/definitions-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor19
-rw-r--r--sca-java-1.x/branches/sca-android/modules/definitions-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor19
-rw-r--r--sca-java-1.x/branches/sca-android/modules/definitions-xml/src/main/resources/definitions-xml-validation-messages.properties22
-rw-r--r--sca-java-1.x/branches/sca-android/modules/definitions-xml/src/test/java/org/apache/tuscany/sca/definitions/Policy.java33
-rw-r--r--sca-java-1.x/branches/sca-android/modules/definitions-xml/src/test/java/org/apache/tuscany/sca/definitions/ReadDocumentTestCase.java190
-rw-r--r--sca-java-1.x/branches/sca-android/modules/definitions-xml/src/test/java/org/apache/tuscany/sca/definitions/TestPolicyProcessor.java75
-rw-r--r--sca-java-1.x/branches/sca-android/modules/definitions-xml/src/test/resources/org/apache/tuscany/sca/definitions/test_definitions.xml255
-rw-r--r--sca-java-1.x/branches/sca-android/modules/definitions/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/definitions/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/definitions/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/definitions/pom.xml70
-rw-r--r--sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitions.java82
-rw-r--r--sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitionsBuilder.java34
-rw-r--r--sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitionsBuilderException.java43
-rw-r--r--sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitionsBuilderImpl.java309
-rw-r--r--sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/impl/SCADefinitionsImpl.java71
-rw-r--r--sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/util/SCADefinitionsUtil.java87
-rw-r--r--sca-java-1.x/branches/sca-android/modules/endpoint/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/endpoint/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/endpoint/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/endpoint/pom.xml122
-rw-r--r--sca-java-1.x/branches/sca-android/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointResolverFactoryImpl.java49
-rw-r--r--sca-java-1.x/branches/sca-android/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointResolverImpl.java112
-rw-r--r--sca-java-1.x/branches/sca-android/modules/endpoint/src/main/resources/META-INF/services/org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory19
-rw-r--r--sca-java-1.x/branches/sca-android/modules/endpoint/src/main/resources/org/apache/tuscany/sca/binding/sca/definitions.xml26
-rw-r--r--sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/AddService.java28
-rw-r--r--sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/AddServiceImpl.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/CalculatorService.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/CalculatorServiceImpl.java70
-rw-r--r--sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/DivideService.java28
-rw-r--r--sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/DivideServiceImpl.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/MultiplyService.java28
-rw-r--r--sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/MultiplyServiceImpl.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/SubtractService.java28
-rw-r--r--sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/SubtractServiceImpl.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.java212
-rw-r--r--sca-java-1.x/branches/sca-android/modules/endpoint/src/test/resources/Calculator.composite52
-rw-r--r--sca-java-1.x/branches/sca-android/modules/extensibility/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/extensibility/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/extensibility/NOTICE5
-rw-r--r--sca-java-1.x/branches/sca-android/modules/extensibility/pom.xml50
-rw-r--r--sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java184
-rw-r--r--sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultModuleActivatorExtensionPoint.java92
-rw-r--r--sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultUtilityExtensionPoint.java184
-rw-r--r--sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ExtensionPointRegistry.java56
-rw-r--r--sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ModuleActivator.java60
-rw-r--r--sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ModuleActivatorExtensionPoint.java53
-rw-r--r--sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/UtilityExtensionPoint.java54
-rw-r--r--sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscoverer.java248
-rw-r--r--sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDeclaration.java68
-rw-r--r--sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscoverer.java37
-rw-r--r--sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java170
-rw-r--r--sca-java-1.x/branches/sca-android/modules/extensibility/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/extensibility/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.UtilityExtensionPoint18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/extensibility/src/test/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscovererTestCase.java72
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/pom.xml132
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomain.java226
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomainBean.java125
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCATestCaseRunner.java291
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ComponentManagerImpl.java120
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java339
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java235
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/HotUpdatableSCADomain.java389
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java385
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java275
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/management/ComponentListener.java34
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/management/ComponentManager.java48
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainBeanTestCase.java57
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainTestCase.java56
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomainTestCase.java63
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java189
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java104
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/DefaultTestImplementationFactory.java47
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestImplementation.java44
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestImplementationFactory.java37
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestService.java30
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/impl/TestImplementationImpl.java117
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/impl/TestImplementationProcessor.java96
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/module/TestModuleActivator.java65
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestImplementationProvider.java64
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestImplementationProviderFactory.java47
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestInvoker.java52
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/resources/test.composite30
-rw-r--r--sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/resources/test.txt16
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/pom.xml81
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/InstanceFactory.java43
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/InstanceFactoryProvider.java49
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceFactory.java86
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceWrapper.java56
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ArrayMultiplicityObjectFactory.java54
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ContextInjector.java32
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ConversationIDObjectFactory.java39
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/FieldInjector.java67
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InjectionRuntimeException.java45
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/Injector.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InvalidAccessorException.java43
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java325
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ListMultiplicityObjectFactory.java50
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/MethodInjector.java64
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/RequestContextObjectFactory.java55
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceHost.java46
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceNotFoundException.java51
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceObjectFactory.java87
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceResolutionException.java43
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/EventInvocationException.java47
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/EventInvoker.java34
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/InvalidConversationSequenceException.java46
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaCallbackRuntimeWireProcessor.java106
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextFactory.java40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java404
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentNameFactory.java40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java199
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProvider.java204
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProviderFactory.java76
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaInstanceFactoryProvider.java183
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaPolicyHandlingRuntimeWireProcessor.java126
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/MethodEventInvoker.java56
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/NoConversationalContractException.java34
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/PolicyHandlingInterceptor.java74
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java103
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/context/MultiplicityTestCase.java34
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceWrapperTestCase.java84
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/CallbackWireObjectFactoryTestCase.java54
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/FieldInjectorTestCase.java49
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactoryTestCase.java449
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/MethodEventInvokerTestCase.java76
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/MethodInjectorTestCase.java80
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/RequestContextObjectFactoryTestCase.java33
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/ResourceObjectFactoryTestCase.java89
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/SingletonObjectFactory.java39
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/SingletonObjectFactoryTestCase.java33
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/TestObjectFactory.java120
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/TestObjectFactoryTestCase.java77
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/Bean1.java50
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/Bean2.java51
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/Entry.java32
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/JavaIntrospectionHelperTestCase.java185
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/SuperBean.java48
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/pom.xml112
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationConstants.java36
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java315
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor19
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/main/resources/impl-javaxml-validation-messages.properties23
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/AddService.java30
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/AddServiceImpl.java37
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/CalculatorService.java36
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/CalculatorServiceImpl.java73
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/DivideService.java30
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/DivideServiceImpl.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/MultiplyService.java30
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/MultiplyServiceImpl.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/SubtractService.java30
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/SubtractServiceImpl.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/ReadTestCase.java224
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/TestModelResolver.java88
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.java64
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/resources/org/apache/tuscany/sca/implementation/java/xml/Calculator.composite66
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/resources/org/apache/tuscany/sca/implementation/java/xml/definitions.xml100
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/resources/org/apache/tuscany/sca/implementation/java/xml/definitions_with_policysets.xml133
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/pom.xml84
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/BaseJavaImplementation.java59
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/DefaultJavaImplementationFactory.java33
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/IntrospectionException.java60
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/JavaImplementation.java198
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/JavaImplementationFactory.java75
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/BaseJavaImplementationImpl.java89
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaClassIntrospectorImpl.java141
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaConstructorImpl.java53
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaElementImpl.java224
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaImplementationActivator.java86
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaImplementationFactoryImpl.java70
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaImplementationImpl.java168
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaParameterImpl.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaResourceImpl.java85
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaScopeImpl.java66
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/JavaClassVisitor.java126
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java192
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AllowsPassByReferenceProcessor.java51
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AmbiguousConstructorException.java40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/BaseJavaClassVisitor.java64
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ComponentNameProcessor.java80
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessor.java83
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ContextProcessor.java82
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessor.java70
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationProcessor.java132
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DestroyProcessor.java61
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateConstructorException.java41
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateDestructorException.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateInitException.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicatePropertyException.java34
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateReferenceException.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateResourceException.java36
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/EagerInitProcessor.java57
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java615
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalCallbackReferenceException.java40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalContextException.java40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalDestructorException.java40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalInitException.java40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalPropertyException.java40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalReferenceException.java40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalResourceException.java40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalServiceDefinitionException.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InitProcessor.java61
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidConstructorException.java36
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidConversationalImplementation.java39
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidPropertyException.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidReferenceException.java42
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidResourceException.java40
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidServiceType.java48
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JavaIntrospectionHelper.java577
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/NoConstructorException.java37
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java292
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessor.java46
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessor.java208
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/Resource.java49
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessor.java137
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ScopeProcessor.java61
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java184
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceTypeNotFoundException.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/UnknownContextTypeException.java33
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.java.JavaImplementationFactory18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractProcessorTest.java76
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessorTestCase.java169
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AllowsPassByReferenceProcessorTestCase.java71
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessorTestCase.java192
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorPropertyTestCase.java157
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorReferenceTestCase.java167
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorResourceTestCase.java152
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ContextProcessorTestCase.java201
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessorTestCase.java94
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationProcessorTestCase.java144
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConvertTimeMillisTestCase.java117
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DestroyProcessorTestCase.java129
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/EagerInitProcessorTestCase.java59
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicAndPropertyTestCase.java71
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicConstructorTestCase.java310
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessorTestCase.java562
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeutisticExtensibleConstructorTestCase.java148
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InitProcessorTestCase.java145
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JavaClassIntrospectorImplTestCase.java95
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ModelHelper.java99
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java418
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessorTestCase.java212
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessorTestCase.java221
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessorTestCase.java119
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ScopeProcessorTestCase.java113
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceCallbackTestCase.java183
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessorTestCase.java158
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/pom.xml103
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationDaemonBootstrap.java85
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncherBootstrap.java149
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncherUtil.java51
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/provider/NodeImplementationInvoker.java44
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/provider/NodeImplementationProvider.java62
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/provider/NodeImplementationProviderFactory.java49
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppRequestDispatcher.java119
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppServletHost.java392
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory19
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/test/java/org/apache/tuscany/sca/implementation/node/NodeImplementationTestCase.java48
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/test/resources/TestComposite.composite29
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/test/resources/TestNode.composite30
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node/pom.xml93
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/ConfiguredNodeImplementation.java54
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/NodeImplementation.java45
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/NodeImplementationFactory.java42
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/builder/impl/NodeCompositeBuilderImpl.java109
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/impl/ConfiguredNodeImplementationImpl.java104
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/impl/NodeImplementationFactoryImpl.java44
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/impl/NodeImplementationImpl.java97
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/xml/ConfiguredNodeImplementationProcessor.java196
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/xml/NodeImplementationProcessor.java119
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor20
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.node.NodeImplementationFactory19
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node/src/test/java/org/apache/tuscany/sca/implementation/node/builder/impl/CalculateBindingURITestCase.java587
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node/src/test/java/org/apache/tuscany/sca/implementation/node/xml/ReadTestCase.java81
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node/src/test/java/org/apache/tuscany/sca/implementation/node/xml/WriteTestCase.java65
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node/src/test/resources/org/apache/tuscany/sca/implementation/node/xml/TestComposite.composite29
-rw-r--r--sca-java-1.x/branches/sca-android/modules/implementation-node/src/test/resources/org/apache/tuscany/sca/implementation/node/xml/TestNode.composite64
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java-xml/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java-xml/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java-xml/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java-xml/pom.xml83
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaConstants.java37
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java193
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor19
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/main/resources/interface-javaxml-validation-messages.properties22
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/ReadTestCase.java100
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/WriteTestCase.java83
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/java/xml/Calculator.composite53
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/java/xml/CalculatorComponent.constrainingType34
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/java/xml/CalculatorImpl.componentType31
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java/pom.xml82
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/DefaultJavaInterfaceFactory.java99
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterface.java87
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceContract.java32
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceFactory.java82
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaOperation.java57
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceContractImpl.java39
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java73
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceImpl.java111
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java258
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java173
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaOperationImpl.java83
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/PolicyJavaInterfaceVisitor.java159
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/introspect/JavaInterfaceVisitor.java39
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtilDuplicateRemotableTestCase.java308
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtilTestCase.java121
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/ConversationalIntrospectionTestCase.java98
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/JavaInterfaceProcessorRegistryImplTestCase.java107
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/PolicyProcessorTestCase.java108
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/pom.xml57
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/ConversationSequence.java29
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/DataType.java119
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/FaultExceptionMapper.java62
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/IncompatibleInterfaceContractException.java69
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Interface.java95
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContract.java81
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java115
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidCallbackException.java34
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidInterfaceException.java41
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidOperationException.java42
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Operation.java203
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/OverloadedOperationException.java45
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/DataTypeImpl.java219
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractImpl.java128
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java303
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceImpl.java296
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/OperationImpl.java339
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/ElementInfo.java114
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/FaultException.java82
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/JavaXMLMapper.java143
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/TypeInfo.java100
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/WrapperInfo.java190
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/XMLType.java152
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.InterfaceContractMapper18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/test/java/org/apache/tuscany/sca/interfacedef/impl/ContractCompatibilityTestCase.java380
-rw-r--r--sca-java-1.x/branches/sca-android/modules/interface/src/test/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractTestCase.java69
-rw-r--r--sca-java-1.x/branches/sca-android/modules/monitor/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/monitor/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/monitor/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/monitor/pom.xml57
-rw-r--r--sca-java-1.x/branches/sca-android/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Monitor.java44
-rw-r--r--sca-java-1.x/branches/sca-android/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/MonitorFactory.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Problem.java49
-rw-r--r--sca-java-1.x/branches/sca-android/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/DefaultMonitorFactoryImpl.java41
-rw-r--r--sca-java-1.x/branches/sca-android/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/DefaultMonitorImpl.java102
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-api/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-api/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-api/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-api/pom.xml61
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCAClient.java71
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCAContribution.java54
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode.java42
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode2.java33
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode2Factory.java203
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANodeFactory.java201
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-impl/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-impl/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-impl/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-impl/pom.xml154
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/Node2FactoryImpl.java57
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/Node2Impl.java63
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java55
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java824
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java392
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBuilder.java258
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.SCANode2Factory17
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.SCANodeFactory17
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-impl/src/test/java/hello/HelloWorld.java30
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-impl/src/test/java/hello/HelloWorldImpl.java30
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/Node2ImplTestCase.java119
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java119
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-impl/src/test/resources/HelloWorld.composite30
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-impl/src/test/resources/META-INF/sca-contribution.xml23
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-launcher/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-launcher/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-launcher/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-launcher/pom.xml72
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/Contribution.java48
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/DomainManagerLauncher.java179
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/LauncherException.java55
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeDaemonLauncher.java168
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java230
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java535
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeMain.java44
-rw-r--r--sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.java130
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy-xml/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy-xml/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy-xml/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy-xml/pom.xml76
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java68
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java68
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentAttachPointTypeProcessor.java248
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java75
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyIntentProcessor.java417
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java487
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ProfileIntentProcessor.java45
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/QualifiedIntentProcessor.java45
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SimpleIntentProcessor.java45
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor24
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/resources/policy-xml-validation-messages.properties44
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java280
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/TestPolicyProcessor.java74
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/test_definitions.xml255
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/NOTICE5
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/pom.xml58
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/DefaultIntentAttachPointTypeFactory.java29
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/DefaultPolicyFactory.java30
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Intent.java116
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentAttachPoint.java52
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentAttachPointType.java71
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentAttachPointTypeFactory.java43
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentMap.java89
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Policy.java33
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicyContext.java38
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicyFactory.java69
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySet.java155
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySetAttachPoint.java48
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySetReference.java43
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/ProfileIntent.java36
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/QualifiedIntent.java41
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/BindingTypeImpl.java89
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/ImplementationTypeImpl.java88
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentAttachPointTypeFactoryImpl.java39
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentImpl.java151
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentMapImpl.java73
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyContextImpl.java93
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyFactoryImpl.java60
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicySetImpl.java149
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicySetReferenceImpl.java48
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/ProfileIntentImpl.java39
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/QualifiedIntentImpl.java50
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyComputationUtils.java418
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandler.java38
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerDefinitionsLoader.java87
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerTuple.java91
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerUtils.java64
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationException.java38
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationUtils.java111
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.PolicyFactory18
-rw-r--r--sca-java-1.x/branches/sca-android/modules/policy/src/test/java/org/apache/tuscany/sca/policy/PolicyFactoryTestCase.java50
-rw-r--r--sca-java-1.x/branches/sca-android/modules/pom.xml149
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/LICENSE205
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/META-INF/README1
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/NOTICE6
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/pom.xml54
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/CallableReference.java65
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/ComponentContext.java109
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/Constants.java34
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/Conversation.java41
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/ConversationEndedException.java67
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/NoRegisteredCallbackException.java68
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/RequestContext.java66
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/ServiceReference.java65
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/ServiceRuntimeException.java69
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/ServiceUnavailableException.java65
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/AllowsPassByReference.java39
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Authentication.java69
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Callback.java50
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/ComponentName.java36
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Confidentiality.java69
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Constructor.java36
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Context.java39
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/ConversationAttributes.java57
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/ConversationID.java36
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Conversational.java38
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Destroy.java36
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/EagerInit.java36
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/EndsConversation.java35
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Init.java37
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Integrity.java69
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Intent.java59
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/OneWay.java36
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/PolicySets.java46
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Property.java52
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Qualifier.java36
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Reference.java51
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Remotable.java37
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Requires.java57
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Scope.java49
-rw-r--r--sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Service.java48
1250 files changed, 126947 insertions, 0 deletions
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/LICENSE b/sca-java-1.x/branches/sca-android/modules/assembly-xml/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/META-INF/README b/sca-java-1.x/branches/sca-android/modules/assembly-xml/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/NOTICE b/sca-java-1.x/branches/sca-android/modules/assembly-xml/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/pom.xml b/sca-java-1.x/branches/sca-android/modules/assembly-xml/pom.xml
new file mode 100644
index 0000000000..cd439d3216
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/pom.xml
@@ -0,0 +1,141 @@
+<?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.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-assembly-xml</artifactId>
+ <name>Apache Tuscany SCA XML Assembly Model</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-definitions</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-policy</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution-namespace</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution-java</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.xml.stream</groupId>
+ <artifactId>stax-api</artifactId>
+ <version>1.0-2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ <version>3.2.1</version>
+ <scope>runtime</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-definitions-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-policy-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-policy-xml-ws</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly-xsd</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution-impl</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.assembly.xml</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.assembly.xml*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java
new file mode 100644
index 0000000000..06b208540a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java
@@ -0,0 +1,905 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import static javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI;
+import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.dom.DOMSource;
+
+import org.apache.tuscany.sca.assembly.AbstractContract;
+import org.apache.tuscany.sca.assembly.AbstractProperty;
+import org.apache.tuscany.sca.assembly.AbstractReference;
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Base;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.ConfiguredOperation;
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.assembly.Contract;
+import org.apache.tuscany.sca.assembly.Extensible;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.Multiplicity;
+import org.apache.tuscany.sca.assembly.OperationsConfigurator;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPoint;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+import org.apache.tuscany.sca.policy.impl.IntentAttachPointTypeFactoryImpl;
+import org.apache.tuscany.sca.policy.util.PolicyValidationException;
+import org.apache.tuscany.sca.policy.util.PolicyValidationUtils;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * A base class with utility methods for the other artifact processors in this module.
+ *
+ * @version $Rev$ $Date$
+ */
+abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor implements Constants {
+
+ protected ContributionFactory contributionFactory;
+ protected AssemblyFactory assemblyFactory;
+ protected PolicyFactory policyFactory;
+ protected StAXArtifactProcessor<Object> extensionProcessor;
+ protected PolicyAttachPointProcessor policyProcessor;
+ private DocumentBuilderFactory documentBuilderFactory;
+ protected IntentAttachPointTypeFactory intentAttachPointTypeFactory;
+ private Monitor monitor;
+
+ /**
+ * Constructs a new BaseArtifactProcessor.
+ * @param contribFactory
+ * @param factory
+ * @param policyFactory
+ */
+ @SuppressWarnings("unchecked")
+ public BaseAssemblyProcessor(ContributionFactory contribFactory,
+ AssemblyFactory factory,
+ PolicyFactory policyFactory,
+ StAXArtifactProcessor extensionProcessor,
+ Monitor monitor) {
+ this.assemblyFactory = factory;
+ this.policyFactory = policyFactory;
+ this.extensionProcessor = (StAXArtifactProcessor<Object>)extensionProcessor;
+ this.contributionFactory = contribFactory;
+ this.policyProcessor = new PolicyAttachPointProcessor(policyFactory);
+ this.intentAttachPointTypeFactory = new IntentAttachPointTypeFactoryImpl();
+ this.monitor = monitor;
+ }
+
+ /**
+ * Constructs a new BaseArtifactProcessor.
+ * @param factory
+ * @param policyFactory
+ */
+ @SuppressWarnings("unchecked")
+ public BaseAssemblyProcessor(AssemblyFactory factory,
+ PolicyFactory policyFactory,
+ StAXArtifactProcessor extensionProcessor,
+ Monitor monitor) {
+ this.assemblyFactory = factory;
+ this.policyFactory = policyFactory;
+ this.extensionProcessor = (StAXArtifactProcessor<Object>)extensionProcessor;
+ this.policyProcessor = new PolicyAttachPointProcessor(policyFactory);
+ this.monitor = monitor;
+
+ //TODO - this constructor should take a monitor too.
+ }
+
+ /**
+ * Marshals warnings into the monitor
+ *
+ * @param message
+ * @param model
+ * @param messageParameters
+ */
+ protected void warning(String message, Object model, String... messageParameters) {
+ if (monitor != null){
+ Problem problem = new ProblemImpl(this.getClass().getName(), "assembly-xml-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Marshals errors into the monitor
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ protected void error(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "assembly-xml-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Marshals exceptions into the monitor
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ protected void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "assembly-xml-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Start an element.
+ * @param writer
+ * @param name
+ * @param attrs
+ * @throws XMLStreamException
+ */
+ protected void writeStart(XMLStreamWriter writer, String name, XAttr... attrs) throws XMLStreamException {
+ writeStart(writer, SCA10_NS, name, attrs);
+ }
+
+ /**
+ * Start a document.
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void writeStartDocument(XMLStreamWriter writer, String name, XAttr... attrs) throws XMLStreamException {
+ writer.writeStartDocument();
+ writer.setDefaultNamespace(SCA10_NS);
+ writeStart(writer, SCA10_NS, name, attrs);
+ writer.writeDefaultNamespace(SCA10_NS);
+ }
+
+ /**
+ * Read list of reference targets
+ * @param reference
+ * @param reader
+ */
+ protected void readTargets(Reference reference, XMLStreamReader reader) {
+ String value = reader.getAttributeValue(null, TARGET);
+ ComponentService target = null;
+ if (value != null) {
+ for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
+ target = assemblyFactory.createComponentService();
+ target.setUnresolved(true);
+ target.setName(tokens.nextToken());
+ reference.getTargets().add(target);
+ }
+ }
+ }
+
+ /**
+ * Write a list of targets into an attribute
+ * @param reference
+ * @return
+ */
+ protected XAttr writeTargets(Reference reference) {
+ List<String> targets = new ArrayList<String>();
+ for (Service target : reference.getTargets()) {
+ targets.add(target.getName());
+ }
+ return new XAttr(TARGET, targets);
+ }
+
+ /**
+ * Read a multiplicity attribute.
+ * @param reference
+ * @param reader
+ */
+ protected void readMultiplicity(AbstractReference reference, XMLStreamReader reader) {
+ String value = reader.getAttributeValue(null, MULTIPLICITY);
+ if (ZERO_ONE.equals(value)) {
+ reference.setMultiplicity(Multiplicity.ZERO_ONE);
+ } else if (ONE_N.equals(value)) {
+ reference.setMultiplicity(Multiplicity.ONE_N);
+ } else if (ZERO_N.equals(value)) {
+ reference.setMultiplicity(Multiplicity.ZERO_N);
+ }
+ }
+
+ /**
+ * Returns the value of a constrainingType attribute.
+ * @param reader
+ * @return
+ */
+ protected ConstrainingType readConstrainingType(XMLStreamReader reader) {
+ QName constrainingTypeName = getQName(reader, Constants.CONSTRAINING_TYPE);
+ if (constrainingTypeName != null) {
+ ConstrainingType constrainingType = assemblyFactory.createConstrainingType();
+ constrainingType.setName(constrainingTypeName);
+ constrainingType.setUnresolved(true);
+ return constrainingType;
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Reads an abstract property element.
+ * @param property
+ * @param reader
+ * @throws XMLStreamException
+ * @throws ContributionReadException
+ */
+ protected void readAbstractProperty(AbstractProperty property, XMLStreamReader reader) throws XMLStreamException,
+ ContributionReadException {
+
+ property.setName(getString(reader, NAME));
+ property.setMany(getBoolean(reader, MANY));
+ property.setMustSupply(getBoolean(reader, MUST_SUPPLY));
+ property.setXSDElement(getQName(reader, ELEMENT));
+ property.setXSDType(getQName(reader, TYPE));
+ }
+
+ /**
+ * Resolve an implementation.
+ * @param implementation
+ * @param resolver
+ * @return
+ * @throws ContributionResolveException
+ */
+ protected Implementation resolveImplementation(Implementation implementation, ModelResolver resolver)
+ throws ContributionResolveException, PolicyValidationException {
+ if (implementation != null) {
+ if (implementation.isUnresolved()) {
+ implementation = resolver.resolveModel(Implementation.class, implementation);
+
+ // Lazily resolve implementations
+ if (implementation.isUnresolved()) {
+ extensionProcessor.resolve(implementation, resolver);
+ if (!implementation.isUnresolved()) {
+ //resolve policies
+ if ( implementation instanceof PolicySetAttachPoint ) {
+ PolicySetAttachPoint policiedImpl = (PolicySetAttachPoint)implementation;
+ resolveIntents(policiedImpl.getRequiredIntents(), resolver);
+ PolicyValidationUtils.validateIntents(policiedImpl, policiedImpl.getType());
+
+ resolvePolicySets(policiedImpl.getPolicySets(), resolver);
+ PolicyValidationUtils.validatePolicySets(policiedImpl);
+
+ if ( implementation instanceof OperationsConfigurator ) {
+ OperationsConfigurator opsConfigurator = (OperationsConfigurator)implementation;
+ for ( ConfiguredOperation implOp : opsConfigurator.getConfiguredOperations() ) {
+ resolveIntents(implOp.getRequiredIntents(), resolver);
+ PolicyValidationUtils.validateIntents(implOp, policiedImpl.getType());
+
+ resolvePolicySets(implOp.getPolicySets(), resolver);
+ PolicyValidationUtils.validatePolicySets(implOp,
+ policiedImpl.getType(),
+ policiedImpl.getApplicablePolicySets());
+ }
+ }
+
+ for ( Service service : implementation.getServices() ) {
+ resolveIntents(service.getRequiredIntents(), resolver);
+ resolvePolicySets(service.getPolicySets(), resolver);
+
+ for ( ConfiguredOperation svcOp : service.getConfiguredOperations() ) {
+ resolveIntents(svcOp.getRequiredIntents(), resolver);
+ resolvePolicySets(svcOp.getPolicySets(), resolver);
+ }
+ }
+
+ for ( Reference reference : implementation.getReferences() ) {
+ resolveIntents(reference.getRequiredIntents(), resolver);
+ resolvePolicySets(reference.getPolicySets(), resolver);
+ }
+ }
+
+ resolver.addModel(implementation);
+ }
+ }
+ }
+
+ if ( implementation instanceof IntentAttachPoint &&
+ ((IntentAttachPoint)implementation).getType() != null &&
+ ((IntentAttachPoint)implementation).getType().isUnresolved() ) {
+ ((IntentAttachPoint)implementation).setType(
+ resolver.resolveModel(IntentAttachPointType.class,
+ ((IntentAttachPoint)implementation).getType()));
+ }
+ }
+ return implementation;
+ }
+
+ /**
+ * Resolve interface, callback interface and bindings on a list of contracts.
+ * @param contracts the list of contracts
+ * @param resolver the resolver to use to resolve models
+ */
+ protected <C extends Contract> void resolveContracts(List<C> contracts, ModelResolver resolver)
+ throws ContributionResolveException {
+ resolveContracts(null, contracts, resolver);
+ }
+
+
+ /**
+ * Resolve interface, callback interface and bindings on a list of contracts.
+ * @param parent element for the contracts
+ * @param contracts the list of contracts
+ * @param resolver the resolver to use to resolve models
+ */
+ protected <C extends Contract> void resolveContracts(Base parent, List<C> contracts, ModelResolver resolver)
+ throws ContributionResolveException {
+
+ String parentName = (parent instanceof Composite) ? ((Composite)parent).getName().toString() :
+ (parent instanceof Component) ? ((Component)parent).getName() : "UNKNOWN";
+
+ for (Contract contract : contracts) {
+ try {
+ //resolve the intents and policysets as they need to be copied over into the
+ //child binding elements
+ resolveIntents(contract.getRequiredIntents(), resolver);
+ resolvePolicySets(contract.getPolicySets(), resolver);
+ resolvePolicySets(contract.getApplicablePolicySets(), resolver);
+
+ // Inherit the composite / component level applicable policy sets.
+ if ( parent != null && parent instanceof PolicySetAttachPoint ) {
+ addInheritedPolicySets(((PolicySetAttachPoint)parent).getApplicablePolicySets(), contract.getApplicablePolicySets());
+ }
+
+ for ( ConfiguredOperation confOp : contract.getConfiguredOperations() ) {
+ resolveIntents(confOp.getRequiredIntents(), resolver);
+ resolvePolicySets(confOp.getPolicySets(), resolver);
+ resolvePolicySets(confOp.getApplicablePolicySets(), resolver);
+
+ //inherit applicable policy sets from parent contract
+ addInheritedPolicySets(contract.getApplicablePolicySets(), confOp.getApplicablePolicySets());
+ }
+
+ // Resolve the interface contract
+ InterfaceContract interfaceContract = contract.getInterfaceContract();
+ if (interfaceContract != null) {
+ extensionProcessor.resolve(interfaceContract, resolver);
+ }
+
+ // Resolve bindings
+ for (int i = 0, n = contract.getBindings().size(); i < n; i++) {
+ Binding binding = contract.getBindings().get(i);
+ extensionProcessor.resolve(binding, resolver);
+
+ if (binding instanceof IntentAttachPoint) {
+ IntentAttachPoint policiedBinding = (IntentAttachPoint)binding;
+
+ if ( policiedBinding.getType() != null && policiedBinding.getType().isUnresolved() ) {
+ IntentAttachPointType resolved =
+ resolver.resolveModel(IntentAttachPointType.class,
+ policiedBinding.getType());
+ policiedBinding.setType(resolved);
+ }
+
+ resolveIntents(policiedBinding.getRequiredIntents(), resolver);
+ PolicyValidationUtils.validateIntents(policiedBinding, policiedBinding.getType());
+ }
+
+ if (binding instanceof PolicySetAttachPoint) {
+ PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)binding;
+ resolvePolicySets(policiedBinding.getPolicySets(), resolver);
+ //validate if attached policysets apply to the binding
+ resolvePolicySets(policiedBinding.getApplicablePolicySets(), resolver);
+ //inherit the applicable policysets from parent contract as whatever applies to that
+ //applies to the binding as well
+ addInheritedPolicySets(contract.getApplicablePolicySets(), policiedBinding.getApplicablePolicySets());
+ PolicyValidationUtils.validatePolicySets(policiedBinding);
+ }
+
+ if (binding instanceof OperationsConfigurator) {
+ OperationsConfigurator opConfigurator = (OperationsConfigurator)binding;
+ for (ConfiguredOperation confOp : opConfigurator.getConfiguredOperations()) {
+ resolveIntents(confOp.getRequiredIntents(), resolver);
+ PolicyValidationUtils.validateIntents(confOp, ((PolicySetAttachPoint)binding).getType());
+
+ resolvePolicySets(confOp.getPolicySets(), resolver);
+ resolvePolicySets(confOp.getApplicablePolicySets(), resolver);
+ //inherit the applicable policysets from parent binding as whatever applies to that
+ //applies to the binding as well
+ addInheritedPolicySets(((PolicySetAttachPoint)binding).getApplicablePolicySets(),
+ confOp.getApplicablePolicySets());
+ PolicyValidationUtils.validatePolicySets(confOp, ((PolicySetAttachPoint)binding).getType());
+ }
+ }
+ }
+
+ // Resolve callback bindings
+ if (contract.getCallback() != null) {
+ resolveIntents(contract.getCallback().getRequiredIntents(), resolver);
+ resolvePolicySets(contract.getCallback().getPolicySets(), resolver);
+ resolvePolicySets(contract.getCallback().getApplicablePolicySets(), resolver);
+ //inherit the contract's policy intents and policysets
+ addInheritedPolicySets(contract.getApplicablePolicySets(), contract.getCallback().getApplicablePolicySets());
+
+ for (int i = 0, n = contract.getCallback().getBindings().size(); i < n; i++) {
+ Binding binding = contract.getCallback().getBindings().get(i);
+ extensionProcessor.resolve(binding, resolver);
+
+ if (binding instanceof IntentAttachPoint) {
+ IntentAttachPoint policiedBinding = (IntentAttachPoint)binding;
+
+ if ( policiedBinding.getType().isUnresolved() ) {
+ IntentAttachPointType resolved =
+ resolver.resolveModel(IntentAttachPointType.class,
+ policiedBinding.getType());
+ policiedBinding.setType(resolved);
+ }
+
+ resolveIntents(policiedBinding.getRequiredIntents(), resolver);
+ PolicyValidationUtils.validateIntents(policiedBinding, policiedBinding.getType());
+ }
+
+ if (binding instanceof PolicySetAttachPoint) {
+ PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)binding;
+ resolvePolicySets(policiedBinding.getPolicySets(), resolver);
+ //validate if attached policysets apply to the binding
+ resolvePolicySets(policiedBinding.getApplicablePolicySets(), resolver);
+ //inherit the applicable policysets from parent contract as whatever applies to that
+ //applies to the binding as well
+ addInheritedPolicySets(contract.getApplicablePolicySets(), policiedBinding.getApplicablePolicySets());
+ PolicyValidationUtils.validatePolicySets(policiedBinding);
+ }
+
+ if (binding instanceof OperationsConfigurator) {
+ OperationsConfigurator opConfigurator = (OperationsConfigurator)binding;
+ for (ConfiguredOperation confOp : opConfigurator.getConfiguredOperations()) {
+ resolveIntents(confOp.getRequiredIntents(), resolver);
+ PolicyValidationUtils.validateIntents(confOp, ((PolicySetAttachPoint)binding).getType());
+
+ resolvePolicySets(confOp.getPolicySets(), resolver);
+ resolvePolicySets(confOp.getApplicablePolicySets(), resolver);
+ //inherit the applicable policysets from parent binding as whatever applies to that
+ //applies to the binding as well
+ addInheritedPolicySets(((PolicySetAttachPoint)binding).getApplicablePolicySets(),
+ confOp.getApplicablePolicySets());
+ PolicyValidationUtils.validatePolicySets(confOp, ((PolicySetAttachPoint)binding).getType());
+ }
+ }
+ }
+ }
+ } catch ( PolicyValidationException e ) {
+ error("PolicyServiceValidationException", contract, contract.getName(), parentName, e.getMessage());
+ //throw new ContributionResolveException("PolicyValidation exceptions when processing service/reference '"
+ //+ contract.getName() + "' in '" + parentName + "'");
+ }
+ }
+ }
+
+ /**
+ * Resolve interface and callback interface on a list of abstract contracts.
+ * @param contracts the list of contracts
+ * @param resolver the resolver to use to resolve models
+ */
+ protected <C extends AbstractContract> void resolveAbstractContracts(List<C> contracts, ModelResolver resolver)
+ throws ContributionResolveException {
+ for (AbstractContract contract : contracts) {
+
+ // Resolve the interface contract
+ InterfaceContract interfaceContract = contract.getInterfaceContract();
+ if (interfaceContract != null) {
+ extensionProcessor.resolve(interfaceContract, resolver);
+ }
+ }
+ }
+
+ /**
+ * Returns a constrainingType attribute.
+ * @param componentType
+ * @return
+ */
+ protected XAttr writeConstrainingType(ComponentType componentType) {
+ ConstrainingType constrainingType = componentType.getConstrainingType();
+ if (constrainingType != null)
+ return new XAttr(Constants.CONSTRAINING_TYPE, constrainingType.getName());
+ else
+ return null;
+ }
+
+ /**
+ * Read a property value into a DOM document.
+ * @param element
+ * @param type
+ * @param reader
+ * @return
+ * @throws XMLStreamException
+ * @throws ContributionReadException
+ * @throws ParserConfigurationException
+ */
+ protected Document readPropertyValue(QName element, QName type, XMLStreamReader reader) throws XMLStreamException,
+ ContributionReadException {
+
+ Document document;
+ try {
+ if (documentBuilderFactory == null) {
+ documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilderFactory.setNamespaceAware(true);
+ }
+ document = documentBuilderFactory.newDocumentBuilder().newDocument();
+ } catch (ParserConfigurationException e) {
+ ContributionReadException ce = new ContributionReadException(e);
+ error("ContributionReadException", documentBuilderFactory, ce);
+ throw ce;
+ }
+
+ // root element has no namespace and local name "value"
+ Element root = document.createElementNS(null, "value");
+ if (type != null) {
+ org.w3c.dom.Attr xsi = document.createAttributeNS(XMLNS_ATTRIBUTE_NS_URI, "xmlns:xsi");
+ xsi.setValue(W3C_XML_SCHEMA_INSTANCE_NS_URI);
+ root.setAttributeNodeNS(xsi);
+
+ String prefix = type.getPrefix();
+ if (prefix == null || prefix.length() == 0) {
+ prefix = "ns";
+ }
+
+ declareNamespace(root, prefix, type.getNamespaceURI());
+
+ org.w3c.dom.Attr xsiType = document.createAttributeNS(W3C_XML_SCHEMA_INSTANCE_NS_URI, "xsi:type");
+ xsiType.setValue(prefix + ":" + type.getLocalPart());
+ root.setAttributeNodeNS(xsiType);
+ }
+ document.appendChild(root);
+
+ loadElement(reader, root);
+ return document;
+ }
+
+ /**
+ * Create a DOM element
+ * @param document
+ * @param name
+ * @return
+ */
+ private Element createElement(Document document, QName name) {
+ String prefix = name.getPrefix();
+ String qname =
+ (prefix != null && prefix.length() > 0) ? prefix + ":" + name.getLocalPart() : name.getLocalPart();
+ return document.createElementNS(name.getNamespaceURI(), qname);
+ }
+
+ /**
+ * Declare a namespace.
+ * @param element
+ * @param prefix
+ * @param ns
+ */
+ private void declareNamespace(Element element, String prefix, String ns) {
+ if (ns == null) {
+ ns = "";
+ }
+ if (prefix == null) {
+ prefix = "";
+ }
+ String qname = null;
+ if ("".equals(prefix)) {
+ qname = "xmlns";
+ } else {
+ qname = "xmlns:" + prefix;
+ }
+ Node node = element;
+ boolean declared = false;
+ while (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
+ NamedNodeMap attrs = node.getAttributes();
+ if (attrs == null) {
+ break;
+ }
+ Node attr = attrs.getNamedItem(qname);
+ if (attr != null) {
+ declared = ns.equals(attr.getNodeValue());
+ break;
+ }
+ node = node.getParentNode();
+ }
+ if (!declared) {
+ org.w3c.dom.Attr attr = element.getOwnerDocument().createAttributeNS(XMLNS_ATTRIBUTE_NS_URI, qname);
+ attr.setValue(ns);
+ element.setAttributeNodeNS(attr);
+ }
+ }
+
+ /**
+ * Load a property value specification from an StAX stream into a DOM
+ * Document. Only elements, text and attributes are processed; all comments
+ * and other whitespace are ignored.
+ *
+ * @param reader the stream to read from
+ * @param root the DOM node to load
+ * @throws javax.xml.stream.XMLStreamException
+ */
+ private void loadElement(XMLStreamReader reader, Element root) throws XMLStreamException {
+ Document document = root.getOwnerDocument();
+ Node current = root;
+ while (true) {
+ switch (reader.next()) {
+ case XMLStreamConstants.START_ELEMENT:
+ QName name = reader.getName();
+ Element child = createElement(document, name);
+
+ // push the new element and make it the current one
+ current.appendChild(child);
+ current = child;
+
+ int count = reader.getNamespaceCount();
+ for (int i = 0; i < count; i++) {
+ String prefix = reader.getNamespacePrefix(i);
+ String ns = reader.getNamespaceURI(i);
+ declareNamespace(child, prefix, ns);
+ }
+
+ if (!"".equals(name.getNamespaceURI())) {
+ declareNamespace(child, name.getPrefix(), name.getNamespaceURI());
+ }
+
+ // add the attributes for this element
+ count = reader.getAttributeCount();
+ for (int i = 0; i < count; i++) {
+ String ns = reader.getAttributeNamespace(i);
+ String prefix = reader.getAttributePrefix(i);
+ String qname = reader.getAttributeLocalName(i);
+ String value = reader.getAttributeValue(i);
+ if (prefix != null && prefix.length() != 0) {
+ qname = prefix + ":" + qname;
+ }
+ child.setAttributeNS(ns, qname, value);
+ if (ns != null) {
+ declareNamespace(child, prefix, ns);
+ }
+ }
+
+ break;
+ case XMLStreamConstants.CDATA:
+ current.appendChild(document.createCDATASection(reader.getText()));
+ break;
+ case XMLStreamConstants.CHARACTERS:
+ current.appendChild(document.createTextNode(reader.getText()));
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ // if we are back at the root then we are done
+ if (current == root) {
+ return;
+ }
+
+ // pop the element off the stack
+ current = current.getParentNode();
+ }
+ }
+ }
+
+ /**
+ * Resolve policy intents attached to a specific SCA Artifact
+ * @param policyIntents list of policy intents
+ * @param resolver
+ */
+ protected void resolveIntents(List<Intent> policyIntents, ModelResolver resolver) {
+ List<Intent> requiredIntents = new ArrayList<Intent>();
+ Intent resolvedIntent = null;
+ for (Intent intent : policyIntents) {
+ resolvedIntent = resolver.resolveModel(Intent.class, intent);
+ requiredIntents.add(resolvedIntent);
+ }
+ policyIntents.clear();
+ policyIntents.addAll(requiredIntents);
+ }
+
+ /**
+ * Resolve policy sets attached to a specific SCA Construct
+ * @param policySets list of attached policy sets
+ * @param resolver
+ */
+ protected void resolvePolicySets(List<PolicySet> policySets, ModelResolver resolver) {
+ List<PolicySet> resolvedPolicySets = new ArrayList<PolicySet>();
+ PolicySet resolvedPolicySet = null;
+ for (PolicySet policySet : policySets) {
+ if (policySet.isUnresolved()) {
+ resolvedPolicySet = resolver.resolveModel(PolicySet.class, policySet);
+ resolvedPolicySets.add(resolvedPolicySet);
+ } else {
+ resolvedPolicySets.add(policySet);
+ }
+ }
+ policySets.clear();
+ policySets.addAll(resolvedPolicySets);
+ }
+
+ /**
+ * Write the value of a property
+ * @param document
+ * @param element
+ * @param type
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void writePropertyValue(Object propertyValue, QName element, QName type, XMLStreamWriter writer)
+ throws XMLStreamException {
+
+ if (propertyValue instanceof Document) {
+ Document document = (Document)propertyValue;
+ NodeList nodeList = document.getDocumentElement().getChildNodes();
+
+ for (int item = 0; item < nodeList.getLength(); ++item) {
+ Node node = nodeList.item(item);
+ int nodeType = node.getNodeType();
+ if (nodeType == Node.ELEMENT_NODE) {
+ XMLStreamReader reader =
+ XMLInputFactory.newInstance().createXMLStreamReader(new DOMSource(node));
+
+ while (reader.hasNext()) {
+ switch (reader.next()) {
+ case XMLStreamConstants.START_ELEMENT:
+ QName name = reader.getName();
+ writer.writeStartElement(name.getPrefix(), name.getLocalPart(), name.getNamespaceURI());
+
+ int namespaces = reader.getNamespaceCount();
+ for (int i = 0; i < namespaces; i++) {
+ String prefix = reader.getNamespacePrefix(i);
+ String ns = reader.getNamespaceURI(i);
+ writer.writeNamespace(prefix, ns);
+ }
+
+ if (!"".equals(name.getNamespaceURI())) {
+ writer.writeNamespace(name.getPrefix(), name.getNamespaceURI());
+ }
+
+ // add the attributes for this element
+ namespaces = reader.getAttributeCount();
+ for (int i = 0; i < namespaces; i++) {
+ String ns = reader.getAttributeNamespace(i);
+ String prefix = reader.getAttributePrefix(i);
+ String qname = reader.getAttributeLocalName(i);
+ String value = reader.getAttributeValue(i);
+
+ writer.writeAttribute(prefix, ns, qname, value);
+ }
+
+ break;
+ case XMLStreamConstants.CDATA:
+ writer.writeCData(reader.getText());
+ break;
+ case XMLStreamConstants.CHARACTERS:
+ writer.writeCharacters(reader.getText());
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ writer.writeEndElement();
+ break;
+ }
+ }
+ } else {
+ writer.writeCharacters(node.getTextContent());
+ }
+ }
+ }
+ }
+
+ protected void addInheritedIntents(List<Intent> sourceList, List<Intent> targetList) {
+ if (sourceList != null) {
+ targetList.addAll(sourceList);
+ }
+ }
+
+ protected void addInheritedPolicySets(List<PolicySet> sourceList, List<PolicySet> targetList) {
+ if (sourceList != null) {
+ targetList.addAll(sourceList);
+ }
+ }
+
+ /**
+ *
+ * @param reader
+ * @param elementName
+ * @param estensibleElement
+ * @param extensionAttributeProcessor
+ * @throws ContributionReadException
+ * @throws XMLStreamException
+ */
+ protected void readExtendedAttributes(XMLStreamReader reader, QName elementName, Extensible estensibleElement, StAXAttributeProcessor extensionAttributeProcessor) throws ContributionReadException, XMLStreamException {
+ for (int a = 0; a < reader.getAttributeCount(); a++) {
+ QName attributeName = reader.getAttributeName(a);
+ if( attributeName.getNamespaceURI() != null && attributeName.getNamespaceURI().length() > 0) {
+ if( ! elementName.getNamespaceURI().equals(attributeName.getNamespaceURI()) ) {
+ String attributeExtension = (String) extensionAttributeProcessor.read(attributeName, reader);
+ estensibleElement.getExtensions().add(attributeExtension);
+ }
+ }
+ }
+ }
+
+
+ /**
+ *
+ * @param attributeModel
+ * @param writer
+ * @param extensibleElement
+ * @param extensionAttributeProcessor
+ * @throws ContributionWriteException
+ * @throws XMLStreamException
+ */
+ protected void writeExtendedAttributes(XMLStreamWriter writer, Extensible extensibleElement, StAXAttributeProcessor extensionAttributeProcessor) throws ContributionWriteException, XMLStreamException {
+ for(Object o : extensibleElement.getExtensions()) {
+ //FIXME How to identify it's a extended attribute ?
+ if(o instanceof String) {
+ extensionAttributeProcessor.write(o, writer);
+ }
+ }
+ }
+
+ /*protected void validatePolicySets(PolicySetAttachPoint policySetAttachPoint)
+ throws ContributionResolveException {
+ validatePolicySets(policySetAttachPoint, policySetAttachPoint.getApplicablePolicySets());
+ }
+
+
+ protected void validatePolicySets(PolicySetAttachPoint policySetAttachPoint,
+ List<PolicySet> applicablePolicySets) throws ContributionResolveException {
+ //Since the applicablePolicySets in a policySetAttachPoint will already have the
+ //list of policysets that might ever be applicable to this attachPoint, just check
+ //if the defined policysets feature in the list of applicable policysets
+ IntentAttachPointType attachPointType = policySetAttachPoint.getType();
+ for ( PolicySet definedPolicySet : policySetAttachPoint.getPolicySets() ) {
+ if ( !definedPolicySet.isUnresolved() ) {
+ if ( !applicablePolicySets.contains(definedPolicySet)) {
+ throw new ContributionResolveException("Policy Set '" + definedPolicySet.getName()
+ + "' does not apply to binding type "
+ + attachPointType.getName());
+ }
+ } else {
+ throw new ContributionResolveException("Policy Set '" + definedPolicySet.getName()
+ + "' is not defined in this domain ");
+
+
+ }
+ }
+ }*/
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java
new file mode 100644
index 0000000000..b07c91d1b3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLConnection;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+
+/**
+ * A componentType processor.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentTypeDocumentProcessor extends BaseAssemblyProcessor implements URLArtifactProcessor<ComponentType> {
+ private XMLInputFactory inputFactory;
+
+ /**
+ * Constructs a new componentType processor.
+ * @param factory
+ * @param policyFactory
+ * @param registry
+ */
+ public ComponentTypeDocumentProcessor(StAXArtifactProcessor staxProcessor,
+ XMLInputFactory inputFactory,
+ Monitor monitor) {
+ super(null, null, staxProcessor, monitor);
+ this.inputFactory = inputFactory;
+ }
+
+ /**
+ * Constructs a new componentType processor.
+ * @param modelFactories
+ * @param staxProcessor
+ */
+ public ComponentTypeDocumentProcessor(ModelFactoryExtensionPoint modelFactories,
+ StAXArtifactProcessor staxProcessor,
+ Monitor monitor) {
+ super(null, null, staxProcessor, monitor);
+ this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class);
+ }
+
+ public ComponentType read(URL contributionURL, URI uri, URL url) throws ContributionReadException {
+ InputStream urlStream = null;
+ try {
+
+ // Create a stream reader
+ URLConnection connection = url.openConnection();
+ connection.setUseCaches(false);
+ urlStream = connection.getInputStream();
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(url.toString(), urlStream);
+ reader.nextTag();
+
+ // Reader the componentType model
+ ComponentType componentType = (ComponentType)extensionProcessor.read(reader);
+ if (componentType != null) {
+ componentType.setURI(uri.toString());
+ }
+
+ // For debugging purposes, write it back to XML
+// if (componentType != null) {
+// try {
+// ByteArrayOutputStream bos = new ByteArrayOutputStream();
+// XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
+// outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+// extensionProcessor.write(componentType, outputFactory.createXMLStreamWriter(bos));
+// Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(bos.toByteArray()));
+// OutputFormat format = new OutputFormat();
+// format.setIndenting(true);
+// format.setIndent(2);
+// XMLSerializer serializer = new XMLSerializer(System.out, format);
+// serializer.serialize(document);
+// } catch (Exception e) {
+// e.printStackTrace();
+// }
+// }
+
+ return componentType;
+
+ } catch (XMLStreamException e) {
+ ContributionReadException ce = new ContributionReadException(e);
+ error("ContributionReadException", inputFactory, ce);
+ throw ce;
+ } catch (IOException e) {
+ ContributionReadException ce = new ContributionReadException(e);
+ error("ContributionReadException", inputFactory, ce);
+ throw ce;
+ } finally {
+ try {
+ if (urlStream != null) {
+ urlStream.close();
+ urlStream = null;
+ }
+ } catch (IOException ioe) {
+ //ignore
+ }
+ }
+ }
+
+ public void resolve(ComponentType componentType, ModelResolver resolver) throws ContributionResolveException {
+ extensionProcessor.resolve(componentType, resolver);
+ }
+
+ public String getArtifactType() {
+ return ".componentType";
+ }
+
+ public Class<ComponentType> getModelType() {
+ return ComponentType.class;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeModelResolver.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeModelResolver.java
new file mode 100644
index 0000000000..d0d11cd02b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeModelResolver.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.Import;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.java.JavaImport;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+/**
+ * A Model Resolver for ComponentType models.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentTypeModelResolver implements ModelResolver {
+ private Contribution contribution;
+ private Map<String, ComponentType> map = new HashMap<String, ComponentType>();
+
+ public ComponentTypeModelResolver(Contribution contribution, ModelFactoryExtensionPoint modelFactories) {
+ this.contribution = contribution;
+ }
+
+ public void addModel(Object resolved) {
+ ComponentType componentType = (ComponentType)resolved;
+ map.put(componentType.getURI(), componentType);
+ }
+
+ public Object removeModel(Object resolved) {
+ return map.remove(((ComponentType)resolved).getURI());
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+
+ //get componentType artifact URI
+ String uri = ((ComponentType)unresolved).getURI();
+ if (uri == null) {
+ return (T)unresolved;
+ }
+
+ //lookup the componentType
+ ComponentType resolved = (ComponentType) map.get(uri);
+ if (resolved != null) {
+ return modelClass.cast(resolved);
+ }
+
+ //If not found, delegate the resolution to the imports (in this case based on the java imports)
+ //compute the package name from the componentType URI
+ if (unresolved instanceof ComponentType) {
+ //FIXME The core assembly model now depends on java imports to
+ // resolve componentTypes of all kinds, this is not right at all!!!
+ int s = uri.lastIndexOf('/');
+ if (s != -1) {
+ String packageName = uri.substring(0, uri.lastIndexOf("/"));
+ for (Import import_ : this.contribution.getImports()) {
+ if (import_ instanceof JavaImport) {
+ JavaImport javaImport = (JavaImport)import_;
+ //check the import location against the computed package name from the componentType URI
+ if (javaImport.getPackage().equals(packageName)) {
+ // Delegate the resolution to the import resolver
+ resolved = javaImport.getModelResolver().resolveModel(ComponentType.class, (ComponentType)unresolved);
+ if (!resolved.isUnresolved()) {
+ return modelClass.cast(resolved);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return (T)unresolved;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java
new file mode 100644
index 0000000000..9727b89aab
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java
@@ -0,0 +1,373 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Callback;
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.assembly.Contract;
+import org.apache.tuscany.sca.assembly.Extensible;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.impl.OperationImpl;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.policy.IntentAttachPoint;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+import org.w3c.dom.Document;
+
+/**
+ * A componentType processor.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentTypeProcessor extends BaseAssemblyProcessor implements StAXArtifactProcessor<ComponentType> {
+
+ /**
+ * Constructs a new componentType processor.
+ * @param factory
+ * @param policyFactory
+ * @param registry
+ */
+ public ComponentTypeProcessor(AssemblyFactory factory, PolicyFactory policyFactory,
+ StAXArtifactProcessor extensionProcessor, StAXAttributeProcessor extensionAttributeProcessor, Monitor monitor) {
+ super(factory, policyFactory, extensionProcessor, monitor);
+ }
+
+ /**
+ * Constructs a new componentType processor.
+ *
+ * @param modelFactories
+ * @param extensionProcessor
+ */
+ public ComponentTypeProcessor(ModelFactoryExtensionPoint modelFactories,
+ StAXArtifactProcessor extensionProcessor,
+ StAXAttributeProcessor extensionAttributeProcessor,
+ Monitor monitor) {
+ super(modelFactories.getFactory(AssemblyFactory.class),
+ modelFactories.getFactory(PolicyFactory.class), extensionProcessor, monitor);
+ }
+
+ public ComponentType read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ ComponentType componentType = null;
+ Service service = null;
+ Reference reference = null;
+ Contract contract = null;
+ Property property = null;
+ Callback callback = null;
+ QName name = null;
+
+ // Read the componentType document
+ while (reader.hasNext()) {
+ int event = reader.getEventType();
+ switch (event) {
+ case START_ELEMENT:
+ name = reader.getName();
+
+ if (Constants.COMPONENT_TYPE_QNAME.equals(name)) {
+
+ // Read a <componentType>
+ componentType = assemblyFactory.createComponentType();
+ componentType.setConstrainingType(readConstrainingType(reader));
+
+ } else if (Constants.SERVICE_QNAME.equals(name)) {
+
+ // Read a <service>
+ service = assemblyFactory.createService();
+ contract = service;
+ service.setName(getString(reader, Constants.NAME));
+ componentType.getServices().add(service);
+ policyProcessor.readPolicies(service, reader);
+
+ } else if (Constants.REFERENCE_QNAME.equals(name)) {
+
+ // Read a <reference>
+ reference = assemblyFactory.createReference();
+ contract = reference;
+ reference.setName(getString(reader, Constants.NAME));
+ reference.setWiredByImpl(getBoolean(reader, Constants.WIRED_BY_IMPL));
+ readMultiplicity(reference, reader);
+ readTargets(reference, reader);
+ componentType.getReferences().add(reference);
+ policyProcessor.readPolicies(reference, reader);
+
+ } else if (Constants.PROPERTY_QNAME.equals(name)) {
+
+ // Read a <property>
+ property = assemblyFactory.createProperty();
+ readAbstractProperty(property, reader);
+ policyProcessor.readPolicies(property, reader);
+
+ // Read the property value
+ Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
+ property.setValue(value);
+
+ componentType.getProperties().add(property);
+
+ } else if (Constants.IMPLEMENTATION_QNAME.equals(name)) {
+
+ // Read an <implementation> element
+ policyProcessor.readPolicies(componentType, reader);
+
+ } else if (Constants.CALLBACK_QNAME.equals(name)) {
+
+ // Read a <callback>
+ callback = assemblyFactory.createCallback();
+ contract.setCallback(callback);
+ policyProcessor.readPolicies(callback, reader);
+
+ } else if (OPERATION_QNAME.equals(name)) {
+
+ // Read an <operation>
+ Operation operation = new OperationImpl();
+ operation.setName(getString(reader, NAME));
+ operation.setUnresolved(true);
+ if (callback != null) {
+ policyProcessor.readPolicies(callback, operation, reader);
+ } else {
+ policyProcessor.readPolicies(contract, operation, reader);
+ }
+ } else {
+
+ // Read an extension element
+ Object extension = extensionProcessor.read(reader);
+ if (extension != null) {
+ if (extension instanceof InterfaceContract) {
+
+ // <service><interface> and <reference><interface>
+ contract.setInterfaceContract((InterfaceContract)extension);
+
+ } else if (extension instanceof Binding) {
+
+ // <service><binding> and <reference><binding>
+ if (callback != null) {
+ callback.getBindings().add((Binding)extension);
+ } else {
+ contract.getBindings().add((Binding)extension);
+ }
+ } else {
+
+ // Add the extension element to the current element
+ if (callback != null) {
+ callback.getExtensions().add(extension);
+ } else if (contract != null) {
+ contract.getExtensions().add(extension);
+ } else if (property != null) {
+ property.getExtensions().add(extension);
+ } else {
+ if (componentType instanceof Extensible) {
+ ((Extensible)componentType).getExtensions().add(extension);
+ }
+ }
+ }
+ }
+ }
+ break;
+
+ case END_ELEMENT:
+ name = reader.getName();
+
+ // Clear current state when reading reaching end element
+ if (SERVICE_QNAME.equals(name)) {
+ service = null;
+ contract = null;
+ } else if (REFERENCE_QNAME.equals(name)) {
+ reference = null;
+ contract = null;
+ } else if (PROPERTY_QNAME.equals(name)) {
+ property = null;
+ } else if (CALLBACK_QNAME.equals(name)) {
+ callback = null;
+ }
+ break;
+ }
+
+ // Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
+ }
+ return componentType;
+ }
+
+ public void write(ComponentType componentType, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+
+ // Write <componentType> element
+ writeStartDocument(writer, COMPONENT_TYPE,
+ writeConstrainingType(componentType));
+
+ // Write <service> elements
+ for (Service service : componentType.getServices()) {
+ writeStart(writer, SERVICE, new XAttr(NAME, service.getName()),
+ policyProcessor.writePolicies(service));
+
+ if (service.getInterfaceContract() != null) {
+ extensionProcessor.write(service.getInterfaceContract(), writer);
+ }
+
+ for (Binding binding: service.getBindings()) {
+ extensionProcessor.write(binding, writer);
+ }
+
+ if (service.getCallback() != null) {
+ Callback callback = service.getCallback();
+ writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback));
+
+ for (Binding binding: callback.getBindings()) {
+ extensionProcessor.write(binding, writer);
+ }
+ for (Object extension: callback.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ for (Object extension: service.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ // Write <reference> elements
+ for (Reference reference : componentType.getReferences()) {
+
+ writeStart(writer, REFERENCE,
+ new XAttr(NAME, reference.getName()),
+ writeTargets(reference),
+ policyProcessor.writePolicies(reference));
+
+ extensionProcessor.write(reference.getInterfaceContract(), writer);
+
+ for (Binding binding: reference.getBindings()) {
+ extensionProcessor.write(binding, writer);
+ }
+
+ if (reference.getCallback() != null) {
+ Callback callback = reference.getCallback();
+ writeStart(writer, CALLBACK,
+ policyProcessor.writePolicies(callback));
+
+ for (Binding binding: callback.getBindings()) {
+ extensionProcessor.write(binding, writer);
+ }
+ for (Object extension: callback.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ for (Object extension: reference.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ // Write <property> elements
+ for (Property property : componentType.getProperties()) {
+ writeStart(writer,
+ PROPERTY,
+ new XAttr(NAME, property.getName()),
+ new XAttr(MUST_SUPPLY, property.isMustSupply()),
+ new XAttr(MANY, property.isMany()),
+ new XAttr(TYPE, property.getXSDType()),
+ new XAttr(ELEMENT, property.getXSDElement()),
+ policyProcessor.writePolicies(property));
+
+ // Write property value
+ writePropertyValue(property.getValue(), property.getXSDElement(), property.getXSDType(), writer);
+
+ // Write extensions
+ for (Object extension : property.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ // Write extension elements
+ if (componentType instanceof Extensible) {
+ for (Object extension: ((Extensible)componentType).getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+ }
+
+ // Write <implementation> elements if the componentType has
+ // any intents or policySets
+ boolean writeImplementation = false;
+ if (componentType instanceof IntentAttachPoint) {
+ if (!((IntentAttachPoint)componentType).getRequiredIntents().isEmpty()) {
+ writeImplementation = true;
+ }
+ }
+ if (componentType instanceof PolicySetAttachPoint) {
+ if (!((PolicySetAttachPoint)componentType).getPolicySets().isEmpty()) {
+ writeImplementation = true;
+ }
+ }
+ if (writeImplementation) {
+ writeStart(writer, IMPLEMENTATION,
+ policyProcessor.writePolicies(componentType));
+ }
+
+ writeEndDocument(writer);
+ }
+
+ public void resolve(ComponentType componentType, ModelResolver resolver) throws ContributionResolveException {
+
+ // Resolve component type services and references
+ resolveContracts(componentType.getServices(), resolver);
+ resolveContracts(componentType.getReferences(), resolver);
+ if ( componentType instanceof PolicySetAttachPoint ) {
+ resolveIntents(((PolicySetAttachPoint)componentType).getRequiredIntents(), resolver);
+ resolvePolicySets(((PolicySetAttachPoint)componentType).getPolicySets(), resolver);
+ }
+ }
+
+ public QName getArtifactType() {
+ return COMPONENT_TYPE_QNAME;
+ }
+
+ public Class<ComponentType> getModelType() {
+ return ComponentType.class;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java
new file mode 100644
index 0000000000..bc74773d85
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java
@@ -0,0 +1,229 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Collection;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.util.PolicyComputationUtils;
+
+/**
+ * A composite processor.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeDocumentProcessor extends BaseAssemblyProcessor implements URLArtifactProcessor<Composite> {
+ private XMLInputFactory inputFactory;
+ private DocumentBuilderFactory documentBuilderFactory;
+ private List scaDefnSink;
+ private Collection<PolicySet> domainPolicySets = null;
+ private int scaDefnsCount = 0;
+
+ /**
+ * Construct a new composite processor
+ * @param assemblyFactory
+ * @param policyFactory
+ * @param staxProcessor
+ */
+ @Deprecated
+ public CompositeDocumentProcessor(StAXArtifactProcessor staxProcessor,
+ XMLInputFactory inputFactory,
+ List scaDefnsSink, Monitor monitor) {
+ super(null, null, staxProcessor, monitor);
+ this.inputFactory = inputFactory;
+ this.scaDefnSink = scaDefnsSink;
+ }
+
+ /**
+ * Construct a new composite processor
+ * @param assemblyFactory
+ * @param policyFactory
+ * @param staxProcessor
+ */
+ public CompositeDocumentProcessor(StAXArtifactProcessor staxProcessor,
+ XMLInputFactory inputFactory,
+ DocumentBuilderFactory documentBuilderFactory,
+ List scaDefnsSink, Monitor monitor) {
+ super(null, null, staxProcessor, monitor);
+ this.documentBuilderFactory = documentBuilderFactory;
+ this.inputFactory = inputFactory;
+ this.scaDefnSink = scaDefnsSink;
+ }
+
+ /**
+ * Constructs a new composite processor.
+ * @param modelFactories
+ * @param staxProcessor
+ */
+ public CompositeDocumentProcessor(ModelFactoryExtensionPoint modelFactories,
+ StAXArtifactProcessor staxProcessor, Monitor monitor) {
+ super(null, null, staxProcessor, monitor);
+ this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class);
+ this.documentBuilderFactory = modelFactories.getFactory(DocumentBuilderFactory.class);
+ }
+
+ public Composite read(URL contributionURL, URI uri, URL url) throws ContributionReadException {
+ InputStream scdlStream = null;
+ try {
+ URLConnection connection = url.openConnection();
+ connection.setUseCaches(false);
+ scdlStream = connection.getInputStream();
+ } catch (IOException e) {
+ ContributionReadException ce = new ContributionReadException(e);
+ error("ContributionReadException", url, ce);
+ throw ce;
+ }
+ return read(uri, scdlStream);
+ }
+
+ public Composite read(URI uri, InputStream scdlStream) throws ContributionReadException {
+ try {
+ if (scaDefnSink != null ) {
+ fillDomainPolicySets(scaDefnSink);
+ }
+
+ Composite composite = null;
+
+ byte[] transformedArtifactContent;
+ try {
+ if ( domainPolicySets != null ) {
+ transformedArtifactContent =
+ PolicyComputationUtils.addApplicablePolicySets(scdlStream, domainPolicySets, documentBuilderFactory);
+ scdlStream = new ByteArrayInputStream(transformedArtifactContent);
+ }
+ } catch ( IOException e ) {
+ ContributionReadException ce = new ContributionReadException(e);
+ error("ContributionReadException", scdlStream, ce);
+ throw ce;
+ } catch ( Exception e ) {
+ ContributionReadException ce = new ContributionReadException(e);
+ error("ContributionReadException", scdlStream, ce);
+ //throw ce;
+ }
+
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(scdlStream);
+
+ reader.nextTag();
+
+ // Read the composite model
+ composite = (Composite)extensionProcessor.read(reader);
+ if (composite != null) {
+ composite.setURI(uri.toString());
+ }
+
+ // For debugging purposes, write it back to XML
+// if (composite != null) {
+// try {
+// ByteArrayOutputStream bos = new ByteArrayOutputStream();
+// XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
+// outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+// extensionProcessor.write(composite, outputFactory.createXMLStreamWriter(bos));
+// Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(bos.toByteArray()));
+// OutputFormat format = new OutputFormat();
+// format.setIndenting(true);
+// format.setIndent(2);
+// XMLSerializer serializer = new XMLSerializer(System.out, format);
+// serializer.serialize(document);
+// } catch (Exception e) {
+// e.printStackTrace();
+// }
+// }
+
+ return composite;
+
+ } catch (XMLStreamException e) {
+ ContributionReadException ce = new ContributionReadException(e);
+ error("ContributionReadException", inputFactory, ce);
+ throw ce;
+ } finally {
+ try {
+ if (scdlStream != null) {
+ scdlStream.close();
+ scdlStream = null;
+ }
+ } catch (IOException ioe) {
+ //ignore
+ }
+ }
+ }
+
+ public void resolve(Composite composite, ModelResolver resolver) throws ContributionResolveException {
+ if (composite != null)
+ extensionProcessor.resolve(composite, resolver);
+ }
+
+ public String getArtifactType() {
+ return ".composite";
+ }
+
+ public Class<Composite> getModelType() {
+ return Composite.class;
+ }
+
+ private void fillDomainPolicySets(List scaDefnsSink) {
+ Map<QName, PolicySet> domainPolicySetMap = null;
+ if ( scaDefnsSink.size() > scaDefnsCount ) {
+ //if ( !scaDefnsSink.isEmpty() ) {
+ domainPolicySetMap = new Hashtable<QName, PolicySet>();
+
+ if ( domainPolicySets != null ) {
+ for ( PolicySet policySet : domainPolicySets ) {
+ domainPolicySetMap.put(policySet.getName(), policySet);
+ }
+ }
+
+ for ( Object object : scaDefnsSink ) {
+ if ( object instanceof SCADefinitions ) {
+ for ( PolicySet policySet : ((SCADefinitions)object).getPolicySets() ) {
+ domainPolicySetMap.put( policySet.getName(), policySet);
+ }
+ }
+ }
+ domainPolicySets = domainPolicySetMap.values();
+ //scaDefnsSink.clear();
+ scaDefnsCount = scaDefnsSink.size();
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeModelResolver.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeModelResolver.java
new file mode 100644
index 0000000000..72744259f6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeModelResolver.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.Import;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.namespace.NamespaceImport;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+/**
+ * A Model Resolver for Composite models.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeModelResolver implements ModelResolver {
+
+ private Contribution contribution;
+ private Map<QName, Composite> map = new HashMap<QName, Composite>();
+
+ public CompositeModelResolver(Contribution contribution, ModelFactoryExtensionPoint modelFactories) {
+ this.contribution = contribution;
+ }
+
+ public void addModel(Object resolved) {
+ Composite composite = (Composite)resolved;
+ map.put(composite.getName(), composite);
+ }
+
+ public Object removeModel(Object resolved) {
+ return map.remove(((Composite)resolved).getName());
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+
+ // Lookup a definition for the given namespace
+ QName qname = ((Composite)unresolved).getName();
+ Composite resolved = (Composite) map.get(qname);
+ if (resolved != null) {
+ return modelClass.cast(resolved);
+ }
+
+ // No definition found, delegate the resolution to the imports
+ for (Import import_ : this.contribution.getImports()) {
+ if (import_ instanceof NamespaceImport) {
+ NamespaceImport namespaceImport = (NamespaceImport)import_;
+ if (namespaceImport.getNamespace().equals(qname.getNamespaceURI())) {
+
+ // Delegate the resolution to the import resolver
+ resolved = namespaceImport.getModelResolver().resolveModel(Composite.class, (Composite)unresolved);
+ if (!resolved.isUnresolved()) {
+ return modelClass.cast(resolved);
+ }
+ }
+ }
+ }
+ return (T)unresolved;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java
new file mode 100644
index 0000000000..09ec7664ce
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java
@@ -0,0 +1,1219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Callback;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentProperty;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeReference;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.ConfiguredOperation;
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.assembly.Contract;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.OperationsConfigurator;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.Wire;
+import org.apache.tuscany.sca.contribution.Artifact;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ResolverExtension;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+import org.apache.tuscany.sca.policy.util.PolicyComputationUtils;
+import org.apache.tuscany.sca.policy.util.PolicyValidationException;
+import org.apache.tuscany.sca.policy.util.PolicyValidationUtils;
+import org.w3c.dom.Document;
+
+/**
+ * A composite processor.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArtifactProcessor<Composite> {
+ // FIXME: to be refactored
+ private XPathFactory xPathFactory = XPathFactory.newInstance();
+
+ protected StAXAttributeProcessor<Object> extensionAttributeProcessor;
+
+ /**
+ * Construct a new composite processor
+ *
+ * @param extensionPoints
+ * @param extensionProcessor
+ */
+ public CompositeProcessor(ExtensionPointRegistry extensionPoints,
+ StAXArtifactProcessor extensionProcessor,
+ StAXAttributeProcessor extensionAttributeProcessor,
+ Monitor monitor) {
+
+ this(modelFactories(extensionPoints),
+ extensionProcessor,
+ extensionAttributeProcessor,
+ monitor(extensionPoints));
+
+ this.extensionAttributeProcessor = extensionAttributeProcessor;
+ }
+
+ /**
+ * Constructs a new composite processor
+ *
+ * @param modelFactories
+ * @param extensionProcessor
+ * @param monitor
+ */
+ private CompositeProcessor(ModelFactoryExtensionPoint modelFactories,
+ StAXArtifactProcessor extensionProcessor,
+ StAXAttributeProcessor extensionAttributeProcessor,
+ Monitor monitor) {
+
+ super(modelFactories.getFactory(ContributionFactory.class),
+ modelFactories.getFactory(AssemblyFactory.class),
+ modelFactories.getFactory(PolicyFactory.class),
+ extensionProcessor,
+ monitor);
+
+ this.extensionAttributeProcessor = extensionAttributeProcessor;
+
+ }
+
+ /**
+ * Construct a new composite processor
+ *
+ * @param contributionFactory
+ * @param assemblyFactory
+ * @param policyFactory
+ * @param extensionProcessor
+ */
+ public CompositeProcessor(ContributionFactory contributionFactory,
+ AssemblyFactory assemblyFactory,
+ PolicyFactory policyFactory,
+ StAXArtifactProcessor extensionProcessor,
+ StAXAttributeProcessor extensionAttributeProcessor,
+ Monitor monitor) {
+ super(contributionFactory, assemblyFactory, policyFactory, extensionProcessor, monitor);
+ }
+
+ public Composite read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ Composite composite = null;
+ Composite include = null;
+ Component component = null;
+ Property property = null;
+ ComponentService componentService = null;
+ ComponentReference componentReference = null;
+ ComponentProperty componentProperty = null;
+ CompositeService compositeService = null;
+ CompositeReference compositeReference = null;
+ Contract contract = null;
+ Wire wire = null;
+ Callback callback = null;
+ QName name = null;
+
+ // Read the composite document
+ while (reader.hasNext()) {
+ int event = reader.getEventType();
+ switch (event) {
+ case START_ELEMENT:
+ name = reader.getName();
+
+ if (COMPOSITE_QNAME.equals(name)) {
+
+ // Read a <composite>
+ composite = assemblyFactory.createComposite();
+
+ composite.setName(new QName(getString(reader, TARGET_NAMESPACE), getString(reader, NAME)));
+
+ if(!isSet(reader, TARGET_NAMESPACE)){
+ // spec says that a composite must have a namespace
+ warning("NoCompositeNamespace", composite, composite.getName().toString());
+ }
+
+ if(isSet(reader, AUTOWIRE)) {
+ composite.setAutowire(getBoolean(reader, AUTOWIRE));
+ }
+
+ //handle extension attributes
+ this.readExtendedAttributes(reader, name, composite, extensionAttributeProcessor);
+
+ composite.setLocal(getBoolean(reader, LOCAL));
+ composite.setConstrainingType(readConstrainingType(reader));
+ policyProcessor.readPolicies(composite, reader);
+
+ } else if (INCLUDE_QNAME.equals(name)) {
+
+ // Read an <include>
+ include = assemblyFactory.createComposite();
+ include.setName(getQName(reader, NAME));
+ include.setURI(getString(reader, URI));
+ include.setUnresolved(true);
+ composite.getIncludes().add(include);
+
+ } else if (SERVICE_QNAME.equals(name)) {
+ if (component != null) {
+
+ // Read a <component><service>
+ componentService = assemblyFactory.createComponentService();
+ contract = componentService;
+ componentService.setName(getString(reader, NAME));
+
+ //handle extension attributes
+ this.readExtendedAttributes(reader, name, componentService, extensionAttributeProcessor);
+
+ component.getServices().add(componentService);
+ policyProcessor.readPolicies(contract, reader);
+ } else {
+
+ // Read a <composite><service>
+ compositeService = assemblyFactory.createCompositeService();
+ contract = compositeService;
+ compositeService.setName(getString(reader, NAME));
+
+ String promoted = getString(reader, PROMOTE);
+ if (promoted != null) {
+ String promotedComponentName;
+ String promotedServiceName;
+ int s = promoted.indexOf('/');
+ if (s == -1) {
+ promotedComponentName = promoted;
+ promotedServiceName = null;
+ } else {
+ promotedComponentName = promoted.substring(0, s);
+ promotedServiceName = promoted.substring(s + 1);
+ }
+
+ Component promotedComponent = assemblyFactory.createComponent();
+ promotedComponent.setUnresolved(true);
+ promotedComponent.setName(promotedComponentName);
+ compositeService.setPromotedComponent(promotedComponent);
+
+ ComponentService promotedService = assemblyFactory.createComponentService();
+ promotedService.setUnresolved(true);
+ promotedService.setName(promotedServiceName);
+ compositeService.setPromotedService(promotedService);
+ }
+
+ //handle extension attributes
+ this.readExtendedAttributes(reader, name, compositeService, extensionAttributeProcessor);
+
+ composite.getServices().add(compositeService);
+ policyProcessor.readPolicies(contract, reader);
+ }
+
+ } else if (REFERENCE_QNAME.equals(name)) {
+ if (component != null) {
+ // Read a <component><reference>
+ componentReference = assemblyFactory.createComponentReference();
+ contract = componentReference;
+ componentReference.setName(getString(reader, NAME));
+ readMultiplicity(componentReference, reader);
+ if (isSet(reader, AUTOWIRE)) {
+ componentReference.setAutowire(getBoolean(reader, AUTOWIRE));
+ }
+ readTargets(componentReference, reader);
+ componentReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
+
+ //handle extension attributes
+ this.readExtendedAttributes(reader, name, componentReference, extensionAttributeProcessor);
+
+ component.getReferences().add(componentReference);
+ policyProcessor.readPolicies(contract, reader);
+ } else {
+ // Read a <composite><reference>
+ compositeReference = assemblyFactory.createCompositeReference();
+ contract = compositeReference;
+ compositeReference.setName(getString(reader, NAME));
+ readMultiplicity(compositeReference, reader);
+ readTargets(compositeReference, reader);
+ String promote = reader.getAttributeValue(null, Constants.PROMOTE);
+ if (promote != null) {
+ for (StringTokenizer tokens = new StringTokenizer(promote); tokens.hasMoreTokens();) {
+ ComponentReference promotedReference =
+ assemblyFactory.createComponentReference();
+ promotedReference.setUnresolved(true);
+ promotedReference.setName(tokens.nextToken());
+ compositeReference.getPromotedReferences().add(promotedReference);
+ }
+ }
+ compositeReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
+
+ //handle extension attributes
+ this.readExtendedAttributes(reader, name, compositeReference, extensionAttributeProcessor);
+
+ composite.getReferences().add(compositeReference);
+ policyProcessor.readPolicies(contract, reader);
+ }
+
+ } else if (PROPERTY_QNAME.equals(name)) {
+ if (component != null) {
+
+ // Read a <component><property>
+ componentProperty = assemblyFactory.createComponentProperty();
+ property = componentProperty;
+ String source = getString(reader, SOURCE);
+ if(source!=null) {
+ source = source.trim();
+ }
+ componentProperty.setSource(source);
+ if (source != null) {
+ // $<name>/...
+ if (source.charAt(0) == '$') {
+ int index = source.indexOf('/');
+ if (index == -1) {
+ // Tolerating $prop
+ source = source + "/";
+ index = source.length() - 1;
+ }
+ source = source.substring(index + 1);
+ if ("".equals(source)) {
+ source = ".";
+ }
+ }
+ XPath xpath = xPathFactory.newXPath();
+ xpath.setNamespaceContext(reader.getNamespaceContext());
+ try {
+ componentProperty.setSourceXPathExpression(xpath.compile(source));
+ } catch (XPathExpressionException e) {
+ ContributionReadException ce = new ContributionReadException(e);
+ error("ContributionReadException", xpath, ce);
+ //throw ce;
+ }
+ }
+ componentProperty.setFile(getString(reader, FILE));
+
+ //handle extension attributes
+ this.readExtendedAttributes(reader, name, componentProperty, extensionAttributeProcessor);
+
+ policyProcessor.readPolicies(property, reader);
+ readAbstractProperty(componentProperty, reader);
+
+ // Read the property value
+ Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
+ property.setValue(value);
+
+ component.getProperties().add(componentProperty);
+ } else {
+
+ // Read a <composite><property>
+ property = assemblyFactory.createProperty();
+ policyProcessor.readPolicies(property, reader);
+ readAbstractProperty(property, reader);
+
+ // Read the property value
+ Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
+ property.setValue(value);
+
+ composite.getProperties().add(property);
+ }
+
+ // TUSCANY-1949
+ // If the property doesn't have a value, the END_ELEMENT event is read by the readPropertyValue
+ if (reader.getEventType() == END_ELEMENT && PROPERTY_QNAME.equals(reader.getName())) {
+ property = null;
+ componentProperty = null;
+ }
+
+ } else if (COMPONENT_QNAME.equals(name)) {
+
+ // Read a <component>
+ component = assemblyFactory.createComponent();
+ component.setName(getString(reader, NAME));
+ if (isSet(reader, AUTOWIRE)) {
+ component.setAutowire(getBoolean(reader, AUTOWIRE));
+ }
+ if (isSet(reader, URI)) {
+ component.setURI(getString(reader, URI));
+ }
+
+ //handle extension attributes
+ this.readExtendedAttributes(reader, name, component, extensionAttributeProcessor);
+
+ component.setConstrainingType(readConstrainingType(reader));
+ composite.getComponents().add(component);
+ policyProcessor.readPolicies(component, reader);
+
+ } else if (WIRE_QNAME.equals(name)) {
+
+ // Read a <wire>
+ wire = assemblyFactory.createWire();
+ ComponentReference source = assemblyFactory.createComponentReference();
+ source.setUnresolved(true);
+ source.setName(getString(reader, SOURCE));
+ wire.setSource(source);
+
+ ComponentService target = assemblyFactory.createComponentService();
+ target.setUnresolved(true);
+ target.setName(getString(reader, TARGET));
+ wire.setTarget(target);
+
+ //handle extension attributes
+ this.readExtendedAttributes(reader, name, wire, extensionAttributeProcessor);
+
+ composite.getWires().add(wire);
+ policyProcessor.readPolicies(wire, reader);
+
+ } else if (CALLBACK_QNAME.equals(name)) {
+
+ // Read a <callback>
+ callback = assemblyFactory.createCallback();
+ contract.setCallback(callback);
+
+ //handle extension attributes
+ this.readExtendedAttributes(reader, name, callback, extensionAttributeProcessor);
+
+ policyProcessor.readPolicies(callback, reader);
+
+ } else if (OPERATION_QNAME.equals(name)) {
+
+ // Read an <operation>
+ ConfiguredOperation operation = assemblyFactory.createConfiguredOperation();
+ operation.setName(getString(reader, NAME));
+ operation.setUnresolved(true);
+ if (callback != null) {
+ policyProcessor.readPolicies(operation, reader);
+ } else {
+ policyProcessor.readPolicies(operation, reader);
+ }
+
+ OperationsConfigurator opConfigurator = null;
+ if ( compositeService != null ) {
+ opConfigurator = compositeService;
+ } else if ( componentService != null ) {
+ opConfigurator = componentService;
+ } else if ( compositeReference != null ) {
+ opConfigurator = compositeReference;
+ } else if ( componentReference != null ) {
+ opConfigurator = componentReference;
+ }
+
+ opConfigurator.getConfiguredOperations().add(operation);
+ } else if (IMPLEMENTATION_COMPOSITE_QNAME.equals(name)) {
+
+ // Read an implementation.composite
+ Composite implementation = assemblyFactory.createComposite();
+ implementation.setName(getQName(reader, NAME));
+ implementation.setUnresolved(true);
+
+ //handle extension attributes
+ this.readExtendedAttributes(reader, name, implementation, extensionAttributeProcessor);
+
+ component.setImplementation(implementation);
+ policyProcessor.readPolicies(implementation, reader);
+ } else {
+
+ // Read an extension element
+ Object extension = extensionProcessor.read(reader);
+ if (extension != null) {
+ if (extension instanceof InterfaceContract) {
+
+ // <service><interface> and
+ // <reference><interface>
+ if (contract != null) {
+ contract.setInterfaceContract((InterfaceContract)extension);
+ } else {
+ if (name.getNamespaceURI().equals(SCA10_NS)) {
+ error("UnexpectedInterfaceElement", extension);
+ //throw new ContributionReadException("Unexpected <interface> element found. It should appear inside a <service> or <reference> element");
+ } else {
+ composite.getExtensions().add(extension);
+ }
+ }
+ } else if (extension instanceof Binding) {
+ if ( extension instanceof PolicySetAttachPoint ) {
+ IntentAttachPointType bindingType = intentAttachPointTypeFactory.createBindingType();
+ bindingType.setName(name);
+ bindingType.setUnresolved(true);
+ ((PolicySetAttachPoint)extension).setType(bindingType);
+ }
+ // <service><binding> and
+ // <reference><binding>
+ if (callback != null) {
+ callback.getBindings().add((Binding)extension);
+ } else {
+ if (contract != null) {
+ contract.getBindings().add((Binding)extension);
+ } else {
+ if (name.getNamespaceURI().equals(SCA10_NS)) {
+ error("UnexpectedBindingElement", extension);
+ //throw new ContributionReadException("Unexpected <binding> element found. It should appear inside a <service> or <reference> element");
+ } else {
+ composite.getExtensions().add(extension);
+ }
+ }
+ }
+
+ } else if (extension instanceof Implementation) {
+ if ( extension instanceof PolicySetAttachPoint ) {
+ IntentAttachPointType implType = intentAttachPointTypeFactory.createImplementationType();
+ implType.setName(name);
+ implType.setUnresolved(true);
+ ((PolicySetAttachPoint)extension).setType(implType);
+ }
+ // <component><implementation>
+ if (component != null) {
+ component.setImplementation((Implementation)extension);
+ } else {
+ if (name.getNamespaceURI().equals(SCA10_NS)) {
+ error("UnexpectedImplementationElement", extension);
+ //throw new ContributionReadException("Unexpected <implementation> element found. It should appear inside a <component> element");
+ } else {
+ composite.getExtensions().add(extension);
+ }
+ }
+ } else {
+
+ // Add the extension element to the current
+ // element
+ if (callback != null) {
+ callback.getExtensions().add(extension);
+ } else if (contract != null) {
+ contract.getExtensions().add(extension);
+ } else if (property != null) {
+ property.getExtensions().add(extension);
+ } else if (component != null) {
+ component.getExtensions().add(extension);
+ } else {
+ composite.getExtensions().add(extension);
+ }
+ }
+ }
+ }
+ break;
+
+ case XMLStreamConstants.CHARACTERS:
+ break;
+
+ case END_ELEMENT:
+ name = reader.getName();
+
+ // Clear current state when reading reaching end element
+ if (SERVICE_QNAME.equals(name)) {
+ componentService = null;
+ compositeService = null;
+ contract = null;
+ } else if (INCLUDE_QNAME.equals(name)) {
+ include = null;
+ } else if (REFERENCE_QNAME.equals(name)) {
+ componentReference = null;
+ compositeReference = null;
+ contract = null;
+ } else if (PROPERTY_QNAME.equals(name)) {
+ componentProperty = null;
+ property = null;
+ } else if (COMPONENT_QNAME.equals(name)) {
+ component = null;
+ } else if (WIRE_QNAME.equals(name)) {
+ wire = null;
+ } else if (CALLBACK_QNAME.equals(name)) {
+ callback = null;
+ }
+ break;
+ }
+
+ // Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
+ }
+ return composite;
+ }
+
+ public void write(Composite composite, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+
+ // Write <composite> element
+ writeStartDocument(writer,
+ COMPOSITE,
+ writeConstrainingType(composite),
+ new XAttr(TARGET_NAMESPACE, composite.getName().getNamespaceURI()),
+ new XAttr(NAME, composite.getName().getLocalPart()),
+ new XAttr(AUTOWIRE, composite.getAutowire()),
+ policyProcessor.writePolicies(composite));
+
+ //write extended attributes
+ this.writeExtendedAttributes(writer, composite, extensionAttributeProcessor);
+
+ // Write <include> elements
+ for (Composite include : composite.getIncludes()) {
+ String uri = include.isUnresolved()? include.getURI() : null;
+ writeStart(writer,
+ INCLUDE,
+ new XAttr(NAME, include.getName()),
+ new XAttr(URI, uri));
+
+ //write extended attributes
+ this.writeExtendedAttributes(writer, include, extensionAttributeProcessor);
+
+ writeEnd(writer);
+ }
+
+ // Write <service> elements
+ for (Service service : composite.getServices()) {
+ CompositeService compositeService = (CompositeService)service;
+ Component promotedComponent = compositeService.getPromotedComponent();
+ ComponentService promotedService = compositeService.getPromotedService();
+ String promote;
+ if (promotedService != null) {
+ if (promotedService.getName() != null) {
+ promote = promotedComponent.getName() + '/' + promotedService.getName();
+ } else {
+ promote = promotedComponent.getName();
+ }
+ } else {
+ promote = null;
+ }
+ writeStart(writer, SERVICE, new XAttr(NAME, service.getName()), new XAttr(PROMOTE, promote),
+ policyProcessor.writePolicies(service));
+
+ //write extended attributes
+ this.writeExtendedAttributes(writer, service, extensionAttributeProcessor);
+
+
+ // Write service interface
+ extensionProcessor.write(service.getInterfaceContract(), writer);
+
+ // Write bindings
+ for (Binding binding : service.getBindings()) {
+ extensionProcessor.write(binding, writer);
+ }
+
+ // Write <callback> element
+ if (service.getCallback() != null) {
+ Callback callback = service.getCallback();
+ writeStart(writer, CALLBACK,
+ policyProcessor.writePolicies(callback));
+
+ //write extended attributes
+ this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor);
+
+ // Write callback bindings
+ for (Binding binding : callback.getBindings()) {
+ extensionProcessor.write(binding, writer);
+ }
+
+ // Write extensions
+ for (Object extension : callback.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ // Write extensions
+ for (Object extension : service.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ // Write <component> elements
+ for (Component component : composite.getComponents()) {
+ writeStart(writer, COMPONENT, new XAttr(NAME, component.getName()),
+ new XAttr(URI, component.getURI()),
+ new XAttr(AUTOWIRE, component.getAutowire()),
+ policyProcessor.writePolicies(component));
+
+ //write extended attributes
+ this.writeExtendedAttributes(writer, component, extensionAttributeProcessor);
+
+ // Write the component implementation
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ writeStart(writer, IMPLEMENTATION_COMPOSITE, new XAttr(NAME, ((Composite)implementation).getName()));
+
+ //write extended attributes
+ this.writeExtendedAttributes(writer, (Composite)implementation, extensionAttributeProcessor);
+
+ writeEnd(writer);
+ } else {
+ extensionProcessor.write(component.getImplementation(), writer);
+ }
+
+ // Write <service> elements
+ for (ComponentService service : component.getServices()) {
+ writeStart(writer, SERVICE, new XAttr(NAME, service.getName()),
+ policyProcessor.writePolicies(service));
+
+ //write extended attributes
+ this.writeExtendedAttributes(writer, service, extensionAttributeProcessor);
+
+ // Write service interface
+ extensionProcessor.write(service.getInterfaceContract(), writer);
+
+ // Write bindings
+ for (Binding binding : service.getBindings()) {
+ extensionProcessor.write(binding, writer);
+ }
+
+ // Write <callback> element
+ if (service.getCallback() != null) {
+ Callback callback = service.getCallback();
+ writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback));
+
+ //write extended attributes
+ this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor);
+
+ // Write bindings
+ for (Binding binding : callback.getBindings()) {
+ extensionProcessor.write(binding, writer);
+ }
+
+ // Write extensions
+ for (Object extension : callback.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ // Write extensions
+ for (Object extension : service.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ // Write <reference> elements
+ for (ComponentReference reference : component.getReferences()) {
+ writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()),
+ new XAttr(AUTOWIRE, reference.getAutowire()),
+ writeTargets(reference),
+ policyProcessor.writePolicies(reference));
+
+ //write extended attributes
+ this.writeExtendedAttributes(writer, reference, extensionAttributeProcessor);
+
+ // Write reference interface
+ extensionProcessor.write(reference.getInterfaceContract(), writer);
+
+ // Write bindings
+ for (Binding binding : reference.getBindings()) {
+ extensionProcessor.write(binding, writer);
+ }
+
+ // Write callback
+ if (reference.getCallback() != null) {
+ Callback callback = reference.getCallback();
+ writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback));
+
+ //write extended attributes
+ this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor);
+
+ // Write callback bindings
+ for (Binding binding : callback.getBindings()) {
+ extensionProcessor.write(binding, writer);
+ }
+
+ // Write extensions
+ for (Object extensions : callback.getExtensions()) {
+ extensionProcessor.write(extensions, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ // Write extensions
+ for (Object extensions : reference.getExtensions()) {
+ extensionProcessor.write(extensions, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ // Write <property> elements
+ for (ComponentProperty property : component.getProperties()) {
+ writeStart(writer,
+ PROPERTY,
+ new XAttr(NAME, property.getName()),
+ new XAttr(MUST_SUPPLY, property.isMustSupply()),
+ new XAttr(MANY, property.isMany()),
+ new XAttr(TYPE, property.getXSDType()),
+ new XAttr(ELEMENT, property.getXSDElement()),
+ new XAttr(SOURCE, property.getSource()),
+ new XAttr(FILE, property.getFile()),
+ policyProcessor.writePolicies(property));
+
+ //write extended attributes
+ this.writeExtendedAttributes(writer, property, extensionAttributeProcessor);
+
+ // Write property value
+ writePropertyValue(property.getValue(), property.getXSDElement(), property.getXSDType(), writer);
+
+ // Write extensions
+ for (Object extension : property.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ // Write <reference> elements
+ for (Reference reference : composite.getReferences()) {
+ CompositeReference compositeReference = (CompositeReference)reference;
+
+ // Write list of promoted references
+ List<String> promote = new ArrayList<String>();
+ for (ComponentReference promoted: compositeReference.getPromotedReferences()) {
+ promote.add(promoted.getName());
+ }
+
+ // Write <reference> element
+ writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()),
+ new XAttr(PROMOTE, promote),
+ policyProcessor.writePolicies(reference));
+
+ //write extended attributes
+ this.writeExtendedAttributes(writer, reference, extensionAttributeProcessor);
+
+ // Write reference interface
+ extensionProcessor.write(reference.getInterfaceContract(), writer);
+
+ // Write bindings
+ for (Binding binding : reference.getBindings()) {
+ extensionProcessor.write(binding, writer);
+ }
+
+ // Write <callback> element
+ if (reference.getCallback() != null) {
+ Callback callback = reference.getCallback();
+ writeStart(writer, CALLBACK);
+
+ //write extended attributes
+ this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor);
+
+ // Write callback bindings
+ for (Binding binding : callback.getBindings()) {
+ extensionProcessor.write(binding, writer);
+ }
+
+ // Write extensions
+ for (Object extension : callback.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ // Write extensions
+ for (Object extension : reference.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ // Write <property> elements
+ for (Property property : composite.getProperties()) {
+ writeStart(writer,
+ PROPERTY,
+ new XAttr(NAME, property.getName()),
+ new XAttr(MUST_SUPPLY, property.isMustSupply()),
+ new XAttr(MANY, property.isMany()),
+ new XAttr(TYPE, property.getXSDType()),
+ new XAttr(ELEMENT, property.getXSDElement()),
+ policyProcessor.writePolicies(property));
+
+ //write extended attributes
+ this.writeExtendedAttributes(writer, property, extensionAttributeProcessor);
+
+ // Write property value
+ writePropertyValue(property.getValue(), property.getXSDElement(), property.getXSDType(), writer);
+
+ // Write extensions
+ for (Object extension : property.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ // Write <wire> elements
+ for (Wire wire : composite.getWires()) {
+ writeStart(writer, WIRE, new XAttr(SOURCE, wire.getSource().getName()), new XAttr(TARGET, wire
+ .getTarget().getName()));
+
+ //write extended attributes
+ this.writeExtendedAttributes(writer, wire, extensionAttributeProcessor);
+
+ // Write extensions
+ for (Object extension : wire.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+ writeEnd(writer);
+ }
+
+ for (Object extension : composite.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEndDocument(writer);
+ }
+
+ public void resolve(Composite composite, ModelResolver resolver) throws ContributionResolveException {
+
+ // Resolve constraining type
+ ConstrainingType constrainingType = composite.getConstrainingType();
+ if (constrainingType != null) {
+ constrainingType = resolver.resolveModel(ConstrainingType.class, constrainingType);
+ composite.setConstrainingType(constrainingType);
+ }
+
+ // Resolve includes in the composite
+ for (int i = 0, n = composite.getIncludes().size(); i < n; i++) {
+ Composite include = composite.getIncludes().get(i);
+ if (include != null) {
+ include = resolver.resolveModel(Composite.class, include);
+ composite.getIncludes().set(i, include);
+ }
+ }
+
+ // Resolve extensions
+ for (Object extension : composite.getExtensions()) {
+ if (extension != null) {
+ extensionProcessor.resolve(extension, resolver);
+ }
+ }
+
+ //resolve intents and policy sets
+ List<Intent> compositeIntents = null;
+ List<PolicySet> compositePolicySets = null;
+ List<PolicySet> compositeApplicablePolicySets = null;
+ resolveIntents(composite.getRequiredIntents(), resolver);
+ resolvePolicySets(composite.getPolicySets(), resolver);
+ resolvePolicySets(composite.getApplicablePolicySets(), resolver);
+ compositeIntents = composite.getRequiredIntents();
+ compositePolicySets = composite.getPolicySets();
+ compositeApplicablePolicySets = composite.getApplicablePolicySets();
+
+ //Resolve composite services and references
+ resolveContracts(composite, composite.getServices(), resolver);
+ resolveContracts(composite, composite.getReferences(), resolver);
+
+ // Resolve component implementations, services and references
+ for (Component component : composite.getComponents()) {
+ constrainingType = component.getConstrainingType();
+ if (constrainingType != null) {
+ constrainingType = resolver.resolveModel(ConstrainingType.class, constrainingType);
+ component.setConstrainingType(constrainingType);
+ }
+
+ //resolve intents and policy sets
+ resolveIntents(component.getRequiredIntents(), resolver);
+ resolvePolicySets(component.getPolicySets(), resolver);
+ resolvePolicySets(component.getApplicablePolicySets(), resolver);
+
+ //inherit composite intents and policysets
+ PolicyComputationUtils.addDefaultPolicies(compositeIntents,
+ compositePolicySets,
+ component.getRequiredIntents(),
+ component.getPolicySets());
+
+ addInheritedPolicySets(compositeApplicablePolicySets, component.getApplicablePolicySets());
+
+ //resolve component services and references
+ resolveContracts(component, component.getServices(), resolver);
+ resolveContracts(component, component.getReferences(), resolver);
+
+ for (ComponentProperty componentProperty : component.getProperties()) {
+ if (componentProperty.getFile() != null) {
+ Artifact artifact = contributionFactory.createArtifact();
+ artifact.setURI(componentProperty.getFile());
+ artifact = resolver.resolveModel(Artifact.class, artifact);
+ if (artifact.getLocation() != null) {
+ componentProperty.setFile(artifact.getLocation());
+ }
+ }
+ }
+
+ //resolve component implementation
+ Implementation implementation = component.getImplementation();
+ if (implementation != null) {
+ try {
+ //resolve intents and policysets specified on this implementation
+ //before copying them over to the component. Before that, from the component
+ //copy over the applicablePolicySets alone as it might have to be
+ //used to validate the policysets specified on the implementation
+
+ resolveImplIntentsAndPolicySets(implementation,
+ component.getApplicablePolicySets(),
+ resolver);
+
+ copyPoliciesToComponent(component, implementation, resolver, true);
+
+ //now resolve the implementation so that even if there is a shared instance
+ //for this that is resolved, the specified intents and policysets are safe in the
+ //component and not lost
+ implementation = resolveImplementation(implementation, resolver);
+
+ //resolved implementation may contain intents and policysets specified at
+ //componentType (either in the componentType side file or in annotations if its a
+ //java implementation). This has to be consolidated in to the component.
+ copyPoliciesToComponent(component, implementation, resolver, false);
+
+ component.setImplementation(implementation);
+ } catch ( PolicyValidationException e ) {
+ error("PolicyImplValidationException", resolver, component.getName(), e.getMessage());
+ //throw new ContributionResolveException("PolicyValidation exception when processing implementation of component '"
+ //+ component.getName() + "' due to " + e.getMessage(), e);
+ }
+
+ }
+
+ //add model resolver to component
+ if (component instanceof ResolverExtension) {
+ ((ResolverExtension)component).setModelResolver(resolver);
+ }
+ }
+
+ // Add model resolver to promoted components
+ for (Service service : composite.getServices()) {
+ CompositeService compositeService = (CompositeService)service;
+ Component promotedComponent = compositeService.getPromotedComponent();
+ if (promotedComponent instanceof ResolverExtension) {
+ ((ResolverExtension)promotedComponent).setModelResolver(resolver);
+ }
+ }
+ }
+
+ private void resolveImplIntentsAndPolicySets(Implementation implementation,
+ List<PolicySet> inheritedApplicablePolicySets,
+ ModelResolver resolver) throws ContributionResolveException,
+ PolicyValidationException
+ {
+ if ( implementation instanceof PolicySetAttachPoint ) {
+ PolicySetAttachPoint policiedImpl = (PolicySetAttachPoint)implementation;
+
+ policiedImpl.getApplicablePolicySets().addAll(inheritedApplicablePolicySets);
+
+ resolveIntents(policiedImpl.getRequiredIntents(), resolver);
+ PolicyValidationUtils.validateIntents(policiedImpl, policiedImpl.getType());
+
+ resolvePolicySets(policiedImpl.getPolicySets(), resolver);
+ resolvePolicySets(policiedImpl.getApplicablePolicySets(), resolver);
+
+ PolicyValidationUtils.validatePolicySets(policiedImpl);
+
+ if ( implementation instanceof OperationsConfigurator ) {
+ for ( ConfiguredOperation implConfOp : ((OperationsConfigurator)implementation).getConfiguredOperations() ) {
+ resolveIntents(implConfOp.getRequiredIntents(), resolver);
+ PolicyValidationUtils.validateIntents(implConfOp, policiedImpl.getType());
+
+ resolvePolicySets(implConfOp.getPolicySets(), resolver);
+ resolvePolicySets(implConfOp.getApplicablePolicySets(), resolver);
+ //add the inherited applicablePolicysets
+ addInheritedPolicySets(policiedImpl.getApplicablePolicySets(), implConfOp.getApplicablePolicySets());
+
+ PolicyValidationUtils.validatePolicySets(implConfOp, policiedImpl.getType());
+
+ PolicyComputationUtils.addDefaultPolicies(
+ ((PolicySetAttachPoint)implementation).getRequiredIntents(),
+ ((PolicySetAttachPoint)implementation).getPolicySets(),
+ implConfOp.getRequiredIntents(),
+ implConfOp.getPolicySets());
+ }
+ }
+ }
+ }
+
+ private void copyPoliciesToComponent(Component component,
+ Implementation implementation,
+ ModelResolver resolver,
+ boolean clearImplSettings) throws ContributionResolveException {
+ if (implementation instanceof PolicySetAttachPoint) {
+ // Add implementation policies into component, since implementation instances are
+ // reused and it's likely that this implementation instance will not hold after its resolution.
+ // On the first call to this method (clearImplSettings=true), we are moving policies from the
+ // implementation XML element up to the component. In this case if there are mutually exclusive
+ // policies we must clear the component policy so that the implementation policy "wins".
+ // On the second call to this method (clearImplSettings=false), we are moving policies from the
+ // componentType implementation up to the component. In this case if there are mutually
+ // exclusive policies it is an error. This error will be detected later in the PolicyComputer.
+ if (clearImplSettings) {
+ for (Intent intent : ((PolicySetAttachPoint)implementation).getRequiredIntents()) {
+ for (Intent excluded : intent.getExcludedIntents()) {
+ if (component.getRequiredIntents().contains(excluded)) {
+ component.getRequiredIntents().remove(excluded);
+ }
+ for (Iterator i = component.getPolicySets().iterator(); i.hasNext(); ) {
+ PolicySet cmpPolicySet = (PolicySet) i.next();
+ if (cmpPolicySet.getProvidedIntents().contains(excluded)) {
+ i.remove();
+ }
+ }
+ }
+ }
+ for (PolicySet policySet : ((PolicySetAttachPoint)implementation).getPolicySets()) {
+ for (Intent intent : policySet.getProvidedIntents()) {
+ for (Intent excluded : intent.getExcludedIntents()) {
+ if (component.getRequiredIntents().contains(excluded)) {
+ component.getRequiredIntents().remove(excluded);
+ }
+ for (Iterator i = component.getPolicySets().iterator(); i.hasNext(); ) {
+ PolicySet cmpPolicySet = (PolicySet) i.next();
+ if (cmpPolicySet.getProvidedIntents().contains(excluded)) {
+ i.remove();
+ }
+ }
+ }
+ }
+ }
+ }
+ component.getRequiredIntents().addAll(((PolicySetAttachPoint)implementation).getRequiredIntents());
+ component.getPolicySets().addAll(((PolicySetAttachPoint)implementation).getPolicySets());
+ component.getApplicablePolicySets().addAll(((PolicySetAttachPoint)implementation).getApplicablePolicySets());
+
+ if ( implementation instanceof OperationsConfigurator ) {
+ boolean notFound;
+ List<ConfiguredOperation> opsFromImplementation = new ArrayList<ConfiguredOperation>();
+ List<ConfiguredOperation> implConfOperations =
+ new ArrayList<ConfiguredOperation>(((OperationsConfigurator)implementation).getConfiguredOperations());
+ for ( ConfiguredOperation implConfOp : implConfOperations ) {
+ notFound = true;
+ for ( ConfiguredOperation compConfOp : ((OperationsConfigurator)component).getConfiguredOperations() ) {
+ if ( implConfOp.getName().equals(compConfOp.getName()) ) {
+ notFound = false;
+
+ if (clearImplSettings) {
+ for (Intent intent : implConfOp.getRequiredIntents()) {
+ for (Intent excluded : intent.getExcludedIntents()) {
+ if (compConfOp.getRequiredIntents().contains(excluded)) {
+ compConfOp.getRequiredIntents().remove(excluded);
+ }
+ }
+ }
+ for (PolicySet policySet : implConfOp.getPolicySets()) {
+ for (Intent intent : policySet.getProvidedIntents()) {
+ for (Intent excluded : intent.getExcludedIntents()) {
+ if (compConfOp.getRequiredIntents().contains(excluded)) {
+ compConfOp.getRequiredIntents().remove(excluded);
+ }
+ for (Iterator i = compConfOp.getPolicySets().iterator(); i.hasNext(); ) {
+ PolicySet cmpPolicySet = (PolicySet) i.next();
+ if (cmpPolicySet.getProvidedIntents().contains(excluded)) {
+ i.remove();
+ }
+ }
+ }
+ }
+ }
+ }
+
+ addInheritedIntents(implConfOp.getRequiredIntents(), compConfOp.getRequiredIntents());
+ addInheritedPolicySets(implConfOp.getPolicySets(), compConfOp.getPolicySets());
+ addInheritedPolicySets(implConfOp.getApplicablePolicySets(), compConfOp.getApplicablePolicySets());
+ }
+ }
+
+ if ( notFound ) {
+ opsFromImplementation.add(implConfOp);
+ }
+
+ if ( clearImplSettings ) {
+ ((OperationsConfigurator)implementation).getConfiguredOperations().remove(implConfOp);
+ }
+ }
+ ((OperationsConfigurator)component).getConfiguredOperations().addAll(opsFromImplementation);
+ }
+
+ if ( clearImplSettings ) {
+ ((PolicySetAttachPoint)implementation).getRequiredIntents().clear();
+ ((PolicySetAttachPoint)implementation).getPolicySets().clear();
+ }
+ }
+ }
+
+
+ public QName getArtifactType() {
+ return COMPOSITE_QNAME;
+ }
+
+ public Class<Composite> getModelType() {
+ return Composite.class;
+ }
+
+ /**
+ * Returns the model factory extension point to use.
+ *
+ * @param extensionPoints
+ * @return
+ */
+ private static ModelFactoryExtensionPoint modelFactories(ExtensionPointRegistry extensionPoints) {
+ return extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ }
+
+ /**
+ * Returns the monitor to use.
+ *
+ * @param extensionPoints
+ * @return
+ */
+ private static Monitor monitor(ExtensionPointRegistry extensionPoints) {
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ if (utilities != null) {
+ MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
+ if (monitorFactory != null) {
+ return monitorFactory.createMonitor();
+ }
+ }
+ return null;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConfiguredOperationProcessor.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConfiguredOperationProcessor.java
new file mode 100644
index 0000000000..aa4980fcb6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConfiguredOperationProcessor.java
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.ConfiguredOperation;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/**
+ * Processor for dealing with 'operation' elements from composite definitions
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConfiguredOperationProcessor implements StAXArtifactProcessor<ConfiguredOperation>, Constants{
+
+ private AssemblyFactory assemblyFactory;
+ private PolicyAttachPointProcessor policyProcessor;
+ private PolicyFactory policyFactory;
+ private Monitor monitor;
+
+ public ConfiguredOperationProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
+ this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ this.policyFactory = modelFactories.getFactory(PolicyFactory.class);
+ this.policyProcessor = new PolicyAttachPointProcessor(policyFactory);
+ this.monitor = monitor;
+ }
+
+ public ConfiguredOperation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ ConfiguredOperation configuredOp = assemblyFactory.createConfiguredOperation();
+
+ //Read an <operation>
+ configuredOp.setName(reader.getAttributeValue(null, NAME));
+ configuredOp.setContractName(reader.getAttributeValue(null, SERVICE));
+ configuredOp.setUnresolved(true);
+
+ // Read policies
+ policyProcessor.readPolicies(configuredOp, reader);
+
+ //Skip to end element
+ while (reader.hasNext()) {
+ if (reader.next() == END_ELEMENT && OPERATION_QNAME.equals(reader.getName())) {
+ break;
+ }
+ }
+
+ return configuredOp;
+ }
+
+ public void write(ConfiguredOperation configuredOperation, XMLStreamWriter writer)
+ throws ContributionWriteException, XMLStreamException {
+
+ // Write an <operation>
+ policyProcessor.writePolicyPrefixes(configuredOperation, writer);
+ writer.writeStartElement(Constants.SCA10_NS, OPERATION);
+ policyProcessor.writePolicyAttributes(configuredOperation, writer);
+
+ writer.writeAttribute(NAME, configuredOperation.getName());
+ if ( configuredOperation.getContractName() != null ) {
+ writer.writeAttribute(SERVICE, configuredOperation.getContractName());
+ }
+ writer.writeEndElement();
+ }
+
+ public void resolve(ConfiguredOperation configuredOperation, ModelResolver resolver)
+ throws ContributionResolveException {
+ }
+
+ public QName getArtifactType() {
+ return OPERATION_QNAME;
+ }
+
+ public Class<ConfiguredOperation> getModelType() {
+ return ConfiguredOperation.class;
+ }
+
+}
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java
new file mode 100644
index 0000000000..3bf5a1173b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Constants used in SCA assembly XML files.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Constants {
+ String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0";
+ String SCA10_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.0";
+
+ String COMPONENT_TYPE = "componentType";
+ QName COMPONENT_TYPE_QNAME = new QName(SCA10_NS, COMPONENT_TYPE);
+
+ String SERVICE = "service";
+ QName SERVICE_QNAME = new QName(SCA10_NS, SERVICE);
+
+ String REFERENCE = "reference";
+ QName REFERENCE_QNAME = new QName(SCA10_NS, REFERENCE);
+
+ String PROPERTY = "property";
+ QName PROPERTY_QNAME = new QName(SCA10_NS, PROPERTY);
+
+ String CONSTRAINING_TYPE = "constrainingType";
+ QName CONSTRAINING_TYPE_QNAME = new QName(SCA10_NS, CONSTRAINING_TYPE);
+
+ String COMPOSITE = "composite";
+ QName COMPOSITE_QNAME = new QName(SCA10_NS, COMPOSITE);
+
+ String INCLUDE = "include";
+ QName INCLUDE_QNAME = new QName(SCA10_NS, INCLUDE);
+
+ String COMPONENT = "component";
+ QName COMPONENT_QNAME = new QName(SCA10_NS, COMPONENT);
+
+ String WIRE = "wire";
+ QName WIRE_QNAME = new QName(SCA10_NS, WIRE);
+
+ String OPERATION = "operation";
+ QName OPERATION_QNAME = new QName(SCA10_NS, OPERATION);
+
+ String CALLBACK = "callback";
+ QName CALLBACK_QNAME = new QName(SCA10_NS, CALLBACK);
+
+ String IMPLEMENTATION_COMPOSITE = "implementation.composite";
+ QName IMPLEMENTATION_COMPOSITE_QNAME = new QName(SCA10_NS, IMPLEMENTATION_COMPOSITE);
+
+ String IMPLEMENTATION = "implementation";
+ QName IMPLEMENTATION_QNAME = new QName(SCA10_NS, IMPLEMENTATION);
+
+ String BINDING_SCA = "binding.sca";
+ QName BINDING_SCA_QNAME = new QName(Constants.SCA10_NS, BINDING_SCA);
+
+ String NAME = "name";
+ String TARGET_NAMESPACE = "targetNamespace";
+ String LOCAL = "local";
+ String AUTOWIRE = "autowire";
+ String REQUIRES = "requires";
+ String POLICY_SETS = "policySets";
+ String APPLICABLE_POLICY_SETS = "applicablePolicySets";
+ String PROMOTE = "promote";
+ String TARGET = "target";
+ String WIRED_BY_IMPL = "wiredByImpl";
+ String MULTIPLICITY = "multiplicity";
+ String TYPE = "type";
+ String ELEMENT = "element";
+ String MANY = "many";
+ String MUST_SUPPLY = "mustSupply";
+ String SOURCE = "source";
+ String FILE = "file";
+ String URI = "uri";
+ String ZERO_ONE = "0..1";
+ String ZERO_N = "0..n";
+ String ONE_ONE = "1..1";
+ String ONE_N = "1..n";
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java
new file mode 100644
index 0000000000..4c5d6f8f49
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeDocumentProcessor.java
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLConnection;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/**
+ * A contrainingType content handler.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConstrainingTypeDocumentProcessor extends BaseAssemblyProcessor implements URLArtifactProcessor<ConstrainingType> {
+ private XMLInputFactory inputFactory;
+
+ /**
+ * Construct a new constrainingType processor.
+ * @param factory
+ * @param policyFactory
+ * @param staxProcessor
+ */
+ public ConstrainingTypeDocumentProcessor(StAXArtifactProcessor staxProcessor,
+ XMLInputFactory inputFactory,
+ Monitor monitor) {
+ super(null, null, staxProcessor, monitor);
+ this.inputFactory = inputFactory;
+ }
+
+ /**
+ * Constructs a new constrainingType processor.
+ * @param modelFactories
+ * @param staxProcessor
+ */
+ public ConstrainingTypeDocumentProcessor(ModelFactoryExtensionPoint modelFactories,
+ StAXArtifactProcessor staxProcessor,
+ Monitor monitor) {
+ super(null, null, staxProcessor, monitor);
+ this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class);
+ }
+
+ public ConstrainingType read(URL contributionURL, URI uri, URL url) throws ContributionReadException {
+ InputStream urlStream = null;
+ try {
+
+ // Create a stream reader
+ URLConnection connection = url.openConnection();
+ connection.setUseCaches(false);
+ urlStream = connection.getInputStream();
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(url.toString(), urlStream);
+ reader.nextTag();
+
+ // Read the constrainingType model
+ ConstrainingType constrainingType = (ConstrainingType)extensionProcessor.read(reader);
+
+ // For debugging purposes, write it back to XML
+// if (constrainingType != null) {
+// try {
+// ByteArrayOutputStream bos = new ByteArrayOutputStream();
+// XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
+// outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+// extensionProcessor.write(constrainingType, outputFactory.createXMLStreamWriter(bos));
+// Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(bos.toByteArray()));
+// OutputFormat format = new OutputFormat();
+// format.setIndenting(true);
+// format.setIndent(2);
+// XMLSerializer serializer = new XMLSerializer(System.out, format);
+// serializer.serialize(document);
+// } catch (Exception e) {
+// e.printStackTrace();
+// }
+// }
+
+ return constrainingType;
+
+ } catch (XMLStreamException e) {
+ ContributionReadException ce = new ContributionReadException(e);
+ error("ContributionReadException", inputFactory, ce);
+ throw ce;
+ } catch (IOException e) {
+ ContributionReadException ce = new ContributionReadException(e);
+ error("ContributionReadException", inputFactory, ce);
+ throw ce;
+ } finally {
+ try {
+ if (urlStream != null) {
+ urlStream.close();
+ urlStream = null;
+ }
+ } catch (IOException ioe) {
+ //ignore
+ }
+ }
+ }
+
+ public void resolve(ConstrainingType constrainingType, ModelResolver resolver) throws ContributionResolveException {
+ extensionProcessor.resolve(constrainingType, resolver);
+ }
+
+ public String getArtifactType() {
+ return ".constrainingType";
+ }
+
+ public Class<ConstrainingType> getModelType() {
+ return ConstrainingType.class;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeModelResolver.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeModelResolver.java
new file mode 100644
index 0000000000..7dd95e3944
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeModelResolver.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.Import;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.namespace.NamespaceImport;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+/**
+ * A Model Resolver for ConstrainingType models.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConstrainingTypeModelResolver implements ModelResolver {
+
+ private Contribution contribution;
+ private Map<QName, ConstrainingType> map = new HashMap<QName, ConstrainingType>();
+
+ public ConstrainingTypeModelResolver(Contribution contribution, ModelFactoryExtensionPoint modelFactories) {
+ this.contribution = contribution;
+ }
+
+ public void addModel(Object resolved) {
+ ConstrainingType composite = (ConstrainingType)resolved;
+ map.put(composite.getName(), composite);
+ }
+
+ public Object removeModel(Object resolved) {
+ return map.remove(((ConstrainingType)resolved).getName());
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+
+ // Lookup a definition for the given namespace
+ QName qname = ((ConstrainingType)unresolved).getName();
+ ConstrainingType resolved = (ConstrainingType) map.get(qname);
+ if (resolved != null) {
+ return modelClass.cast(resolved);
+ }
+
+ // No definition found, delegate the resolution to the imports
+ for (Import import_ : this.contribution.getImports()) {
+ if (import_ instanceof NamespaceImport) {
+ NamespaceImport namespaceImport = (NamespaceImport)import_;
+ if (namespaceImport.getNamespace().equals(qname.getNamespaceURI())) {
+
+ // Delegate the resolution to the import resolver
+ resolved = namespaceImport.getModelResolver().resolveModel(ConstrainingType.class, (ConstrainingType)unresolved);
+ if (!resolved.isUnresolved()) {
+ return modelClass.cast(resolved);
+ }
+ }
+ }
+ }
+ return (T)unresolved;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java
new file mode 100644
index 0000000000..334b6c6b97
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConstrainingTypeProcessor.java
@@ -0,0 +1,273 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.AbstractContract;
+import org.apache.tuscany.sca.assembly.AbstractProperty;
+import org.apache.tuscany.sca.assembly.AbstractReference;
+import org.apache.tuscany.sca.assembly.AbstractService;
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.impl.OperationImpl;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.w3c.dom.Document;
+
+/**
+ * A constrainingType processor.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConstrainingTypeProcessor extends BaseAssemblyProcessor implements StAXArtifactProcessor<ConstrainingType> {
+
+ /**
+ * Construct a new constrainingType processor.
+ * @param factory
+ * @param policyFactory
+ * @param extensionProcessor
+ */
+ public ConstrainingTypeProcessor(AssemblyFactory factory, PolicyFactory policyFactory,
+ StAXArtifactProcessor extensionProcessor, Monitor monitor) {
+ super(factory, policyFactory, extensionProcessor, monitor);
+ }
+
+ /**
+ * Constructs a new constrainingType processor.
+ *
+ * @param modelFactories
+ * @param extensionProcessor
+ */
+ public ConstrainingTypeProcessor(ModelFactoryExtensionPoint modelFactories,
+ StAXArtifactProcessor extensionProcessor,
+ Monitor monitor) {
+ super(modelFactories.getFactory(AssemblyFactory.class),
+ modelFactories.getFactory(PolicyFactory.class), extensionProcessor, monitor);
+ }
+
+ public ConstrainingType read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ ConstrainingType constrainingType = null;
+ AbstractService abstractService = null;
+ AbstractReference abstractReference = null;
+ AbstractProperty abstractProperty = null;
+ AbstractContract abstractContract = null;
+ QName name = null;
+
+ // Read the constrainingType document
+ while (reader.hasNext()) {
+ int event = reader.getEventType();
+ switch (event) {
+
+ case START_ELEMENT:
+ name = reader.getName();
+
+ // Read a <constrainingType>
+ if (Constants.CONSTRAINING_TYPE_QNAME.equals(name)) {
+ constrainingType = assemblyFactory.createConstrainingType();
+ constrainingType.setName(new QName(getString(reader, TARGET_NAMESPACE), getString(reader, NAME)));
+ policyProcessor.readPolicies(constrainingType, reader);
+
+ } else if (Constants.SERVICE_QNAME.equals(name)) {
+
+ // Read a <service>
+ abstractService = assemblyFactory.createAbstractService();
+ abstractContract = abstractService;
+ abstractService.setName(getString(reader, Constants.NAME));
+ constrainingType.getServices().add(abstractService);
+ policyProcessor.readPolicies(abstractService, reader);
+
+ } else if (Constants.REFERENCE_QNAME.equals(name)) {
+
+ // Read a <reference>
+ abstractReference = assemblyFactory.createAbstractReference();
+ abstractContract = abstractReference;
+ abstractReference.setName(getString(reader, Constants.NAME));
+ readMultiplicity(abstractReference, reader);
+ constrainingType.getReferences().add(abstractReference);
+ policyProcessor.readPolicies(abstractReference, reader);
+
+ } else if (Constants.PROPERTY_QNAME.equals(name)) {
+
+ // Read a <property>
+ abstractProperty = assemblyFactory.createAbstractProperty();
+ readAbstractProperty(abstractProperty, reader);
+
+ // Read the property value
+ Document value = readPropertyValue(abstractProperty.getXSDElement(), abstractProperty.getXSDType(), reader);
+ abstractProperty.setValue(value);
+
+ constrainingType.getProperties().add(abstractProperty);
+ policyProcessor.readPolicies(abstractProperty, reader);
+
+ } else if (OPERATION_QNAME.equals(name)) {
+
+ // Read an <operation>
+ Operation operation = new OperationImpl();
+ operation.setName(getString(reader, NAME));
+ operation.setUnresolved(true);
+ policyProcessor.readPolicies(abstractContract, operation, reader);
+
+ } else {
+
+ // Read an extension element
+ Object extension = extensionProcessor.read(reader);
+ if (extension instanceof InterfaceContract) {
+
+ // <service><interface> and <reference><interface>
+ abstractContract.setInterfaceContract((InterfaceContract)extension);
+ } else {
+
+ // Add the extension element to the current element
+ if (abstractContract != null) {
+ abstractContract.getExtensions().add(extension);
+ } else {
+ constrainingType.getExtensions().add(extension);
+ }
+
+ }
+ }
+ break;
+
+ case END_ELEMENT:
+ name = reader.getName();
+
+ // Clear current state when reading reaching end element
+ if (SERVICE_QNAME.equals(name)) {
+ abstractService = null;
+ abstractContract = null;
+ } else if (REFERENCE_QNAME.equals(name)) {
+ abstractReference = null;
+ abstractContract = null;
+ } else if (PROPERTY_QNAME.equals(name)) {
+ abstractProperty = null;
+ }
+ break;
+ }
+ if (reader.hasNext()) {
+ reader.next();
+ }
+ }
+ return constrainingType;
+ }
+
+ public void write(ConstrainingType constrainingType, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+
+ // Write <constrainingType> element
+ writeStartDocument(writer, CONSTRAINING_TYPE,
+ new XAttr(TARGET_NAMESPACE, constrainingType.getName().getNamespaceURI()),
+ new XAttr(NAME, constrainingType.getName().getLocalPart()),
+ policyProcessor.writePolicies(constrainingType));
+
+ // Write <service> elements
+ for (AbstractService service : constrainingType.getServices()) {
+ writeStart(writer, SERVICE, new XAttr(NAME, service.getName()),
+ policyProcessor.writePolicies(service));
+
+ extensionProcessor.write(service.getInterfaceContract(), writer);
+
+ for (Object extension: service.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ // Write <reference> elements
+ for (AbstractReference reference : constrainingType.getReferences()) {
+ writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()),
+ policyProcessor.writePolicies(reference));
+
+ extensionProcessor.write(reference.getInterfaceContract(), writer);
+
+ for (Object extension: reference.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ // Write <property> elements
+ for (AbstractProperty abstractProperty : constrainingType.getProperties()) {
+ writeStart(writer,
+ PROPERTY,
+ new XAttr(NAME, abstractProperty.getName()),
+ new XAttr(MUST_SUPPLY, abstractProperty.isMustSupply()),
+ new XAttr(MANY, abstractProperty.isMany()),
+ new XAttr(TYPE, abstractProperty.getXSDType()),
+ new XAttr(ELEMENT, abstractProperty.getXSDElement()),
+ policyProcessor.writePolicies(abstractProperty));
+
+ // Write property value
+ writePropertyValue(abstractProperty.getValue(), abstractProperty.getXSDElement(), abstractProperty.getXSDType(), writer);
+
+ // Write extensions
+ for (Object extension : abstractProperty.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEnd(writer);
+ }
+
+ // Write extension elements
+ for (Object extension: constrainingType.getExtensions()) {
+ extensionProcessor.write(extension, writer);
+ }
+
+ writeEndDocument(writer);
+ }
+
+ public void resolve(ConstrainingType constrainingType, ModelResolver resolver) throws ContributionResolveException {
+ // Resolve component type services and references
+ resolveAbstractContracts(constrainingType.getServices(), resolver);
+ resolveAbstractContracts(constrainingType.getReferences(), resolver);
+
+ resolveIntents(constrainingType.getRequiredIntents(), resolver);
+ for ( AbstractService service : constrainingType.getServices() ) {
+ resolveIntents(service.getRequiredIntents(), resolver);
+ }
+
+ for ( AbstractReference reference : constrainingType.getReferences() ) {
+ resolveIntents(reference.getRequiredIntents(), resolver);
+ }
+ }
+
+ public QName getArtifactType() {
+ return CONSTRAINING_TYPE_QNAME;
+ }
+
+ public Class<ConstrainingType> getModelType() {
+ return ConstrainingType.class;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java
new file mode 100644
index 0000000000..a63ccdf151
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java
@@ -0,0 +1,256 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Base;
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+
+/**
+ * Default Model Processor for beans.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultBeanModelProcessor extends BaseAssemblyProcessor implements StAXArtifactProcessor {
+
+ private QName artifactType;
+ private Class<Implementation> modelClass;
+ private Object modelFactory;
+ private Method factoryMethod;
+ private Map<String, Method> setterMethods = new HashMap<String, Method>();
+ private Map<String, Method> getterMethods = new HashMap<String, Method>();
+
+ public DefaultBeanModelProcessor(AssemblyFactory assemblyFactory,
+ PolicyFactory policyFactory,
+ QName artifactType,
+ Class<Implementation> modelClass,
+ Object modelFactory,
+ Monitor monitor) {
+ super(assemblyFactory, policyFactory, null, monitor);
+ this.artifactType = artifactType;
+ this.modelClass = modelClass;
+ this.modelFactory = modelFactory;
+
+ // Introspect the factory class and bean model class
+ if (modelFactory != null) {
+
+ // Find the model create method
+ for (Method method: modelFactory.getClass().getMethods()) {
+ if (method.getName().startsWith("create") && method.getReturnType() == modelClass) {
+ factoryMethod = method;
+ break;
+ }
+ }
+ }
+
+ // Index the bean's setter methods
+ for (Method method: modelClass.getMethods()) {
+ Method getter;
+ String name = method.getName();
+ if (name.startsWith("set") && name.length() > 3) {
+
+ // Get the corresponding getter method
+ try {
+ getter = modelClass.getMethod("get" + name.substring(3));
+ } catch (Exception e) {
+ getter = null;
+ continue;
+ }
+
+ // Get the property name
+ name = name.substring(3);
+ if (name.length() > 1) {
+ if (!name.toUpperCase().equals(name)) {
+ name = name.substring(0, 1).toLowerCase() + name.substring(1);
+ }
+ }
+ } else {
+ continue;
+ }
+
+ // Map an uppercase property name to a lowercase attribute name
+ if (name.toUpperCase().equals(name)) {
+ name = name.toLowerCase();
+ }
+
+ // Trim trailing _ from property names
+ if (name.endsWith("_")) {
+ name = name.substring(0, name.length()-1);
+ }
+ setterMethods.put(name, method);
+ getterMethods.put(name, getter);
+ }
+ }
+
+ public Object read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+
+ // Read an element
+ try {
+
+ // Create a new instance of the model
+ Object model;
+ if (modelFactory != null) {
+ // Invoke the factory create method
+ model = factoryMethod.invoke(modelFactory);
+ } else {
+ // Invoke the model bean class default constructor
+ model = modelClass.newInstance();
+ }
+
+ // Initialize the bean properties with the attributes found in the
+ // XML element
+ for (int i = 0, n = reader.getAttributeCount(); i < n; i++) {
+ String attributeName = reader.getAttributeLocalName(i);
+ Method setter = setterMethods.get(attributeName);
+ if (setter != null) {
+ String value = reader.getAttributeValue(i);
+ setter.invoke(model, value);
+ }
+ }
+
+ // Read policies
+ policyProcessor.readPolicies(model, reader);
+
+ // FIXME read extension elements
+
+ // By default mark the model object unresolved
+ if (model instanceof Base) {
+ ((Base)model).setUnresolved(true);
+ }
+
+ // Skip to end element
+ while (reader.hasNext()) {
+ if (reader.next() == END_ELEMENT && artifactType.equals(reader.getName())) {
+ break;
+ }
+ }
+ return model;
+
+ } catch (Exception e) {
+ ContributionReadException ce = new ContributionReadException(e);
+ error("ContributionReadException", reader, ce);
+ throw ce;
+ }
+ }
+
+ public void write(Object bean, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+ try {
+ // Write the bean properties as attributes
+ List<XAttr> attrs = new ArrayList<XAttr>();
+ for (Map.Entry<String, Method> entry: getterMethods.entrySet()) {
+ if (entry.getValue().getReturnType() == String.class) {
+ String value = (String)entry.getValue().invoke(bean);
+ attrs.add(new XAttr(entry.getKey(), value));
+ }
+ }
+
+ // Write element
+ writeStart(writer, artifactType.getNamespaceURI(), artifactType.getLocalPart(),
+ policyProcessor.writePolicies(bean), new XAttr(null, attrs));
+
+ writeEnd(writer);
+
+ } catch (Exception e) {
+ ContributionWriteException ce = new ContributionWriteException(e);
+ error("ContributionWriteException", writer, ce);
+ throw ce;
+ }
+ }
+
+ public void resolve(Object bean, ModelResolver resolver) throws ContributionResolveException {
+
+ // Resolve and merge the component type associated with an
+ // implementation model
+ if (bean instanceof Implementation) {
+ Implementation implementation = (Implementation)bean;
+ String uri = implementation.getURI();
+ if (uri != null) {
+ int d = uri.lastIndexOf('.');
+ if (d != -1) {
+ uri = uri.substring(0, d) + ".componentType";
+
+ // Resolve the component type
+ ComponentType componentType = assemblyFactory.createComponentType();
+ componentType.setURI(uri);
+ componentType.setUnresolved(true);
+
+ componentType = resolver.resolveModel(ComponentType.class, componentType);
+ if (componentType != null && !componentType.isUnresolved()) {
+
+ // We found a component type, merge it into the implementation model
+ implementation.getServices().addAll(componentType.getServices());
+ implementation.getReferences().addAll(componentType.getReferences());
+ implementation.getProperties().addAll(componentType.getProperties());
+ implementation.setConstrainingType(componentType.getConstrainingType());
+
+ if (implementation instanceof PolicySetAttachPoint &&
+ componentType instanceof PolicySetAttachPoint ) {
+ PolicySetAttachPoint policiedImpl = (PolicySetAttachPoint)implementation;
+ PolicySetAttachPoint policiedCompType = (PolicySetAttachPoint)componentType;
+
+ if ( policiedImpl.getPolicySets() != null) {
+ policiedImpl.getPolicySets().addAll(policiedCompType.getPolicySets());
+ }
+ if (policiedImpl.getRequiredIntents() != null) {
+ policiedImpl.getRequiredIntents().addAll(policiedCompType.getRequiredIntents());
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // Mark the model resolved
+ if (bean instanceof Base) {
+ ((Base)bean).setUnresolved(false);
+ }
+ }
+
+ public QName getArtifactType() {
+ return artifactType;
+ }
+
+ public Class<?> getModelType() {
+ return modelClass;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicyAttachPointProcessor.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicyAttachPointProcessor.java
new file mode 100644
index 0000000000..fc4e10654d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicyAttachPointProcessor.java
@@ -0,0 +1,266 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPoint;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+
+/**
+ * A Policy Attach Point processor.
+ *
+ * @version $Rev$ $Date$
+ */
+public class PolicyAttachPointProcessor extends BaseStAXArtifactProcessor implements Constants {
+
+ private PolicyFactory policyFactory;
+
+ public PolicyAttachPointProcessor(PolicyFactory policyFactory) {
+ this.policyFactory = policyFactory;
+ }
+
+ /**
+ * Read policy intents associated with an operation.
+ * @param attachPoint
+ * @param operation
+ * @param reader
+ */
+ private void readIntents(Object attachPoint, Operation operation, XMLStreamReader reader) {
+ if (!(attachPoint instanceof IntentAttachPoint))
+ return;
+ IntentAttachPoint intentAttachPoint = (IntentAttachPoint)attachPoint;
+ String value = reader.getAttributeValue(null, REQUIRES);
+ if (value != null) {
+ List<Intent> requiredIntents = intentAttachPoint.getRequiredIntents();
+ for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
+ QName qname = getQNameValue(reader, tokens.nextToken());
+ Intent intent = policyFactory.createIntent();
+ intent.setName(qname);
+ if (operation != null) {
+ //FIXME Don't we need to handle intent specification
+ // on an operation basis?
+ //intent.getOperations().add(operation);
+ }
+ requiredIntents.add(intent);
+ }
+ }
+ }
+
+ /**
+ * Reads policy intents and policy sets associated with an operation.
+ * @param attachPoint
+ * @param operation
+ * @param reader
+ */
+ public void readPolicies(Object attachPoint, Operation operation, XMLStreamReader reader) {
+ readIntents(attachPoint, operation, reader);
+ readPolicySets(attachPoint, operation, reader);
+ }
+
+ /**
+ * Reads policy intents and policy sets.
+ * @param attachPoint
+ * @param reader
+ */
+ public void readPolicies(Object attachPoint, XMLStreamReader reader) {
+ readPolicies(attachPoint, null, reader);
+ }
+
+ /**
+ * Reads policy sets associated with an operation.
+ * @param attachPoint
+ * @param operation
+ * @param reader
+ */
+ private void readPolicySets(Object attachPoint, Operation operation, XMLStreamReader reader) {
+ if (!(attachPoint instanceof PolicySetAttachPoint)) {
+ return;
+ }
+ PolicySetAttachPoint policySetAttachPoint = (PolicySetAttachPoint)attachPoint;
+ String value = reader.getAttributeValue(null, POLICY_SETS);
+ if (value != null) {
+ List<PolicySet> policySets = policySetAttachPoint.getPolicySets();
+ for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
+ QName qname = getQNameValue(reader, tokens.nextToken());
+ PolicySet policySet = policyFactory.createPolicySet();
+ policySet.setName(qname);
+ if (operation != null) {
+ //FIXME Don't we need to handle policySet specification
+ // on an operation basis?
+ //policySet.getOperations().add(operation);
+ }
+ policySets.add(policySet);
+ }
+ }
+
+ value = reader.getAttributeValue(SCA10_TUSCANY_NS, APPLICABLE_POLICY_SETS);
+ if (value != null) {
+ List<PolicySet> applicablePolicySets = policySetAttachPoint.getApplicablePolicySets();
+ for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
+ QName qname = getQNameValue(reader, tokens.nextToken());
+ PolicySet policySet = policyFactory.createPolicySet();
+ policySet.setName(qname);
+ if (operation != null) {
+ //FIXME Don't we need to handle policySet specification
+ // on an operation basis?
+ //policySet.getOperations().add(operation);
+ }
+ applicablePolicySets.add(policySet);
+ }
+ }
+ }
+
+ /**
+ * Write policies
+ * @param attachPoint
+ * @return
+ */
+ XAttr writePolicies(Object attachPoint) throws XMLStreamException {
+ return writePolicies(attachPoint, (Operation)null);
+ }
+
+ /**
+ * Write policies
+ * @param attachPoint
+ * @return
+ */
+ public void writePolicyAttributes(Object attachPoint, XMLStreamWriter writer) throws XMLStreamException {
+ writePolicyAttributes(attachPoint, (Operation)null, writer);
+ }
+
+ /**
+ * Write policies
+ * @param attachPoint
+ * @return
+ */
+ public void writePolicyPrefixes(Object attachPoint, XMLStreamWriter writer) throws XMLStreamException {
+ writePolicyPrefixes(attachPoint, (Operation)null, writer);
+ }
+
+ /**
+ * Write policies associated with an operation
+ * @param attachPoint
+ * @param operation
+ * @return
+ */
+ XAttr writePolicies(Object attachPoint, Operation operation) {
+ List<XAttr> attrs =new ArrayList<XAttr>();
+ attrs.add(writeIntents(attachPoint, operation));
+ attrs.add(writePolicySets(attachPoint, operation));
+ return new XAttr(null, attrs);
+ }
+
+ /**
+ * Write policies
+ * @param attachPoint
+ * @return
+ */
+ public void writePolicyAttributes(Object attachPoint, Operation operation, XMLStreamWriter writer) throws XMLStreamException {
+ XAttr attr = writePolicies(attachPoint, operation);
+ attr.write(writer);
+ }
+
+ /**
+ * Write policies
+ * @param attachPoint
+ * @return
+ */
+ public void writePolicyPrefixes(Object attachPoint, Operation operation, XMLStreamWriter writer) throws XMLStreamException {
+ XAttr attr = writePolicies(attachPoint, operation);
+ attr.writePrefix(writer);
+ }
+
+ /**
+ * Write policy intents associated with an operation.
+ * @param attachPoint
+ * @param operation
+ */
+ private XAttr writeIntents(Object attachPoint, Operation operation) {
+ if (!(attachPoint instanceof IntentAttachPoint)) {
+ return null;
+ }
+ IntentAttachPoint intentAttachPoint = (IntentAttachPoint)attachPoint;
+ List<QName> qnames = new ArrayList<QName>();
+ for (Intent intent: intentAttachPoint.getRequiredIntents()) {
+ qnames.add(intent.getName());
+ }
+ return new XAttr(Constants.REQUIRES, qnames);
+ }
+
+ /**
+ * Write policy sets associated with an operation.
+ * @param attachPoint
+ * @param operation
+ */
+ private XAttr writePolicySets(Object attachPoint, Operation operation) {
+ if (!(attachPoint instanceof PolicySetAttachPoint)) {
+ return null;
+ }
+ PolicySetAttachPoint policySetAttachPoint = (PolicySetAttachPoint)attachPoint;
+ List<QName> qnames = new ArrayList<QName>();
+ for (PolicySet policySet: policySetAttachPoint.getPolicySets()) {
+ qnames.add(policySet.getName());
+ }
+ return new XAttr(Constants.POLICY_SETS, qnames);
+ }
+
+ public void resolvePolicies(Object attachPoint, ModelResolver resolver) {
+ if ( attachPoint instanceof PolicySetAttachPoint ) {
+ PolicySetAttachPoint policySetAttachPoint = (PolicySetAttachPoint)attachPoint;
+
+ List<Intent> requiredIntents = new ArrayList<Intent>();
+ Intent resolvedIntent = null;
+
+ if ( policySetAttachPoint.getRequiredIntents() != null && policySetAttachPoint.getRequiredIntents().size() > 0 ) {
+ for ( Intent intent : policySetAttachPoint.getRequiredIntents() ) {
+ resolvedIntent = resolver.resolveModel(Intent.class, intent);
+ requiredIntents.add(resolvedIntent);
+ }
+ policySetAttachPoint.getRequiredIntents().clear();
+ policySetAttachPoint.getRequiredIntents().addAll(requiredIntents);
+ }
+
+ if ( policySetAttachPoint.getPolicySets() != null && policySetAttachPoint.getPolicySets().size() > 0 ) {
+ List<PolicySet> resolvedPolicySets = new ArrayList<PolicySet>();
+ PolicySet resolvedPolicySet = null;
+ for ( PolicySet policySet : policySetAttachPoint.getPolicySets() ) {
+ resolvedPolicySet = resolver.resolveModel(PolicySet.class, policySet);
+ resolvedPolicySets.add(resolvedPolicySet);
+ }
+ policySetAttachPoint.getPolicySets().clear();
+ policySetAttachPoint.getPolicySets().addAll(resolvedPolicySets);
+ }
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
new file mode 100644
index 0000000000..7a190dea9c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -0,0 +1,21 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for the artifact processor extension
+org.apache.tuscany.sca.assembly.xml.ComponentTypeProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#componentType,model=org.apache.tuscany.sca.assembly.ComponentType
+org.apache.tuscany.sca.assembly.xml.ConstrainingTypeProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#constrainingType,model=org.apache.tuscany.sca.assembly.ConstrainingType
+org.apache.tuscany.sca.assembly.xml.CompositeProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#composite,model=org.apache.tuscany.sca.assembly.Composite
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor
new file mode 100644
index 0000000000..403c049b48
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor
@@ -0,0 +1,21 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for the artifact processor extension
+org.apache.tuscany.sca.assembly.xml.ComponentTypeDocumentProcessor;type=.componentType,model=org.apache.tuscany.sca.assembly.ComponentType
+org.apache.tuscany.sca.assembly.xml.ConstrainingTypeDocumentProcessor;type=.constrainingType,model=org.apache.tuscany.sca.assembly.ConstrainingType
+org.apache.tuscany.sca.assembly.xml.CompositeDocumentProcessor;type=.composite,model=org.apache.tuscany.sca.assembly.Composite
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver
new file mode 100644
index 0000000000..ecc34942f1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver
@@ -0,0 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.assembly.xml.CompositeModelResolver;model=org.apache.tuscany.sca.assembly.Composite
+org.apache.tuscany.sca.assembly.xml.ConstrainingTypeModelResolver;model=org.apache.tuscany.sca.assembly.ConstrainingType
+org.apache.tuscany.sca.assembly.xml.ComponentTypeModelResolver;model=org.apache.tuscany.sca.assembly.ComponentType
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties
new file mode 100644
index 0000000000..95edf89e30
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/main/resources/assembly-xml-validation-messages.properties
@@ -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.
+#
+#
+NoCompositeNamespace = No namespace found: Composite = {0}
+UnexpectedInterfaceElement = Unexpected <interface> element found. It should appear inside a <service> or <reference> element.
+UnexpectedBindingElement = Unexpected <binding> element found. It should appear inside a <service> or <reference> element.
+UnexpectedImplementationElement = Unexpected <implementation> element found. It should appear inside a <component> element.
+PolicyImplValidationException = PolicyValidation exception when processing implementation of component {0} due to {1}.
+PolicyServiceValidationException = PolicyValidation exceptions when processing service/reference {0} in {1}. Error is {2}
+ContributionReadException = ContributionReadException occured due to : {0}
+ContributionWriteException = ContributionWriteException occured due to : {0}
+
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java
new file mode 100644
index 0000000000..5f8f976b84
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/BuildPolicyTestCase.java
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.assembly.OperationsConfigurator;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.DefaultURLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl;
+import org.apache.tuscany.sca.policy.IntentAttachPoint;
+import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
+
+/**
+ * Test reading SCA XML assembly documents.
+ *
+ * @version $Rev: 561254 $ $Date: 2007-07-31 13:16:27 +0530 (Tue, 31 Jul 2007) $
+ */
+public class BuildPolicyTestCase extends TestCase {
+ private URLArtifactProcessor<Object> documentProcessor;
+ private URLArtifactProcessor<SCADefinitions> policyDefinitionsProcessor;
+ private ModelResolver resolver;
+ private CompositeBuilder compositeBuilder;
+ private Composite composite;
+ private Monitor monitor;
+
+ @Override
+ public void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ SCABindingFactory scaBindingFactory = new TestSCABindingFactoryImpl();
+ IntentAttachPointTypeFactory attachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class);
+ List<SCADefinitions> policyDefinitions = new ArrayList<SCADefinitions>();
+ resolver = new DefaultModelResolver();
+
+ MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl();
+ monitor = monitorFactory.createMonitor();
+
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class);
+
+ compositeBuilder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, attachPointTypeFactory, mapper, monitor);
+ URLArtifactProcessorExtensionPoint documentProcessors = new DefaultURLArtifactProcessorExtensionPoint(extensionPoints);
+ documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null);
+ policyDefinitionsProcessor = documentProcessors.getProcessor(SCADefinitions.class);
+
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessors.addArtifactProcessor(new TestPolicyProcessor());
+
+ URL url = getClass().getResource("CalculatorComponent.constrainingType");
+ URI uri = URI.create("CalculatorComponent.constrainingType");
+ ConstrainingType constrainingType = (ConstrainingType)documentProcessor.read(null, uri, url);
+ assertNotNull(constrainingType);
+ resolver.addModel(constrainingType);
+
+ url = getClass().getResource("TestAllPolicyCalculator.composite");
+ uri = URI.create("TestAllCalculator.constrainingType");
+ composite = (Composite)documentProcessor.read(null, uri, url);
+ assertNotNull(composite);
+
+ url = getClass().getResource("another_test_definitions.xml");
+ uri = URI.create("another_test_definitions.xml");
+ SCADefinitions definitions = (SCADefinitions)policyDefinitionsProcessor.read(null, uri, url);
+ assertNotNull(definitions);
+ policyDefinitions.add(definitions);
+
+ documentProcessor.resolve(definitions, resolver);
+ documentProcessor.resolve(composite, resolver);
+
+ compositeBuilder.build(composite);
+ }
+
+ public void testPolicyIntentInheritance() throws Exception {
+ String namespaceUri = "http://test";
+
+ IntentAttachPoint policiedComposite = (IntentAttachPoint)composite;
+ assertEquals(policiedComposite.getRequiredIntents().size(), 1);
+ assertEquals(policiedComposite.getRequiredIntents().get(0).getName(), new QName(namespaceUri, "tuscanyIntent_1"));
+
+ //1 defined for composite, 2 defined for the service, 1 defined and 3 inherited for the promoted service (4)
+ assertEquals(composite.getServices().get(0).getRequiredIntents().size(), 7);
+ //1 from the operation defined in this service and 2 from the operation defined in the promoted service
+ assertEquals(composite.getServices().get(0).getConfiguredOperations().get(0).getRequiredIntents().size(), 5);
+ assertEquals(composite.getServices().get(0).getRequiredIntents().get(3).getName(), new QName(namespaceUri, "tuscanyIntent_3"));
+ //bindings will have only 2 intents since duplications will be cut out
+ assertEquals(((IntentAttachPoint)composite.getServices().get(0).getBindings().get(0)).getRequiredIntents().size(), 3);
+ assertEquals(((OperationsConfigurator)composite.getServices().get(0).getBindings().get(0)).getConfiguredOperations().size(), 1);
+ assertEquals(((OperationsConfigurator)composite.getServices().get(0).getBindings().get(0)).getConfiguredOperations().get(0).getRequiredIntents().size(), 5);
+
+ assertEquals(composite.getReferences().get(0).getRequiredIntents().size(), 5);
+ assertEquals(composite.getReferences().get(0).getConfiguredOperations().size(), 1);
+ assertEquals(composite.getReferences().get(0).getConfiguredOperations().get(0).getRequiredIntents().size(), 4);
+ assertEquals(composite.getReferences().get(0).getRequiredIntents().get(1).getName(), new QName(namespaceUri, "tuscanyIntent_1"));
+ assertEquals(((IntentAttachPoint)composite.getReferences().get(0).getBindings().get(0)).getRequiredIntents().size(), 3);
+
+ assertEquals(composite.getComponents().get(0).getRequiredIntents().size(), 3);
+ assertEquals(composite.getComponents().get(0).getRequiredIntents().get(2).getName(), new QName(namespaceUri, "tuscanyIntent_1"));
+ assertEquals(composite.getComponents().get(0).getServices().get(0).getRequiredIntents().size(), 4);
+ assertEquals(composite.getComponents().get(0).getServices().get(0).getCallback().getRequiredIntents().size(), 4);
+ assertEquals(composite.getComponents().get(0).getServices().get(0).getConfiguredOperations().get(0).getRequiredIntents().size(), 5);
+ assertEquals(composite.getComponents().get(0).getReferences().get(0).getRequiredIntents().size(), 5);
+ assertEquals(composite.getComponents().get(0).getReferences().get(0).getConfiguredOperations().get(0).getRequiredIntents().size(), 5);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java
new file mode 100644
index 0000000000..e2aeb85d32
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadAllTestCase.java
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import java.io.InputStream;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.Callback;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeReference;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Test reading SCA XML assemblies.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReadAllTestCase extends TestCase {
+ private StAXArtifactProcessor<Object> staxProcessor;
+ private XMLInputFactory inputFactory;
+
+ @Override
+ public void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ inputFactory = XMLInputFactory.newInstance();
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null);
+ }
+
+ public void testReadComposite() throws Exception {
+ InputStream is = getClass().getResourceAsStream("TestAllCalculator.composite");
+ Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is));
+ assertNotNull(composite);
+ assertEquals(composite.getName(), new QName("http://calc", "TestAllCalculator"));
+ assertEquals(composite.getConstrainingType().getName(), new QName("http://calc", "CalculatorComponent"));
+ assertTrue(composite.isLocal());
+ assertFalse(composite.getAutowire() == Boolean.TRUE);
+ assertEquals(((PolicySetAttachPoint)composite).getRequiredIntents().get(0).getName(), new QName("http://test",
+ "confidentiality"));
+ assertEquals(((PolicySetAttachPoint)composite).getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
+
+ Composite include = composite.getIncludes().get(0);
+ assertEquals(include.getName(), new QName("http://calc", "TestAllDivide"));
+
+ CompositeService calcCompositeService = (CompositeService)composite.getServices().get(0);
+ assertEquals(calcCompositeService.getName(), "CalculatorService");
+ assertTrue(calcCompositeService.getPromotedService().isUnresolved());
+ assertEquals(calcCompositeService.getPromotedService().getName(),
+ "CalculatorService");
+ assertEquals(calcCompositeService.getRequiredIntents().get(0).getName(),
+ new QName("http://test", "confidentiality"));
+ assertEquals(calcCompositeService.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
+ // TODO test operations
+ Callback calcServiceCallback = calcCompositeService.getCallback();
+ assertNotNull(calcServiceCallback);
+ assertEquals(calcServiceCallback.getRequiredIntents().get(0).getName(),
+ new QName("http://test", "confidentiality"));
+ assertEquals(calcServiceCallback.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
+ // TODO test operations
+
+ Component calcComponent = composite.getComponents().get(0);
+ assertEquals(calcComponent.getName(), "CalculatorServiceComponent");
+ assertEquals(calcComponent.getAutowire(), Boolean.FALSE);
+ assertEquals(calcComponent.getConstrainingType().getName(), new QName("http://calc",
+ "CalculatorComponent"));
+ assertEquals(calcComponent.getRequiredIntents().get(0).getName(), new QName("http://test",
+ "confidentiality"));
+ assertEquals(calcComponent.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
+
+ ComponentService calcComponentService = calcComponent.getServices().get(0);
+ assertEquals(calcComponentService.getName(), "CalculatorService");
+ assertEquals(calcComponentService.getRequiredIntents().get(0).getName(),
+ new QName("http://test", "confidentiality"));
+ assertEquals(calcComponentService.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
+ // TODO test operations
+
+ ComponentReference calcComponentReference = calcComponent.getReferences().get(0);
+ assertEquals(calcComponentReference.getName(), "addService");
+ assertEquals(calcComponentReference.getAutowire(), Boolean.FALSE);
+ assertEquals(calcComponentReference.isWiredByImpl(), false);
+ assertEquals(calcComponentReference.getRequiredIntents().get(0).getName(),
+ new QName("http://test", "confidentiality"));
+ assertEquals(calcComponentReference.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
+ // TODO test operations
+
+ Property property = calcComponent.getProperties().get(0);
+ assertEquals(property.getName(), "round");
+ Document doc = (Document) property.getValue();
+ Element element = doc.getDocumentElement();
+ String value = element.getTextContent();
+ assertEquals(value, "true");
+ assertEquals(property.getXSDType(), new QName("http://www.w3.org/2001/XMLSchema", "boolean"));
+ assertEquals(property.isMany(), false);
+
+ CompositeReference calcCompositeReference = (CompositeReference)composite.getReferences().get(0);
+ assertEquals(calcCompositeReference.getName(), "MultiplyService");
+ assertTrue(calcCompositeReference.getPromotedReferences().get(0).isUnresolved());
+ assertEquals(calcCompositeReference.getPromotedReferences().get(0).getName(),
+ "CalculatorServiceComponent/multiplyService");
+ assertEquals(calcCompositeReference.getRequiredIntents().get(0).getName(),
+ new QName("http://test", "confidentiality"));
+ assertEquals(calcCompositeReference.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
+ // TODO test operations
+ Callback calcCallback = calcCompositeReference.getCallback();
+ assertEquals(calcCompositeReference.getRequiredIntents().get(0).getName(),
+ new QName("http://test", "confidentiality"));
+ assertEquals(calcCompositeReference.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
+ assertNotNull(calcCallback);
+ // TODO test operations
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java
new file mode 100644
index 0000000000..111a517552
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadDocumentTestCase.java
@@ -0,0 +1,207 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import java.net.URI;
+import java.net.URL;
+
+import javax.xml.XMLConstants;
+import javax.xml.parsers.SAXParserFactory;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.ValidatorHandler;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.contribution.processor.DefaultValidatingXMLInputFactory;
+import org.apache.tuscany.sca.contribution.processor.DefaultValidationSchemaExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+
+/**
+ * Test reading SCA XML assembly documents.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReadDocumentTestCase extends TestCase {
+
+ private URLArtifactProcessor<Object> documentProcessor;
+ private ModelResolver resolver;
+ private XMLInputFactory inputFactory;
+ private StAXArtifactProcessor<Object> staxProcessor;
+
+ @Override
+ public void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null);
+
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ inputFactory = XMLInputFactory.newInstance();
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null);
+
+ resolver = new DefaultModelResolver();
+ }
+
+ public void testValidateAssembly() throws Exception {
+
+ SchemaFactory schemaFactory;
+ try {
+ schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ } catch (Error e) {
+ // Some old JDKs don't support XMLSchema validation
+ return;
+ } catch (Exception e) {
+ // Some old JDKs don't support XMLSchema validation
+ return;
+ }
+ Schema schema = schemaFactory.newSchema(getClass().getClassLoader().getResource("tuscany-sca.xsd"));
+ ValidatorHandler handler = schema.newValidatorHandler();
+
+ SAXParserFactory parserFactory = SAXParserFactory.newInstance();
+ URL url = getClass().getResource("Calculator.composite");
+ XMLReader reader = parserFactory.newSAXParser().getXMLReader();
+ reader.setFeature("http://xml.org/sax/features/namespaces", true);
+ reader.setContentHandler(handler);
+ reader.parse(new InputSource(url.openStream()));
+
+ }
+
+ public void testValidateImplementation() throws Exception {
+
+ SchemaFactory schemaFactory;
+ try {
+ schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ } catch (Error e) {
+ // Some old JDKs don't support XMLSchema validation
+ return;
+ } catch (Exception e) {
+ // Some old JDKs don't support XMLSchema validation
+ return;
+ }
+ Schema schema = schemaFactory.newSchema(getClass().getClassLoader().getResource("tuscany-sca.xsd"));
+ ValidatorHandler handler = schema.newValidatorHandler();
+
+ SAXParserFactory parserFactory = SAXParserFactory.newInstance();
+ URL url = getClass().getResource("JavaScriptReference.composite");
+ XMLReader reader = parserFactory.newSAXParser().getXMLReader();
+ reader.setFeature("http://xml.org/sax/features/namespaces", true);
+ reader.setContentHandler(handler);
+ reader.parse(new InputSource(url.openStream()));
+ }
+
+ public void testReadImplementation() throws Exception {
+
+ ValidationSchemaExtensionPoint schemas = new DefaultValidationSchemaExtensionPoint();
+ schemas.addSchema(getClass().getClassLoader().getResource("tuscany-sca.xsd").toString());
+ XMLInputFactory validatingInputFactory = new DefaultValidatingXMLInputFactory(inputFactory, schemas, null);
+ CompositeDocumentProcessor compositeDocumentProcessor = new CompositeDocumentProcessor(staxProcessor, validatingInputFactory, null, null);
+
+ URL url = getClass().getResource("JavaScriptReference.composite");
+ URI uri = URI.create("JavaScriptReference.composite");
+ Composite composite = (Composite)compositeDocumentProcessor.read(null, uri, url);
+ assertNotNull(composite);
+ }
+
+ public void testValidateBinding() throws Exception {
+
+ SchemaFactory schemaFactory;
+ try {
+ schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ } catch (Error e) {
+ // Some old JDKs don't support XMLSchema validation
+ return;
+ } catch (Exception e) {
+ // Some old JDKs don't support XMLSchema validation
+ return;
+ }
+ Schema schema = schemaFactory.newSchema(getClass().getClassLoader().getResource("tuscany-sca.xsd"));
+ ValidatorHandler handler = schema.newValidatorHandler();
+
+ SAXParserFactory parserFactory = SAXParserFactory.newInstance();
+ URL url = getClass().getResource("RMIBindingTest.composite");
+ XMLReader reader = parserFactory.newSAXParser().getXMLReader();
+ reader.setFeature("http://xml.org/sax/features/namespaces", true);
+ reader.setContentHandler(handler);
+ reader.parse(new InputSource(url.openStream()));
+ }
+
+ public void testReadBinding() throws Exception {
+
+ ValidationSchemaExtensionPoint schemas = new DefaultValidationSchemaExtensionPoint();
+ schemas.addSchema(getClass().getClassLoader().getResource("tuscany-sca.xsd").toString());
+ XMLInputFactory validatingInputFactory = new DefaultValidatingXMLInputFactory(inputFactory, schemas, null);
+ CompositeDocumentProcessor compositeDocumentProcessor = new CompositeDocumentProcessor(staxProcessor, validatingInputFactory, null, null);
+
+ URL url = getClass().getResource("RMIBindingTest.composite");
+ URI uri = URI.create("RMIBindingTest.composite");
+ Composite composite = (Composite)compositeDocumentProcessor.read(null, uri, url);
+ assertNotNull(composite);
+ }
+
+ public void testResolveConstrainingType() throws Exception {
+
+ URL url = getClass().getResource("CalculatorComponent.constrainingType");
+ URI uri = URI.create("CalculatorComponent.constrainingType");
+ ConstrainingType constrainingType = (ConstrainingType)documentProcessor.read(null, uri, url);
+ assertNotNull(constrainingType);
+ resolver.addModel(constrainingType);
+
+ url = getClass().getResource("TestAllCalculator.composite");
+ uri = URI.create("TestAllCalculator.constrainingType");
+ Composite composite = (Composite)documentProcessor.read(null, uri, url);
+ assertNotNull(composite);
+
+ documentProcessor.resolve(composite, resolver);
+
+ assertEquals(composite.getConstrainingType(), constrainingType);
+ assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType);
+ }
+
+ public void testResolveComposite() throws Exception {
+ URL url = getClass().getResource("Calculator.composite");
+ URI uri = URI.create("Calculator.composite");
+ Composite nestedComposite = (Composite)documentProcessor.read(null, uri, url);
+ assertNotNull(nestedComposite);
+ resolver.addModel(nestedComposite);
+
+ url = getClass().getResource("TestAllCalculator.composite");
+ uri = URI.create("TestAllCalculator.composite");
+ Composite composite = (Composite)documentProcessor.read(null, uri, url);
+
+ documentProcessor.resolve(composite, resolver);
+
+ assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java
new file mode 100644
index 0000000000..1aede413a5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadTestCase.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import java.io.InputStream;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+
+/**
+ * Test reading SCA XML assemblies.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReadTestCase extends TestCase {
+
+ private XMLInputFactory inputFactory;
+ private StAXArtifactProcessor<Object> staxProcessor;
+
+ @Override
+ public void setUp() throws Exception {
+ ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ inputFactory = XMLInputFactory.newInstance();
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance(), null);
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ }
+
+ public void testReadComponentType() throws Exception {
+ InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ assertNotNull(staxProcessor.read(reader));
+ is.close();
+ }
+
+ public void testReadConstrainingType() throws Exception {
+ InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ assertNotNull(staxProcessor.read(reader));
+ is.close();
+
+ }
+
+ public void testReadComposite() throws Exception {
+ InputStream is = getClass().getResourceAsStream("Calculator.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ assertNotNull(staxProcessor.read(reader));
+ is.close();
+
+ }
+
+ public void testReadCompositeAndWireIt() throws Exception {
+ InputStream is = getClass().getResourceAsStream("Calculator.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ assertNotNull(staxProcessor.read(reader));
+ is.close();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAttributeTestCase.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAttributeTestCase.java
new file mode 100644
index 0000000000..9b88ad3a3d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ReadWriteAttributeTestCase.java
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+
+/**
+ * Test reading SCA XML assemblies.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReadWriteAttributeTestCase extends TestCase {
+
+ private XMLInputFactory inputFactory;
+ private ExtensibleStAXArtifactProcessor staxProcessor;
+
+ private static final QName ATTRIBUTE = new QName("http://test", "customAttribute");
+
+ private static final String XML = "<?xml version='1.0' encoding='UTF-8'?>"+
+ "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns1=\"http://www.osoa.org/xmlns/sca/1.0\" targetNamespace=\"http://calc\" name=\"Calculator\">"+
+ "<service name=\"CalculatorService\" promote=\"CalculatorServiceComponent\">"+
+ "<interface.java xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" interface=\"calculator.CalculatorService\" />"+
+ "</service>"+
+ "<component name=\"CalculatorServiceComponent\" customAttribute=\"customValue\">"+
+ "<reference name=\"addService\" target=\"AddServiceComponent\" />"+
+ "<reference name=\"subtractService\" target=\"SubtractServiceComponent\" />"+
+ "<reference name=\"multiplyService\" target=\"MultiplyServiceComponent\" />"+
+ "<reference name=\"divideService\" target=\"DivideServiceComponent\" />"+
+ "</component>"+
+ "<component name=\"AddServiceComponent\" />"+
+ "<component name=\"SubtractServiceComponent\" />"+
+ "<component name=\"MultiplyServiceComponent\" />"+
+ "<component name=\"DivideServiceComponent\" />"+
+ "</composite>";
+
+ @Override
+ public void setUp() throws Exception {
+ ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ inputFactory = XMLInputFactory.newInstance();
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+
+ StAXAttributeProcessorExtensionPoint staxAttributeProcessors = extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class);
+ staxAttributeProcessors.addArtifactProcessor(new TestAttributeProcessor());
+
+
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance(), null);
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+
+ }
+
+ public void testReadComposite() throws Exception {
+ InputStream is = getClass().getResourceAsStream("CalculatorExtended.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = (Composite) staxProcessor.read(reader);
+ assertNotNull(composite);
+ is.close();
+ }
+
+ public void testWriteComposite() throws Exception {
+ InputStream is = getClass().getResourceAsStream("CalculatorExtended.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = (Composite) staxProcessor.read(reader);
+ assertNotNull(composite);
+ is.close();
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(composite, bos);
+ System.out.println(bos.toString());
+
+ assertEquals(XML, bos.toString());
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java
new file mode 100644
index 0000000000..32a2d94220
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolvePolicyTestCase.java
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import java.net.URI;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+
+/**
+ * Test reading SCA XML assembly documents.
+ *
+ * @version $Rev: 561254 $ $Date: 2007-07-31 13:16:27 +0530 (Tue, 31 Jul 2007) $
+ */
+public class ResolvePolicyTestCase extends TestCase {
+
+ private URLArtifactProcessor<Object> documentProcessor;
+ private ModelResolver resolver;
+ private URLArtifactProcessor<SCADefinitions> policyDefinitionsProcessor;
+
+ @Override
+ public void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ resolver = new DefaultModelResolver();
+
+ URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, null);
+ policyDefinitionsProcessor = documentProcessors.getProcessor(SCADefinitions.class);
+
+ // Create StAX processors
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessors.addArtifactProcessor(new TestPolicyProcessor());
+ }
+
+ public void testResolveConstrainingType() throws Exception {
+
+ URL url = getClass().getResource("CalculatorComponent.constrainingType");
+ URI uri = URI.create("CalculatorComponent.constrainingType");
+ ConstrainingType constrainingType = (ConstrainingType)documentProcessor.read(null, uri, url);
+ assertNotNull(constrainingType);
+ resolver.addModel(constrainingType);
+
+ url = getClass().getResource("TestAllCalculator.composite");
+ uri = URI.create("TestAllCalculator.constrainingType");
+ Composite composite = (Composite)documentProcessor.read(null, uri, url);
+ assertNotNull(composite);
+
+ url = getClass().getResource("test_definitions.xml");
+ uri = URI.create("test_definitions.xml");
+ SCADefinitions scaDefns = (SCADefinitions)policyDefinitionsProcessor.read(null, uri, url);
+ assertNotNull(scaDefns);
+
+ preResolvePolicyTests(composite);
+ documentProcessor.resolve(scaDefns, resolver);
+ documentProcessor.resolve(composite, resolver);
+ postResolvePolicyTests(composite);
+
+ assertEquals(composite.getConstrainingType(), constrainingType);
+ assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType);
+ }
+
+ private void preResolvePolicyTests(Composite composite) {
+ assertNull(((PolicySetAttachPoint)composite).getRequiredIntents().get(0).getDescription());
+ assertTrue(((PolicySetAttachPoint)composite).getPolicySets().get(0).getProvidedIntents().isEmpty());
+
+ assertNull(composite.getServices().get(0).getRequiredIntents().get(0).getDescription());
+ assertTrue(composite.getServices().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
+ assertNull(composite.getServices().get(0).getCallback().getRequiredIntents().get(0).getDescription());
+ assertTrue(composite.getServices().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().isEmpty());
+
+ assertNull(composite.getComponents().get(0).getRequiredIntents().get(0).getDescription());
+ assertTrue(composite.getComponents().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
+ assertNull(composite.getComponents().get(0).getServices().get(0).getRequiredIntents().get(0).getDescription());
+ assertTrue(composite.getComponents().get(0).getServices().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
+ assertNull(composite.getComponents().get(0).getReferences().get(0).getRequiredIntents().get(0).getDescription());
+ assertTrue(composite.getComponents().get(0).getReferences().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
+
+ assertNull(composite.getReferences().get(0).getRequiredIntents().get(0).getDescription());
+ assertTrue(composite.getReferences().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
+ assertNull(composite.getReferences().get(0).getCallback().getRequiredIntents().get(0).getDescription());
+ assertTrue(composite.getReferences().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().isEmpty());
+ }
+
+ private void postResolvePolicyTests(Composite composite) {
+ assertNotNull(((PolicySetAttachPoint)composite).getRequiredIntents().get(0).getDescription());
+ assertFalse(((PolicySetAttachPoint)composite).getPolicySets().get(0).getProvidedIntents().isEmpty());
+ assertNotNull(((PolicySetAttachPoint)composite).getPolicySets().get(0).getProvidedIntents().get(1).getDescription());
+
+ assertNotNull(composite.getServices().get(0).getRequiredIntents().get(0).getDescription());
+ assertFalse(composite.getServices().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
+ assertNotNull(composite.getServices().get(0).getPolicySets().get(0).getProvidedIntents().get(1).getDescription());
+ assertNotNull(composite.getServices().get(0).getCallback().getRequiredIntents().get(0).getDescription());
+ assertFalse(composite.getServices().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().isEmpty());
+ assertNotNull(composite.getServices().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().get(1).getDescription());
+
+ assertNotNull(composite.getComponents().get(0).getRequiredIntents().get(0).getDescription());
+ assertFalse(composite.getComponents().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
+ assertNotNull(composite.getComponents().get(0).getPolicySets().get(0).getProvidedIntents().get(1).getDescription());
+ assertNotNull(composite.getComponents().get(0).getServices().get(0).getRequiredIntents().get(0).getDescription());
+ assertFalse(composite.getComponents().get(0).getServices().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
+ assertNotNull(composite.getComponents().get(0).getServices().get(0).getPolicySets().get(0).getProvidedIntents().get(1).getDescription());
+ assertNotNull(composite.getComponents().get(0).getReferences().get(0).getRequiredIntents().get(0).getDescription());
+ assertFalse(composite.getComponents().get(0).getReferences().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
+ assertNotNull(composite.getComponents().get(0).getReferences().get(0).getPolicySets().get(0).getProvidedIntents().get(1).getDescription());
+
+ assertNotNull(composite.getReferences().get(0).getRequiredIntents().get(0).getDescription());
+ assertFalse(composite.getReferences().get(0).getPolicySets().get(0).getProvidedIntents().isEmpty());
+ assertNotNull(composite.getReferences().get(0).getPolicySets().get(0).getProvidedIntents().get(1).getDescription());
+ assertNotNull(composite.getReferences().get(0).getCallback().getRequiredIntents().get(0).getDescription());
+ assertFalse(composite.getReferences().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().isEmpty());
+ assertNotNull(composite.getReferences().get(0).getCallback().getPolicySets().get(0).getProvidedIntents().get(1).getDescription());
+
+
+ }
+
+ public void testResolveComposite() throws Exception {
+ URL url = getClass().getResource("Calculator.composite");
+ URI uri = URI.create("Calculator.composite");
+ Composite nestedComposite = (Composite)documentProcessor.read(null, uri, url);
+ assertNotNull(nestedComposite);
+ resolver.addModel(nestedComposite);
+
+ url = getClass().getResource("TestAllCalculator.composite");
+ uri = URI.create("TestAllCalculator.composite");
+ Composite composite = (Composite)documentProcessor.read(null, uri, url);
+
+ documentProcessor.resolve(composite, resolver);
+
+ assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java
new file mode 100644
index 0000000000..df09a56c38
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/ResolveTestCase.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import java.io.InputStream;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+
+/**
+ * Test resolving SCA XML assemblies.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ResolveTestCase extends TestCase {
+
+ private XMLInputFactory inputFactory;
+ private StAXArtifactProcessorExtensionPoint staxProcessors;
+ private ModelResolver resolver;
+
+ @Override
+ public void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ inputFactory = XMLInputFactory.newInstance();
+ staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ resolver = new DefaultModelResolver();
+ }
+
+ public void testResolveConstrainingType() throws Exception {
+ InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType");
+ StAXArtifactProcessor<ConstrainingType> constrainingTypeReader = staxProcessors.getProcessor(ConstrainingType.class);
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ ConstrainingType constrainingType = constrainingTypeReader.read(reader);
+ is.close();
+ assertNotNull(constrainingType);
+ resolver.addModel(constrainingType);
+
+ is = getClass().getResourceAsStream("TestAllCalculator.composite");
+ StAXArtifactProcessor<Composite> compositeReader = staxProcessors.getProcessor(Composite.class);
+ reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = compositeReader.read(reader);
+ is.close();
+ assertNotNull(composite);
+
+ compositeReader.resolve(composite, resolver);
+
+ assertEquals(composite.getConstrainingType(), constrainingType);
+ assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType);
+ }
+
+ public void testResolveComposite() throws Exception {
+ InputStream is = getClass().getResourceAsStream("Calculator.composite");
+ StAXArtifactProcessor<Composite> compositeReader = staxProcessors.getProcessor(Composite.class);
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite nestedComposite = compositeReader.read(reader);
+ is.close();
+ assertNotNull(nestedComposite);
+ resolver.addModel(nestedComposite);
+
+ is = getClass().getResourceAsStream("TestAllCalculator.composite");
+ reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = compositeReader.read(reader);
+ is.close();
+
+ compositeReader.resolve(composite, resolver);
+
+ assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java
new file mode 100644
index 0000000000..691145a30e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestAttributeProcessor.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly.xml;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+
+/**
+ * A Policy Processor used for testing.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestAttributeProcessor extends BaseStAXArtifactProcessor implements StAXAttributeProcessor<String> {
+ private static final QName ATTRIBUTE = new QName("http://test", "customAttribute");
+
+ public QName getArtifactType() {
+ return ATTRIBUTE;
+ }
+
+ public String read(QName attributeName, XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ return reader.getAttributeValue(attributeName.getNamespaceURI(), attributeName.getLocalPart());
+ }
+
+ public void write(String value, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+ writer.setPrefix(ATTRIBUTE.getPrefix(), ATTRIBUTE.getNamespaceURI());
+ writer.writeAttribute(ATTRIBUTE.getLocalPart(), value);
+ }
+
+ public Class<String> getModelType() {
+ return String.class;
+ }
+
+ public void resolve(String arg0, ModelResolver arg1) throws ContributionResolveException {
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestPolicyProcessor.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestPolicyProcessor.java
new file mode 100644
index 0000000000..16cefc58cf
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestPolicyProcessor.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly.xml;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.policy.Policy;
+
+/**
+ * A Policy Processor used for testing.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestPolicyProcessor implements StAXArtifactProcessor<Policy> {
+
+ public QName getArtifactType() {
+ return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment");
+ }
+
+ public Policy read(XMLStreamReader arg0) throws ContributionReadException, XMLStreamException {
+ return new MockPolicyImplOne();
+ }
+
+ public void write(Policy arg0, XMLStreamWriter arg1) throws ContributionWriteException,
+ XMLStreamException {
+ }
+
+ public Class<Policy> getModelType() {
+ return Policy.class;
+ }
+
+ public void resolve(Policy arg0, ModelResolver arg1) throws ContributionResolveException {
+ }
+
+
+ public class MockPolicyImplOne implements Policy {
+ public QName getSchemaName() {
+ return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment");
+ }
+
+ public boolean isUnresolved() {
+ return false;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ }
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestReadWriteUnkonwnElement.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestReadWriteUnkonwnElement.java
new file mode 100644
index 0000000000..3c1d9ba88e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestReadWriteUnkonwnElement.java
@@ -0,0 +1,60 @@
+package org.apache.tuscany.sca.assembly.xml;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+import java.util.Iterator;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.junit.Test;
+import org.w3c.dom.Document;
+
+public class TestReadWriteUnkonwnElement extends TestCase {
+
+ private XMLInputFactory inputFactory;
+ String XML = "<?xml version='1.0' encoding='UTF-8'?><composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns1=\"http://www.osoa.org/xmlns/sca/1.0\" targetNamespace=\"http://calc\" name=\"Calculator\"><service name=\"CalculatorService\" promote=\"CalculatorServiceComponent\"><interface.java xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" interface=\"calculator.CalculatorService\" /></service><component name=\"CalculatorServiceComponent\"><reference name=\"addService\" target=\"AddServiceComponent\" /><reference name=\"subtractService\" target=\"SubtractServiceComponent\" /><reference name=\"multiplyService\" target=\"MultiplyServiceComponent\" /><reference name=\"divideService\" target=\"DivideServiceComponent\" /></component><component name=\"AddServiceComponent\" /><component name=\"SubtractServiceComponent\" /><component name=\"MultiplyServiceComponent\" /><component name=\"DivideServiceComponent\" /><x:unknownElement xmlns:x=\"http://x\" uknAttr=\"attribute1\"><x:subUnknownElement1 uknAttr1=\"attribute1\" /><x:subUnknownElement2 /></x:unknownElement></composite>";
+ private ExtensibleStAXArtifactProcessor staxProcessor;
+
+ @Override
+ public void setUp() throws Exception {
+ ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ inputFactory = XMLInputFactory.newInstance();
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, XMLInputFactory.newInstance(), XMLOutputFactory.newInstance(), null);
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testReadWriteComposite() throws Exception{
+ InputStream is = getClass().getResourceAsStream("Calculator.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = (Composite)staxProcessor.read(reader);
+ assertNotNull(composite);
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(composite, bos);
+ System.out.println(bos.toString());
+ assertEquals(XML,bos.toString());
+ bos.close();
+
+ is.close();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingFactoryImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingFactoryImpl.java
new file mode 100644
index 0000000000..c423df6f7d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingFactoryImpl.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+
+/**
+ * A factory for the SCA binding model.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestSCABindingFactoryImpl implements SCABindingFactory {
+ public SCABinding createSCABinding() {
+ return new TestSCABindingImpl();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingImpl.java
new file mode 100644
index 0000000000..af25109de1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/TestSCABindingImpl.java
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly.xml;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.ConfiguredOperation;
+import org.apache.tuscany.sca.assembly.OperationsConfigurator;
+import org.apache.tuscany.sca.assembly.OptimizableBinding;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+
+/**
+ * A test cheel for the SCA binding.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestSCABindingImpl implements SCABinding, OptimizableBinding, PolicySetAttachPoint, OperationsConfigurator {
+ private String name;
+ private String uri;
+ private List<Object> extensions = new ArrayList<Object>();
+
+ private Component targetComponent;
+ private ComponentService targetComponentService;
+ private Binding targetBinding;
+
+ private List<Intent> requiredIntents = new ArrayList<Intent>();
+ private List<PolicySet> policySets = new ArrayList<PolicySet>();
+ private IntentAttachPointType bindingType = new TestSCABindingType();
+ private List<ConfiguredOperation> configuredOperations = new ArrayList<ConfiguredOperation>();
+ private List<PolicySet> applicablePolicySets = new ArrayList<PolicySet>();
+
+ /**
+ * Constructs a new SCA binding.
+ */
+ protected TestSCABindingImpl() {
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getURI() {
+ return uri;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setURI(String uri) {
+ this.uri = uri;
+ }
+
+ public List<Object> getExtensions() {
+ return extensions;
+ }
+
+ public boolean isUnresolved() {
+ return false;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ }
+
+ /**
+ * @see java.lang.Object#clone()
+ */
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+ /**
+ * @return the targetComponent
+ */
+ public Component getTargetComponent() {
+ return targetComponent;
+ }
+
+ /**
+ * @param targetComponent the targetComponent to set
+ */
+ public void setTargetComponent(Component targetComponent) {
+ this.targetComponent = targetComponent;
+ }
+
+ /**
+ * @return the targetComponentService
+ */
+ public ComponentService getTargetComponentService() {
+ return targetComponentService;
+ }
+
+ /**
+ * @param targetComponentService the targetComponentService to set
+ */
+ public void setTargetComponentService(ComponentService targetComponentService) {
+ this.targetComponentService = targetComponentService;
+ }
+
+ /**
+ * @return the targetBinding
+ */
+ public Binding getTargetBinding() {
+ return targetBinding;
+ }
+
+ /**
+ * @param targetBinding the targetBinding to set
+ */
+ public void setTargetBinding(Binding targetBinding) {
+ this.targetBinding = targetBinding;
+ }
+
+ public List<PolicySet> getPolicySets() {
+ // TODO Auto-generated method stub
+ return policySets;
+ }
+
+ public List<Intent> getRequiredIntents() {
+ // TODO Auto-generated method stub
+ return requiredIntents;
+ }
+
+ public IntentAttachPointType getType() {
+ // TODO Auto-generated method stub
+ return bindingType;
+ }
+
+ public void setType(IntentAttachPointType type) {
+ this.bindingType = type;
+ }
+
+ private class TestSCABindingType implements IntentAttachPointType {
+ private QName name = new QName("http://www.osoa.org/xmlns/sca/1.0","binding");
+
+ public List<Intent> getAlwaysProvidedIntents() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public List<Intent> getMayProvideIntents() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public QName getName() {
+ return name;
+ }
+
+ public boolean isUnresolved() {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ public void setName(QName type) {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ // TODO Auto-generated method stub
+
+ }
+
+ }
+
+ public void setPolicySets(List<PolicySet> policySets) {
+ this.policySets = policySets;
+ }
+
+ public void setRequiredIntents(List<Intent> intents) {
+ this.requiredIntents = intents;
+ }
+
+ public List<ConfiguredOperation> getConfiguredOperations() {
+ return configuredOperations;
+ }
+
+ public void setConfiguredOperations(List<ConfiguredOperation> configuredOperations) {
+ this.configuredOperations = configuredOperations;
+ }
+
+ public List<PolicySet> getApplicablePolicySets() {
+ return applicablePolicySets;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java
new file mode 100644
index 0000000000..76361d4b70
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WireTestCase.java
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl;
+import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
+
+/**
+ * Test the wiring of SCA XML assemblies.
+ *
+ * @version $Rev$ $Date$
+ */
+public class WireTestCase extends TestCase {
+
+ private XMLInputFactory inputFactory;
+ private StAXArtifactProcessor<Object> staxProcessor;
+ private ModelResolver resolver;
+ private URLArtifactProcessor<SCADefinitions> policyDefinitionsProcessor;
+ private CompositeBuilder compositeBuilder;
+ private Monitor monitor;
+
+ @Override
+ public void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ inputFactory = XMLInputFactory.newInstance();
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null);
+ resolver = new DefaultModelResolver();
+
+ MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl();
+ monitor = monitorFactory.createMonitor();
+
+ ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ SCABindingFactory scaBindingFactory = new TestSCABindingFactoryImpl();
+ IntentAttachPointTypeFactory attachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class);
+
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class);
+ compositeBuilder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, attachPointTypeFactory, mapper, monitor);
+
+ URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ policyDefinitionsProcessor = documentProcessors.getProcessor(SCADefinitions.class);
+ }
+
+ public void testResolveConstrainingType() throws Exception {
+ InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ ConstrainingType constrainingType = (ConstrainingType)staxProcessor.read(reader);
+ is.close();
+ assertNotNull(constrainingType);
+ resolver.addModel(constrainingType);
+
+ is = getClass().getResourceAsStream("TestAllCalculator.composite");
+ reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = (Composite)staxProcessor.read(reader);
+ is.close();
+ assertNotNull(composite);
+
+ URL url = getClass().getResource("test_definitions.xml");
+ URI uri = URI.create("test_definitions.xml");
+ SCADefinitions scaDefns = (SCADefinitions)policyDefinitionsProcessor.read(null, uri, url);
+ assertNotNull(scaDefns);
+
+ policyDefinitionsProcessor.resolve(scaDefns, resolver);
+
+ staxProcessor.resolve(composite, resolver);
+ compositeBuilder.build(composite);
+
+ assertEquals(composite.getConstrainingType(), constrainingType);
+ assertEquals(composite.getComponents().get(0).getConstrainingType(), constrainingType);
+ }
+
+ public void testResolveComposite() throws Exception {
+ InputStream is = getClass().getResourceAsStream("Calculator.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite nestedComposite = (Composite)staxProcessor.read(reader);
+ is.close();
+ assertNotNull(nestedComposite);
+ resolver.addModel(nestedComposite);
+
+ is = getClass().getResourceAsStream("TestAllCalculator.composite");
+ reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = (Composite)staxProcessor.read(reader);
+ is.close();
+
+ URL url = getClass().getResource("test_definitions.xml");
+ URI uri = URI.create("test_definitions.xml");
+ SCADefinitions scaDefns = (SCADefinitions)policyDefinitionsProcessor.read(null, uri, url);
+ assertNotNull(scaDefns);
+
+ policyDefinitionsProcessor.resolve(scaDefns, resolver);
+
+ staxProcessor.resolve(composite, resolver);
+ compositeBuilder.build(composite);
+
+ assertEquals(composite.getComponents().get(2).getImplementation(), nestedComposite);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java
new file mode 100644
index 0000000000..b859779437
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteAllTestCase.java
@@ -0,0 +1,160 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl;
+import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
+
+/**
+ * Test writing SCA XML assemblies.
+ *
+ * @version $Rev$ $Date$
+ */
+public class WriteAllTestCase extends TestCase {
+ private XMLInputFactory inputFactory;
+ private XMLOutputFactory outputFactory;
+ private ExtensibleStAXArtifactProcessor staxProcessor;
+ private ModelResolver resolver;
+ private CompositeBuilder compositeBuilder;
+ private URLArtifactProcessor<SCADefinitions> policyDefinitionsProcessor;
+ private Monitor monitor;
+
+ @Override
+ public void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ inputFactory = XMLInputFactory.newInstance();
+ outputFactory = XMLOutputFactory.newInstance();
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null);
+ resolver = new DefaultModelResolver();
+
+ ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ SCABindingFactory scaBindingFactory = new TestSCABindingFactoryImpl();
+ IntentAttachPointTypeFactory attachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class);
+
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class);
+
+ MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl();
+ monitor = monitorFactory.createMonitor();
+
+ compositeBuilder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, attachPointTypeFactory, mapper, monitor);
+
+ URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ policyDefinitionsProcessor = documentProcessors.getProcessor(SCADefinitions.class);
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ }
+
+ public void testReadWriteComposite() throws Exception {
+ InputStream is = getClass().getResourceAsStream("TestAllCalculator.composite");
+ Composite composite = staxProcessor.read(is, Composite.class);
+
+ verifyComposite(composite);
+
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(composite, bos);
+ bos.close();
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ composite = staxProcessor.read(bis, Composite.class);
+
+ verifyComposite(composite);
+
+ }
+
+ public void testReadWireWriteComposite() throws Exception {
+ InputStream is = getClass().getResourceAsStream("TestAllCalculator.composite");
+ Composite composite = staxProcessor.read(is, Composite.class);
+
+ URL url = getClass().getResource("test_definitions.xml");
+ URI uri = URI.create("test_definitions.xml");
+ SCADefinitions scaDefns = (SCADefinitions)policyDefinitionsProcessor.read(null, uri, url);
+ assertNotNull(scaDefns);
+ policyDefinitionsProcessor.resolve(scaDefns, resolver);
+
+ staxProcessor.resolve(composite, resolver);
+ compositeBuilder.build(composite);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(composite, bos);
+ }
+
+ public void testReadWriteComponentType() throws Exception {
+ InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType");
+ ComponentType componentType = staxProcessor.read(is, ComponentType.class);
+ staxProcessor.resolve(componentType, resolver);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(componentType, bos);
+ }
+
+ public void testReadWriteConstrainingType() throws Exception {
+ InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType");
+ ConstrainingType constrainingType = staxProcessor.read(is, ConstrainingType.class);
+ staxProcessor.resolve(constrainingType, resolver);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(constrainingType, bos);
+ }
+
+ private void verifyComposite(Composite composite) {
+ assertEquals(composite.getProperties().get(0).getName(),"prop1");
+ assertEquals(composite.getProperties().get(0).isMany(), true);
+ assertEquals(composite.getProperties().get(1).getName(),"prop2");
+ assertEquals(composite.getProperties().get(1).isMustSupply(), true);
+ assertEquals(composite.getProperties().get(0).getXSDType(), new QName("http://foo", "MyComplexType"));
+ assertEquals(composite.getProperties().get(1).getXSDElement(), new QName("http://www.osoa.org/xmlns/sca/1.0", "MyComplexPropertyValue1"));
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteNamespacesTestCase.java b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteNamespacesTestCase.java
new file mode 100644
index 0000000000..5188b1c91a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/java/org/apache/tuscany/sca/assembly/xml/WriteNamespacesTestCase.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.xml;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+
+/**
+ * Test writing SCA XML assemblies.
+ *
+ * @version $Rev$ $Date$
+ */
+public class WriteNamespacesTestCase extends TestCase {
+ private StAXArtifactProcessor<Composite> compositeProcessor;
+ private XMLOutputFactory outputFactory;
+ private XMLInputFactory inputFactory;
+
+ @Override
+ public void setUp() throws Exception {
+ ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ outputFactory = modelFactories.getFactory(XMLOutputFactory.class);
+ //outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+ inputFactory = modelFactories.getFactory(XMLInputFactory.class);
+
+ StAXArtifactProcessorExtensionPoint artifactProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ compositeProcessor = artifactProcessors.getProcessor(Composite.class);
+ }
+
+ public void testReadWriteComposite() throws Exception {
+
+ // Read
+ InputStream is = getClass().getResourceAsStream("NestedCalculator.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = compositeProcessor.read(reader);
+ Component component = composite.getComponents().get(0);
+ Composite implementation = (Composite)component.getImplementation();
+ QName qname = implementation.getName();
+
+ // Write
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ XMLStreamWriter writer = outputFactory.createXMLStreamWriter(bos);
+ compositeProcessor.write(composite, writer);
+ System.out.println(bos);
+
+ // Read again
+ is = new ByteArrayInputStream(bos.toByteArray());
+ reader = inputFactory.createXMLStreamReader(is);
+ composite = compositeProcessor.read(reader);
+
+ // Compare
+ component = composite.getComponents().get(0);
+ implementation = (Composite)component.getImplementation();
+ assertEquals(qname, implementation.getName());
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite
new file mode 100644
index 0000000000..85f6a39243
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/Calculator.composite
@@ -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:x="http://x"
+ xmlns:calc="http://calc"
+ targetNamespace="http://calc"
+ name="Calculator">
+
+ <service name="CalculatorService" promote="CalculatorServiceComponent">
+ <interface.java interface="calculator.CalculatorService"/>
+ </service>
+ <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>
+
+ <x:unknownElement uknAttr="attribute1">
+ <x:subUnknownElement1 uknAttr1="attribute1"/>
+ <x:subUnknownElement2/>
+ </x:unknownElement>
+
+
+</composite>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorComponent.constrainingType b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorComponent.constrainingType
new file mode 100644
index 0000000000..072fe8fde1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorComponent.constrainingType
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<constrainingType xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:calc="http://calc"
+ targetNamespace="http://calc"
+ name="CalculatorComponent">
+
+ <service name="CalculatorService">
+ <interface.java class="calculator.CalculatorService" />
+ </service>
+
+ <reference name="divideService">
+ <interface.java class="calculator.DivideService" />
+ </reference>
+
+</constrainingType>
+ \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorExtended.composite b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorExtended.composite
new file mode 100644
index 0000000000..3c69d0ed67
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorExtended.composite
@@ -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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:calc="http://calc"
+ xmlns:test="http://test"
+ targetNamespace="http://calc"
+ name="Calculator">
+
+ <service name="CalculatorService" promote="CalculatorServiceComponent">
+ <interface.java interface="calculator.CalculatorService"/>
+ </service>
+
+ <component name="CalculatorServiceComponent" test:customAttribute="customValue">
+ <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/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorImpl.componentType b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorImpl.componentType
new file mode 100644
index 0000000000..d67ba3ec2b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/CalculatorImpl.componentType
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<componentType xmlns="http://www.osoa.org/xmlns/sca/1.0">
+
+ <service name="CalculatorService">
+ <interface.java class="calculator.CalculatorService" />
+ </service>
+
+ <reference name="divideService">
+ <interface.java class="calculator.DivideService" />
+ </reference>
+
+</componentType>
+ \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/JavaScriptReference.composite b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/JavaScriptReference.composite
new file mode 100644
index 0000000000..a313dd1e6d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/JavaScriptReference.composite
@@ -0,0 +1,37 @@
+<?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/1.0"
+ name="JavaScriptReference">
+
+ <component name="ClientComponent">
+ <implementation.java class="org.apache.tuscany.sca.implementation.script.itests.helloworld.HelloWorldProxy"/>
+ </component>
+
+ <component name="ReferenceComponent">
+ <tuscany:implementation.script script="org/apache/tuscany/sca/implementation/script/itests/references/reference.js"/>
+ <reference name="ref" target="TargetComponent" />
+ </component>
+
+ <component name="TargetComponent">
+ <implementation.java class="org.apache.tuscany.sca.implementation.script.itests.references.HelloWorldTarget"/>
+ </component>
+
+</composite>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/NestedCalculator.composite b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/NestedCalculator.composite
new file mode 100644
index 0000000000..2719ee9162
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/NestedCalculator.composite
@@ -0,0 +1,29 @@
+<?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:calc="http://calc"
+ targetNamespace="http://calc"
+ name="Calculator">
+
+ <component name="CalculatorServiceComponent">
+ <implementation.composite xmlns:n="http://inner" name="n:InnerCalculator"/>
+ </component>
+
+</composite>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/RMIBindingTest.composite b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/RMIBindingTest.composite
new file mode 100644
index 0000000000..d29fe85586
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/RMIBindingTest.composite
@@ -0,0 +1,43 @@
+<?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/1.0"
+ name="HelloWorldRmiComposite">
+
+ <service name="HelloWorldRmiService" promote="HelloWorldServiceComponent">
+ <interface.java interface="helloworld.HelloWorldService"/>
+ <tuscany:binding.rmi host="localhost" port="8099" serviceName="HelloWorldRemoteService" />
+ </service>
+
+ <component name="HelloWorldServiceComponent">
+ <implementation.java class="helloworld.HelloWorldImpl"/>
+ </component>
+
+ <component name="HelloWorldRmiServiceComponent">
+ <implementation.java class="helloworld.HelloWorldRmiImpl"/>
+ <reference name="extService"></reference>
+ </component>
+
+ <reference name="HelloWorldRmiReference" promote="HelloWorldRmiServiceComponent/extService">
+ <interface.java interface="helloworld.HelloWorldService"/>
+ <tuscany:binding.rmi host="localhost" port="8099" serviceName="HelloWorldRemoteService" />
+ </reference>
+
+</composite>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllCalculator.composite b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllCalculator.composite
new file mode 100644
index 0000000000..5091ff700b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllCalculator.composite
@@ -0,0 +1,128 @@
+<?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 autowire="false" constrainingType="tns:CalculatorComponent" local="true" name="TestAllCalculator" policySets="sns:SecureReliablePolicy"
+ requires="cns:confidentiality" targetNamespace="http://calc" xmlns:tns="http://calc"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.osoa.org/xmlns/sca/1.0 http://www.osoa.org/xmlns/sca/1.0 "
+ xmlns:ext="http://extension"
+ xmlns:cns="http://test" xmlns:sns="http://test">
+
+ <include name="tns:TestAllDivide"/>
+ <ext:testExtension/>
+
+ <service name="CalculatorService" promote="CalculatorServiceComponent/CalculatorService" requires="cns:confidentiality"
+ policySets="sns:SecureReliablePolicy">
+ <ext:testExtension/>
+ <interface.java interface="calculator.CalculatorService" callbackInterface="calculator.CalculatorCallback" />
+ <operation name="add" policySets="sns:SecureReliablePolicy" requires="cns:confidentiality" />
+
+ <binding.ws name="CalculatorWS" policySets="sns:SecureReliablePolicy" port="" requires="cns:confidentiality" uri="http://calc/ws">
+ <operation name="add" policySets="sns:SecureReliablePolicy" requires="cns:confidentiality" />
+ </binding.ws>
+
+ <callback policySets="sns:SecureReliablePolicy" requires="cns:confidentiality">
+ <ext:testExtension/>
+ <binding.ws name="CalculatorCallbackWS" policySets="" port="" requires="" uri="http://calc/callback/ws">
+ <operation name="addCallback" policySets="sns:SecureReliablePolicy" requires="cns:confidentiality" />
+ </binding.ws>
+ </callback>
+ </service>
+
+ <component name="CalculatorServiceComponent" autowire="false" constrainingType="tns:CalculatorComponent"
+ policySets="sns:SecureReliablePolicy" requires="cns:confidentiality">
+ <ext:testExtension/>
+ <service name="CalculatorService" policySets="sns:SecureReliablePolicy" requires="cns:confidentiality">
+ <interface.java interface="calculator.CalculatorService" callbackInterface="calculator.CalculatorCallback" />
+ </service>
+
+ <reference name="addService" target="AddServiceComponent/AddService" autowire="false" multiplicity="1..1"
+ policySets="sns:SecureReliablePolicy" requires="cns:confidentiality" wiredByImpl="false">
+ <ext:testExtension/>
+ <interface.java interface="calculator.AddService" callbackInterface="calculator.AddCallback" />
+ </reference>
+ <reference name="subtractService" target="SubtractServiceComponent" />
+ <reference name="multiplyService" />
+ <reference name="divideService" target="DivideServiceComponent" />
+
+ <property name="round" type="xsd:boolean" many="false">true</property>
+
+ <implementation.java class="calculator.CalculatorServiceImpl" policySets="" requires="" />
+ </component>
+
+ <component name="AddServiceComponent">
+ <service name="AddService">
+ <interface.java interface="calculator.AddService" />
+ </service>
+ <implementation.java class="calculator.AddServiceImpl" />
+ </component>
+
+ <component name="NestedCompositeComponent">
+ <service name="CalculatorService">
+ <interface.java interface="calculator.CalculatorService" />
+ </service>
+ <implementation.composite name="tns:Calculator" />
+ </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>
+
+ <reference name="MultiplyService" promote="CalculatorServiceComponent/multiplyService" policySets="sns:SecureReliablePolicy"
+ requires="cns:confidentiality">
+ <interface.java interface="calculator.MultiplyService" callbackInterface="calculator.MultiplyCallback" />
+ <operation name="multiply" policySets="sns:SecureReliablePolicy" requires="cns:confidentiality" />
+
+ <binding.ws name="MultiplyWS" port="" policySets="sns:SecureReliablePolicy" requires="cns:confidentiality" uri="http://calc/ws">
+ <operation name="multiply" policySets="sns:SecureReliablePolicy" requires="cns:confidentiality" />
+ </binding.ws>
+
+ <callback policySets="sns:SecureReliablePolicy" requires="cns:confidentiality">
+ <binding.ws name="MultiplyCallbackWS" port="" uri="http://calc/callback/ws" policySets="sns:SecureReliablePolicy"
+ requires="cns:confidentiality">
+ <operation name="multiplyCallback" policySets="sns:SecureReliablePolicy" requires="cns:confidentiality" />
+ </binding.ws>
+ </callback>
+ </reference>
+
+ <property name="prop1" xmlns:foo="http://foo" many="true" type="foo:MyComplexType">
+ <ext:testExtension/>
+ <MyComplexPropertyValue1 xsi:type="foo:MyComplexType" attr="bar">
+ <foo:a>AValue</foo:a>
+ <bar:b xmlns:bar="http://bar">InterestingURI</bar:b>
+ </MyComplexPropertyValue1>
+ <MyComplexPropertyValue2 xsi:type="foo:MyComplexType" attr="zing">
+ <foo:a>BValue</foo:a>
+ <bar:b xmlns:bar="http://bar">BoringURI</bar:b>
+ </MyComplexPropertyValue2>
+ </property>
+
+ <property name="prop2" xmlns:foo="http://foo" mustSupply="true" element="MyComplexPropertyValue1"/>
+
+</composite>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite
new file mode 100644
index 0000000000..d59e69209d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllDivide.composite
@@ -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 autowire="false"
+ constrainingType="tns:Calculator"
+ local="true"
+ name="TestAllDivide"
+ policySets="" requires=""
+ targetNamespace="http://calc"
+ xmlns:tns="http://calc"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.osoa.org/xmlns/sca/1.0 http://www.osoa.org/xmlns/sca/1.0 ">
+
+ <include name="tns:CompleteDivide"/>
+
+ <service name="DivideService" policySets="" promote="CalculatorDivideComponent/DivideService" requires="">
+ <interface.java interface="calculator.DivideService" callbackInterface="calculator.DivideCallback"/>
+ <operation name="divide" policySets="" requires=""/>
+
+ <binding.ws name="CalculatorWS" policySets="" port="" requires="" uri="http://calc/ws">
+ <operation name="divide" policySets="" requires=""/>
+ </binding.ws>
+
+ <callback policySets="" requires="">
+ <binding.ws name="CalculatorCallbackWS" policySets="" port="" requires="" uri="http://calc/callback/ws">
+ <operation name="divideCallback" policySets="" requires=""/>
+ </binding.ws>
+ </callback>
+ </service>
+
+ <component name="CalculatorDivideComponent" autowire="false" constrainingType="tns:CalculatorServiceComponent" policySets="" requires="">
+ <service name="DivideService" policySets="" requires="">
+ <interface.java interface="calculator.DivideService" callbackInterface="calculator.DivideCallback"/>
+ </service>
+ <implementation.java class="calculator.DivideImpl" policySets="" requires=""/>
+ </component>
+
+</composite>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllPolicyCalculator.composite b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllPolicyCalculator.composite
new file mode 100644
index 0000000000..7bc7ccdb83
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/TestAllPolicyCalculator.composite
@@ -0,0 +1,129 @@
+<?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 autowire="false" constrainingType="tns:CalculatorComponent" local="true" name="TestAllCalculator"
+ requires="cns:tuscanyIntent_1" targetNamespace="http://calc" xmlns:tns="http://calc"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://www.osoa.org/xmlns/sca/1.0 http://www.osoa.org/xmlns/sca/1.0 "
+ xmlns:ext="http://extension"
+ xmlns:cns="http://test" xmlns:sns="http://test">
+
+ <include name="tns:TestAllDivide"/>
+ <ext:testExtension/>
+
+ <service name="CalculatorService" promote="CalculatorServiceComponent/CalculatorService" requires="cns:tuscanyIntent_2 cns:tuscanyIntent_1">
+ <ext:testExtension/>
+ <interface.java interface="calculator.CalculatorService" callbackInterface="calculator.CalculatorCallback" />
+ <operation name="add" requires="cns:tuscanyIntent_6"/>
+
+ <binding.ws name="CalculatorWS" port="" requires="cns:tuscanyIntent_3" uri="http://calc/ws">
+ </binding.ws>
+
+ <callback requires="cns:tuscanyIntent_4">
+ <ext:testExtension/>
+ <binding.ws name="CalculatorCallbackWS" policySets="" port="" requires="cns:tuscanyIntent_5" uri="http://calc/callback/ws">
+ </binding.ws>
+ </callback>
+ </service>
+
+ <component name="CalculatorServiceComponent" autowire="false" constrainingType="tns:CalculatorComponent"
+ requires="cns:tuscanyIntent_2 cns:tuscanyIntent_3">
+ <ext:testExtension/>
+ <service name="CalculatorService" requires="cns:tuscanyIntent_3">
+ <interface.java interface="calculator.CalculatorService" callbackInterface="calculator.CalculatorCallback" />
+ <operation name="add" requires="cns:tuscanyIntent_6 cns:tuscanyIntent_7"/>
+ <binding.ws name="CalculatorCallbackWS" policySets="" port="" requires="cns:tuscanyIntent_4" uri="http://calc/callback/ws">
+ </binding.ws>
+ <callback>
+ </callback>
+ </service>
+
+ <reference name="addService" target="AddServiceComponent/AddService" autowire="false" multiplicity="1..1"
+ requires="cns:tuscanyIntent_3 cns:tuscanyIntent_2.qualified" wiredByImpl="false">
+ <ext:testExtension/>
+ <interface.java interface="calculator.AddService" callbackInterface="calculator.AddCallback" />
+ <operation name="add" requires="cns:tuscanyIntent_8 cns:tuscanyIntent_9"/>
+ <binding.ws name="addServiceWSRef" policySets="" port="" requires="cns:tuscanyIntent_4" uri="http://calc/callback/ws">
+ </binding.ws>
+ </reference>
+ <reference name="subtractService" target="SubtractServiceComponent" />
+ <reference name="multiplyService" />
+ <reference name="divideService" target="DivideServiceComponent" />
+
+ <property name="round" type="xsd:boolean" many="false">true</property>
+
+ <implementation.java class="calculator.CalculatorServiceImpl" policySets="" requires="cns:tuscanyIntent_4" />
+ </component>
+
+ <component name="AddServiceComponent">
+ <service name="AddService">
+ <interface.java interface="calculator.AddService" />
+ </service>
+ <implementation.java class="calculator.AddServiceImpl" />
+ </component>
+
+ <component name="NestedCompositeComponent">
+ <service name="CalculatorService">
+ <interface.java interface="calculator.CalculatorService" />
+ </service>
+ <implementation.composite name="tns:Calculator" />
+ </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>
+
+ <reference name="MultiplyService" promote="CalculatorServiceComponent/multiplyService"
+ requires="cns:tuscanyIntent_2">
+ <interface.java interface="calculator.MultiplyService" callbackInterface="calculator.MultiplyCallback" />
+ <operation name="multiply" requires="cns:tuscanyIntent_6"/>
+
+ <binding.ws name="MultiplyWS" port="" requires="cns:tuscanyIntent_3" uri="http://calc/ws">
+ </binding.ws>
+
+ <callback policySets="sns:SecureReliablePolicy" requires="cns:tuscanyIntent_3">
+ <binding.ws name="MultiplyCallbackWS" port="" uri="http://calc/callback/ws"
+ requires="cns:tuscanyIntent_4">
+ </binding.ws>
+ </callback>
+ </reference>
+
+ <property name="prop1" xmlns:foo="http://foo">
+ <ext:testExtension/>
+ <MyComplexPropertyValue1 xsi:type="foo:MyComplexType" attr="bar">
+ <foo:a>AValue</foo:a>
+ <bar:b xmlns:bar="http://bar">InterestingURI</bar:b>
+ </MyComplexPropertyValue1>
+ <MyComplexPropertyValue2 xsi:type="foo:MyComplexType" attr="zing">
+ <foo:a>BValue</foo:a>
+ <bar:b xmlns:bar="http://bar">BoringURI</bar:b>
+ </MyComplexPropertyValue2>
+ </property>
+
+</composite>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/another_test_definitions.xml b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/another_test_definitions.xml
new file mode 100644
index 0000000000..bcc8c54dc8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/another_test_definitions.xml
@@ -0,0 +1,97 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<sca:definitions xmlns="http://test"
+ targetNamespace="http://test"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0">
+
+<!-- simple intent -->
+ <sca:intent name="tuscanyIntent_1"
+ constrains="sca:binding">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+ <sca:intent name="tuscanyIntent_2"
+ constrains="sca:binding">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+ <sca:intent name="tuscanyIntent_3"
+ constrains="sca:binding">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+ <sca:intent name="tuscanyIntent_4"
+ constrains="sca:binding">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+<sca:intent name="tuscanyIntent_5"
+ constrains="sca:binding">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+ <sca:intent name="tuscanyIntent_6"
+ constrains="sca:binding">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+ <sca:intent name="tuscanyIntent_7"
+ constrains="sca:binding">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+ <sca:intent name="tuscanyIntent_8"
+ constrains="sca:binding">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+ <sca:intent name="tuscanyIntent_9"
+ constrains="sca:binding">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+ <sca:intent name="tuscanyIntent_10"
+ constrains="sca:binding">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+ <!-- qualified intents -->
+ <sca:intent name="tuscanyIntent_1.qualified" />
+ <sca:intent name="tuscanyIntent_2.qualified" />
+</sca:definitions> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/test_definitions.xml b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/test_definitions.xml
new file mode 100644
index 0000000000..b79cb6b7b7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xml/src/test/resources/org/apache/tuscany/sca/assembly/xml/test_definitions.xml
@@ -0,0 +1,175 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<sca:definitions xmlns="http://test"
+ targetNamespace="http://test"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0">
+
+ <!-- qualified intents -->
+ <sca:intent name="confidentiality.transport" />
+ <sca:intent name="confidentiality.message" />
+ <sca:intent name="confidentiality.message.whole" />
+ <sca:intent name="confidentiality.message.body" />
+
+ <!-- POLICY SETS -->
+ <sca:policySet name="SecureReliablePolicy"
+ provides="confidentiality.transport integrity"
+ appliesTo="//sca:binding.ws | //sca:binding.sca"
+ xmlns="http://test"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for
+ "basic authentication" -->
+ </wsp:PolicyAttachment>
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for
+ "reliability" -->
+ </wsp:PolicyAttachment>
+ </sca:policySet>
+
+ <sca:policySet name="SecureMessagingPolicies"
+ provides="confidentiality"
+ appliesTo="//sca:binding.ws"
+ xmlns="http://test"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <sca:intentMap provides="confidentiality" default="transport">
+ <sca:qualifier name="transport">
+ <wsp:Policy>
+ <!-- policy expression and policy subject for "transport" alternative -->
+ </wsp:Policy>
+ <wsp:Policy>...</wsp:Policy>
+ </sca:qualifier>
+ <sca:qualifier name="message">
+ <wsp:Policy>
+ <!-- policy expression and policy subject for "message" alternative" -->
+ </wsp:Policy>
+ </sca:qualifier>
+ </sca:intentMap>
+</sca:policySet>
+
+<sca:policySet name="SecurityPolicy" provides="confidentiality"
+ xmlns="http://test"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" >
+ <sca:intentMap provides="confidentiality" default="message">
+ <sca:qualifier name="message">
+ <sca:intentMap provides="message" default="whole">
+ <sca:qualifier name="body">
+ <wsp:Policy>
+ <!-- policy attachment for body encryption -->
+ </wsp:Policy>
+ </sca:qualifier>
+ <sca:qualifier name="whole">
+ <wsp:Policy>
+ <!-- policy attachment for whole message encryption -->
+ </wsp:Policy>
+ </sca:qualifier>
+ </sca:intentMap>
+ </sca:qualifier>
+ <sca:qualifier name="transport">
+ <wsp:Policy>
+ <!-- policy attachment for transport encryption -->
+ </wsp:Policy>
+ </sca:qualifier>
+ </sca:intentMap>
+</sca:policySet>
+
+<sca:policySet name="BasicAuthMsgProtSecurity"
+ provides="authentication confidentiality"
+ appliesTo="//sca:binding.ws"
+ xmlns="http://test">
+ <sca:policySetReference name="AuthenticationPolicies"/>
+ <sca:policySetReference name="ConfidentialityPolicies"/>
+</sca:policySet>
+
+<sca:policySet name="AuthenticationPolicies"
+ provides="authentication"
+ appliesTo="//sca:binding.ws"
+ xmlns="http://test"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for "basic
+ authentication" -->
+ </wsp:PolicyAttachment>
+</sca:policySet>
+
+<sca:policySet name="ConfidentialityPolicies"
+ provides="confidentiality"
+ bindings="binding.ws"
+ xmlns="http://test"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <sca:intentMap provides="confidentiality" default="transport">
+ <sca:qualifier name="transport">
+ <wsp:Policy>
+ <!-- policy expression and policy subject for "transport"
+ alternative -->
+ </wsp:Policy>
+ <wsp:Policy>...</wsp:Policy>
+ </sca:qualifier>
+ <sca:qualifier name="message">
+ <wsp:Policy>
+ <!-- policy expression and policy subject for "message"
+ alternative" -->...
+ </wsp:Policy>
+ </sca:qualifier>
+ </sca:intentMap>
+</sca:policySet>
+
+<!-- profile intent -->
+ <sca:intent name="reliableMessageProtection"
+ constrains="sca:binding"
+ requires="messageProtection">
+ <sca:description>
+ Protect messages from unauthorized reading or modification
+ </sca:description>
+ </sca:intent>
+
+ <sca:intent name="messageProtection"
+ constrains="sca:binding"
+ requires="confidentiality integrity">
+ <sca:description>
+ Protect messages from unauthorized reading or modification
+ </sca:description>
+ </sca:intent>
+
+<!-- simple intent -->
+ <sca:intent name="confidentiality"
+ constrains="sca:binding">
+ <sca:description>
+ Communitcation thro this binding must prevent
+ unauthorized users from reading the messages.
+ </sca:description>
+ </sca:intent>
+
+ <sca:intent name="integrity"
+ constrains="sca:binding">
+ <sca:description>
+ Communitcation thro this binding must prevent
+ unauthorized modification of the messages.
+ </sca:description>
+ </sca:intent>
+
+ <sca:intent name="authentication"
+ constrains="sca:binding">
+ <sca:description>
+ Communitcation thro this binding required
+ Authentication.
+ </sca:description>
+ </sca:intent>
+
+</sca:definitions> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/LICENSE b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/LICENSE
new file mode 100644
index 0000000000..bfded7c6a9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/LICENSE
@@ -0,0 +1,244 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
+===============================================================================
+
+Apache Tuscany SCA for Java Subcomponents
+=========================================:
+
+The Tuscany SCA for Java release includes a number of subcomponents with
+separate copyright notices and license terms. Your use of the source
+code for the these subcomponents is subject to the terms and
+conditions of the following licenses.
+
+===============================================================================
+
+This module includes XSD files under the following SCA Collaboration license:
+
+License for the Service Component Architecture JavaDoc, Interface Definition files and XSD files.
+
+Permission to copy, make derivative works of, and distribute the Service Component Architecture
+JavaDoc, Interface Definition Files and XSD files in any medium without fee or royalty as part
+of a compliant implementation of the Service Component Architecture Specification is hereby granted.
+The Service Components Architecture Specification may be found at the following location:
+
+ http://www.osoa.org/download/attachments/35/SCA_AssemblyModel_V100.pdf
+
+THE SERVICE COMPONENT ARCHITECTURE SPECIFICATION AND THE JAVADOC, INTERFACE DEFINITION FILES AND XSD FILES
+ARE PROVIDED "AS IS," AND THE AUTHORS MAKE NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED, REGARDING THIS
+SPECIFICATION OR THE JAVADOC, INTERFACE DEFINITION FILES AND XSD FILES AND THE IMPLEMENTATION OF THEIR CONTENTS,
+INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE,
+NON-INFRINGEMENT OR TITLE. THE AUTHORS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL,
+INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR RELATING TO ANY USE OR DISTRIBUTION OF THE
+SERVICE COMPONENT ARCHITECTURE SPECIFICATION OR THE JAVADOC, INTERFACE DEFINTION FILES OR XSD FILES.
+
+The name and trademarks of the Authors may NOT be used in any manner, including advertising or
+publicity pertaining to the Service Component Architecture Specification or its contents without specific,
+written prior permission. Title to copyright in the Service Component Architecture Specification and the
+JavaDoc, Interface Definition Files and XSD Files will at all times remain with the Authors.
+
+No other rights are granted by implication, estoppel or otherwise.
+
+===============================================================================
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/META-INF/README b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/NOTICE b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/NOTICE
new file mode 100644
index 0000000000..6dcfe88195
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/NOTICE
@@ -0,0 +1,12 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
+This product also includes software under the SCA Collaboration license
+(see the LICENSE file contained in this distribution), with the following
+copyright:
+
+(c) Copyright SCA Collaboration 2006, 2007
+
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/pom.xml b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/pom.xml
new file mode 100644
index 0000000000..90bb93222d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/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>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-assembly-xsd</artifactId>
+ <name>Apache Tuscany SCA Assembly Model XML Schemas</name>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.assembly.xsd</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema
new file mode 100644
index 0000000000..69b2701e30
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchema
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+tuscany-sca.xsd \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-all.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-all.xsd
new file mode 100644
index 0000000000..82899ed8ed
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-all.xsd
@@ -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.
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0">
+
+ <include schemaLocation="sca.xsd"/>
+
+ <include schemaLocation="sca-binding-ejb.xsd"/>
+
+ <include schemaLocation="sca-implementation-bpel.xsd"/>
+ <include schemaLocation="sca-implementation-spring.xsd"/>
+ <include schemaLocation="sca-implementation-ejb.xsd"/>
+ <include schemaLocation="sca-implementation-web.xsd"/>
+
+</schema> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-binding-ejb.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-binding-ejb.xsd
new file mode 100644
index 0000000000..26bedfcce5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-binding-ejb.xsd
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- (c) Copyright SCA Collaboration 2006, 2007 -->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ targetNamespace="http://www.osoa.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+ <include schemaLocation="sca-core.xsd"/>
+
+ <element name="binding.ejb" type="sca:EJBSessionBeanBinding"
+ substitutionGroup="sca:binding" />
+
+ <simpleType name="BeanType">
+ <restriction base="string">
+ <enumeration value="stateless"/>
+ <enumeration value="stateful"/>
+ </restriction>
+ </simpleType>
+
+ <simpleType name="VersionValue">
+ <restriction base="string">
+ <enumeration value="EJB2"/>
+ <enumeration value="EJB3"/>
+ </restriction>
+ </simpleType>
+
+
+ <complexType name="EJBSessionBeanBinding">
+ <complexContent>
+ <extension base="sca:Binding">
+ <sequence>
+ <any namespace="##other" processContents="lax"
+ minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="homeInterface" type="NCName" use="optional"/>
+ <attribute name="ejb-link-name" type="NCName" use="optional"/>
+ <attribute name="session-type" type="sca:BeanType" use="optional" default="stateless"/>
+ <attribute name="ejb-version" type="sca:VersionValue" use="optional" default="EJB2"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </extension>
+ </complexContent>
+ </complexType>
+
+</schema>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-binding-jms.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-binding-jms.xsd
new file mode 100644
index 0000000000..6f64453635
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-binding-jms.xsd
@@ -0,0 +1,139 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- (c) Copyright SCA Collaboration 2006, 2007 -->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <include schemaLocation="sca-core.xsd"/>
+
+ <complexType name="JMSBinding">
+ <complexContent>
+ <extension base="sca:Binding">
+ <sequence>
+ <element name="destination" type="sca:Destination" minOccurs="0"/>
+ <element name="connectionFactory" type="sca:ConnectionFactory"
+ minOccurs="0"/>
+ <element name="activationSpec" type="sca:ActivationSpec"
+ minOccurs="0"/>
+ <element name="response" type="sca:Response" minOccurs="0"/>
+ <element name="headers" type="sca:Headers" minOccurs="0"/>
+ <element name="resourceAdapter" type="sca:ResourceAdapter"
+ minOccurs="0"/>
+ <element name="operationProperties" type="sca:OperationProperties"
+ minOccurs="0" maxOccurs="unbounded"/>
+ <any namespace="##other" processContents="lax"
+ minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="correlationScheme"
+ default="RequestMsgIDToCorrelID">
+ <simpleType>
+ <restriction base="string">
+ <enumeration value="RequestMsgIDToCorrelID"/>
+ <enumeration value="RequestCorrelIDToCorrelID"/>
+ <enumeration value="None"/>
+ </restriction>
+ </simpleType>
+ </attribute>
+
+ <attribute name="initialContextFactory" type="anyURI"/>
+ <attribute name="jndiURL" type="anyURI"/>
+ <attribute name="requestConnection" type="QName"/>
+ <attribute name="responseConnection" type="QName"/>
+ <attribute name="operationProperties" type="QName"/>
+ <anyAttribute/>
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <simpleType name="CreateResource">
+ <restriction base="string">
+ <enumeration value="always"/>
+ <enumeration value="never"/>
+ <enumeration value="ifnotexist"/>
+ </restriction>
+ </simpleType>
+
+ <complexType name="Destination">
+ <sequence>
+ <element name="property" type="string"
+ minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="name" type="anyURI" use="required"/>
+ <attribute name="type" use="optional" default="queue">
+ <simpleType>
+ <restriction base="string">
+ <enumeration value="queue"/>
+ <enumeration value="topic"/>
+ </restriction>
+ </simpleType>
+ </attribute>
+ <attribute name="create" type="sca:CreateResource"
+ use="optional" default="ifnotexist"/>
+ </complexType>
+
+ <complexType name="ConnectionFactory">
+ <sequence> <element name="property" type="string"
+ minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="name" type="anyURI" use="required"/>
+ <attribute name="create" type="sca:CreateResource"
+ use="optional" default="ifnotexist"/>
+ </complexType>
+
+ <complexType name="ActivationSpec">
+ <sequence>
+ <element name="property" type="string"
+ minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="name" type="anyURI" use="required"/>
+ <attribute name="create" type="sca:CreateResource"
+ use="optional" default="ifnotexist"/>
+ </complexType>
+
+ <complexType name="Response">
+ <sequence>
+ <element name="destination" type="sca:Destination" minOccurs="0"/>
+ <element name="connectionFactory" type="sca:ConnectionFactory"
+ minOccurs="0"/>
+ <element name="activationSpec" type="sca:ActivationSpec" minOccurs="0"/>
+ </sequence>
+ </complexType>
+
+ <complexType name="Headers">
+ <sequence>
+ <element name="property" type="string"
+ minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="JMSType" type="string"/>
+ <attribute name="JMSCorrelationID" type="string"/>
+ <attribute name="JMSDeliveryMode" type="string"/>
+ <attribute name="JMSTimeToLive" type="int"/>
+ <attribute name="JMSPriority" type="string"/>
+ </complexType>
+
+ <complexType name="SubscriptionHeaders">
+ <attribute name="JMSSelector" type="string"/>
+ </complexType>
+
+ <complexType name="ResourceAdapter">
+ <sequence>
+ <element name="property" type="string"
+ minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="name" type="string" use="required"/>
+ </complexType>
+
+ <complexType name="OperationProperties">
+ <sequence>
+ <element name="property" type="string"
+ minOccurs="0" maxOccurs="unbounded"/>
+ <element name="headers" type="sca:Headers"/>
+ </sequence>
+ <attribute name="name" type="string" use="required"/>
+ <attribute name="nativeOperation" type="string"/>
+ </complexType>
+
+ <element name="binding.jms" type="sca:JMSBinding"
+ substitutionGroup="sca:binding"/>
+</schema>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-binding-sca.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-binding-sca.xsd
new file mode 100644
index 0000000000..02703402ef
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-binding-sca.xsd
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- (c) Copyright SCA Collaboration 2006, 2007 -->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <include schemaLocation="sca-core.xsd"/>
+
+ <element name="binding.sca" type="sca:SCABinding"
+ substitutionGroup="sca:binding"/>
+ <complexType name="SCABinding">
+ <complexContent>
+ <extension base="sca:Binding">
+ <sequence>
+ <any namespace="##other" processContents="lax" minOccurs="0"
+ maxOccurs="unbounded"/>
+ </sequence>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </extension>
+ </complexContent>
+ </complexType>
+</schema> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-binding-webservice.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-binding-webservice.xsd
new file mode 100644
index 0000000000..3e92de193b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-binding-webservice.xsd
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- (c) Copyright SCA Collaboration 2006, 2007 -->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:wsdli="http://www.w3.org/2004/08/wsdl-instance"
+ xmlns:wsa="http://www.w3.org/2004/12/addressing"
+ elementFormDefault="qualified">
+
+ <include schemaLocation="sca-core.xsd"/>
+
+ <element name="binding.ws" type="sca:WebServiceBinding"
+ substitutionGroup="sca:binding"/>
+ <complexType name="WebServiceBinding">
+ <complexContent>
+ <extension base="sca:Binding">
+ <sequence>
+ <any namespace="##other" processContents="lax" minOccurs="0"
+ maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="wsdlElement" type="anyURI" use="optional"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </extension>
+ </complexContent>
+ </complexType>
+</schema>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-contributions.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-contributions.xsd
new file mode 100644
index 0000000000..a22d8ac075
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-contributions.xsd
@@ -0,0 +1,45 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- (c) Copyright SCA Collaboration 2007 -->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <include schemaLocation="sca-core.xsd"/>
+
+ <element name="contribution" type="sca:ContributionType"/>
+ <complexType name="ContributionType">
+ <sequence>
+ <element name="deployable" type="sca:DeployableType" minOccurs="1" maxOccurs="unbounded"/>
+ <element name="import" type="sca:ImportType" minOccurs="0" maxOccurs="unbounded"/>
+ <element name="export" type="sca:ExportType" minOccurs="0" maxOccurs="unbounded"/>
+ <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <anyAttribute namespace="##other" processContents="lax"/>
+ </complexType>
+
+ <complexType name="DeployableType">
+ <sequence>
+ <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="composite" type="QName" use="required"/>
+ <anyAttribute namespace="##other" processContents="lax"/>
+ </complexType>
+
+ <complexType name="ImportType">
+ <sequence>
+ <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="namespace" type="string" use="required"/>
+ <attribute name="location" type="anyURI" use="required"/>
+ <anyAttribute namespace="##other" processContents="lax"/>
+ </complexType>
+
+ <complexType name="ExportType">
+ <sequence>
+ <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="namespace" type="string" use="required"/>
+ <anyAttribute namespace="##other" processContents="lax"/>
+ </complexType>
+</schema> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-core.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-core.xsd
new file mode 100644
index 0000000000..a7ca0433f9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-core.xsd
@@ -0,0 +1,348 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- (c) Copyright SCA Collaboration 2006, 2007 -->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <element name="componentType" type="sca:ComponentType"/>
+ <complexType name="ComponentType">
+ <sequence>
+ <choice minOccurs="0" maxOccurs="1">
+ <element ref="sca:implementation"/>
+ <any namespace="##other" processContents="lax"/>
+ </choice>
+ <choice minOccurs="0" maxOccurs="unbounded">
+ <element name="service" type="sca:ComponentService" />
+ <element name="reference" type="sca:ComponentReference"/>
+ <element name="property" type="sca:Property"/>
+ </choice>
+ <!--
+ <any namespace="##other" processContents="lax" minOccurs="0"
+ maxOccurs="unbounded"/>
+ -->
+ </sequence>
+ <attribute name="constrainingType" type="QName" use="optional"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </complexType>
+
+ <element name="composite" type="sca:Composite"/>
+ <complexType name="Composite">
+ <sequence>
+ <choice minOccurs="0" maxOccurs="unbounded">
+ <element name="include" type="sca:Include"/>
+ <element name="service" type="sca:Service"/>
+ <element name="property" type="sca:Property"/>
+ <element name="component" type="sca:Component"/>
+ <element name="reference" type="sca:Reference"/>
+ <element name="wire" type="sca:Wire"/>
+ <!-- <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/> -->
+ </choice>
+ <any namespace="##other" processContents="lax" minOccurs="0"
+ maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="name" type="NCName" use="required"/>
+ <attribute name="targetNamespace" type="anyURI" use="optional"/>
+ <attribute name="local" type="boolean" use="optional" default="false"/>
+ <attribute name="autowire" type="boolean" use="optional" default="false"/>
+ <attribute name="constrainingType" type="QName" use="optional"/>
+ <attribute name="requires" type="sca:listOfQNames" use="optional"/>
+ <attribute name="policySets" type="sca:listOfQNames" use="optional"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </complexType>
+
+ <complexType name="Service">
+ <sequence>
+ <element ref="sca:interface" minOccurs="0" maxOccurs="1" />
+ <element name="operation" type="sca:Operation" minOccurs="0"
+ maxOccurs="unbounded" />
+ <choice minOccurs="0" maxOccurs="unbounded">
+ <element ref="sca:binding" />
+ <any namespace="##other" processContents="lax"/>
+ </choice>
+ <element ref="sca:callback" minOccurs="0" maxOccurs="1" />
+ <!--
+ <any namespace="##other" processContents="lax" minOccurs="0"
+ maxOccurs="unbounded" />
+ -->
+ </sequence>
+ <attribute name="name" type="NCName" use="required" />
+ <attribute name="promote" type="anyURI" use="required" />
+ <attribute name="requires" type="sca:listOfQNames" use="optional" />
+ <attribute name="policySets" type="sca:listOfQNames" use="optional"/>
+ <anyAttribute namespace="##any" processContents="lax" />
+ </complexType>
+
+ <element name="interface" type="sca:Interface" abstract="true" />
+ <complexType name="Interface" abstract="true"/>
+
+ <complexType name="Reference">
+ <sequence>
+ <element ref="sca:interface" minOccurs="0" maxOccurs="1" />
+ <element name="operation" type="sca:Operation" minOccurs="0"
+ maxOccurs="unbounded" />
+ <choice minOccurs="0" maxOccurs="unbounded">
+ <element ref="sca:binding" />
+ <any namespace="##other" processContents="lax" />
+ </choice>
+ <element ref="sca:callback" minOccurs="0" maxOccurs="1" />
+ <!--
+ <any namespace="##other" processContents="lax" minOccurs="0"
+ maxOccurs="unbounded" />
+ -->
+ </sequence>
+ <attribute name="name" type="NCName" use="required" />
+ <attribute name="target" type="sca:listOfAnyURIs" use="optional"/>
+ <attribute name="wiredByImpl" type="boolean" use="optional" default="false"/>
+ <attribute name="multiplicity" type="sca:Multiplicity"
+ use="optional" default="1..1" />
+ <attribute name="promote" type="sca:listOfAnyURIs" use="required" />
+ <attribute name="requires" type="sca:listOfQNames" use="optional" />
+ <attribute name="policySets" type="sca:listOfQNames" use="optional"/>
+ <anyAttribute namespace="##any" processContents="lax" />
+ </complexType>
+
+ <complexType name="SCAPropertyBase" mixed="true">
+ <!-- mixed="true" to handle simple type -->
+ <sequence>
+ <any namespace="##any" processContents="lax" minOccurs="0"
+ maxOccurs="1" />
+ <!-- NOT an extension point; This xsd:any exists to accept
+ the element-based or complex type property
+ i.e. no element-based extension point under "sca:property" -->
+ </sequence>
+ </complexType>
+
+ <!-- complex type for sca:property declaration -->
+ <complexType name="Property" mixed="true">
+ <complexContent>
+ <extension base="sca:SCAPropertyBase">
+ <!-- extension defines the place to hold default value -->
+ <attribute name="name" type="NCName" use="required"/>
+ <attribute name="type" type="QName" use="optional"/>
+ <attribute name="element" type="QName" use="optional"/>
+ <attribute name="many" type="boolean" default="false"
+ use="optional"/>
+ <attribute name="noDefault" type="boolean" default="false"
+ use="optional"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ <!-- an extension point ; attribute-based only -->
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <complexType name="PropertyValue" mixed="true">
+ <complexContent>
+ <extension base="sca:SCAPropertyBase">
+ <attribute name="name" type="NCName" use="required"/>
+ <attribute name="type" type="QName" use="optional"/>
+ <attribute name="element" type="QName" use="optional"/>
+ <attribute name="many" type="boolean" default="false"
+ use="optional"/>
+ <attribute name="source" type="string" use="optional"/>
+ <attribute name="file" type="anyURI" use="optional"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ <!-- an extension point ; attribute-based only -->
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <element name="binding" type="sca:Binding" abstract="true"/>
+ <complexType name="Binding" abstract="true">
+ <sequence>
+ <element name="operation" type="sca:Operation" minOccurs="0"
+ maxOccurs="unbounded" />
+ </sequence>
+ <attribute name="uri" type="anyURI" use="optional"/>
+ <attribute name="name" type="QName" use="optional"/>
+ <attribute name="requires" type="sca:listOfQNames" use="optional"/>
+ <attribute name="policySets" type="sca:listOfQNames" use="optional"/>
+ </complexType>
+
+ <element name="bindingType" type="sca:BindingType"/>
+ <complexType name="BindingType">
+ <sequence minOccurs="0" maxOccurs="unbounded">
+ <any namespace="##other" processContents="lax" />
+ </sequence>
+ <attribute name="type" type="QName" use="required"/>
+ <attribute name="alwaysProvides" type="sca:listOfQNames" use="optional"/>
+ <attribute name="mayProvide" type="sca:listOfQNames" use="optional"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </complexType>
+
+ <element name="callback" type="sca:Callback"/>
+ <complexType name="Callback">
+ <choice minOccurs="0" maxOccurs="unbounded">
+ <element ref="sca:binding"/>
+ <any namespace="##other" processContents="lax"/>
+ </choice>
+ <attribute name="requires" type="sca:listOfQNames" use="optional"/>
+ <attribute name="policySets" type="sca:listOfQNames" use="optional"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </complexType>
+
+ <complexType name="Component">
+ <sequence>
+ <choice minOccurs="0" maxOccurs="1">
+ <element ref="sca:implementation"/>
+ <any namespace="##other" processContents="lax"/>
+ </choice>
+ <choice minOccurs="0" maxOccurs="unbounded">
+ <element name="service" type="sca:ComponentService"/>
+ <element name="reference" type="sca:ComponentReference"/>
+ <element name="property" type="sca:PropertyValue" />
+ </choice>
+ <!--
+ <any namespace="##other" processContents="lax" minOccurs="0"
+ maxOccurs="unbounded"/>
+ -->
+ </sequence>
+ <attribute name="name" type="NCName" use="required"/>
+ <attribute name="autowire" type="boolean" use="optional" default="false"/>
+ <attribute name="constrainingType" type="QName" use="optional"/>
+ <attribute name="requires" type="sca:listOfQNames" use="optional"/>
+ <attribute name="policySets" type="sca:listOfQNames" use="optional"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </complexType>
+
+ <complexType name="ComponentService">
+ <sequence>
+ <element ref="sca:interface" minOccurs="0" maxOccurs="1"/>
+ <element name="operation" type="sca:Operation" minOccurs="0"
+ maxOccurs="unbounded" />
+ <choice minOccurs="0" maxOccurs="unbounded">
+ <element ref="sca:binding" />
+ <any namespace="##other" processContents="lax"/>
+ </choice>
+ <element ref="sca:callback" minOccurs="0" maxOccurs="1"/>
+ <!--
+ <any namespace="##other" processContents="lax" minOccurs="0"
+ maxOccurs="unbounded"/>
+ -->
+ </sequence>
+ <attribute name="name" type="NCName" use="required"/>
+ <attribute name="requires" type="sca:listOfQNames"
+ use="optional"/>
+ <attribute name="policySets" type="sca:listOfQNames"
+ use="optional"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </complexType>
+
+ <complexType name="ComponentReference">
+ <sequence>
+ <element ref="sca:interface" minOccurs="0" maxOccurs="1" />
+ <element name="operation" type="sca:Operation" minOccurs="0"
+ maxOccurs="unbounded" />
+ <choice minOccurs="0" maxOccurs="unbounded">
+ <element ref="sca:binding" />
+ <any namespace="##other" processContents="lax" />
+ </choice>
+ <element ref="sca:callback" minOccurs="0" maxOccurs="1" />
+ <!--
+ <any namespace="##other" processContents="lax" minOccurs="0"
+ maxOccurs="unbounded" />
+ -->
+ </sequence>
+ <attribute name="name" type="NCName" use="required" />
+ <attribute name="target" type="sca:listOfAnyURIs" use="optional"/>
+ <attribute name="multiplicity" type="sca:Multiplicity"
+ use="optional" default="1..1" />
+ <attribute name="requires" type="sca:listOfQNames" use="optional"/>
+ <attribute name="policySets" type="sca:listOfQNames"
+ use="optional"/>
+ <anyAttribute namespace="##any" processContents="lax" />
+ </complexType>
+
+ <element name="implementation" type="sca:Implementation"
+ abstract="true" />
+ <complexType name="Implementation" abstract="true">
+ <attribute name="requires" type="sca:listOfQNames" use="optional"/>
+ <attribute name="policySets" type="sca:listOfQNames" use="optional"/>
+ </complexType>
+
+ <element name="implementationType" type="sca:ImplementationType"/>
+ <complexType name="ImplementationType">
+ <sequence minOccurs="0" maxOccurs="unbounded">
+ <any namespace="##other" processContents="lax" />
+ </sequence>
+ <attribute name="type" type="QName" use="required"/>
+ <attribute name="alwaysProvides" type="sca:listOfQNames" use="optional"/>
+ <attribute name="mayProvide" type="sca:listOfQNames" use="optional"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </complexType>
+
+ <complexType name="Wire">
+ <sequence>
+ <any namespace="##other" processContents="lax" minOccurs="0"
+ maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="source" type="anyURI" use="required"/>
+ <attribute name="target" type="anyURI" use="required"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </complexType>
+
+ <element name="include" type="sca:Include"/>
+ <complexType name="Include">
+ <attribute name="name" type="QName"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </complexType>
+
+ <complexType name="Operation">
+ <attribute name="name" type="NCName" use="required"/>
+ <attribute name="requires" type="sca:listOfQNames" use="optional"/>
+ <attribute name="policySets" type="sca:listOfQNames" use="optional"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </complexType>
+
+ <element name="constrainingType" type="sca:ConstrainingType"/>
+ <complexType name="ConstrainingType">
+ <sequence>
+ <choice minOccurs="0" maxOccurs="unbounded">
+ <element name="service" type="sca:ComponentService"/>
+ <element name="reference" type="sca:ComponentReference"/>
+ <element name="property" type="sca:Property" />
+ </choice>
+ <any namespace="##other" processContents="lax" minOccurs="0"
+ maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="name" type="NCName" use="required"/>
+ <attribute name="targetNamespace" type="anyURI"/>
+ <attribute name="requires" type="sca:listOfQNames" use="optional"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </complexType>
+
+
+ <simpleType name="Multiplicity">
+ <restriction base="string">
+ <enumeration value="0..1"/>
+ <enumeration value="1..1"/>
+ <enumeration value="0..n"/>
+ <enumeration value="1..n"/>
+ </restriction>
+ </simpleType>
+
+ <simpleType name="OverrideOptions">
+ <restriction base="string">
+ <enumeration value="no"/>
+ <enumeration value="may"/>
+ <enumeration value="must"/>
+ </restriction>
+ </simpleType>
+
+ <!-- Global attribute definition for @requires to permit use of intents
+ within WSDL documents -->
+ <attribute name="requires" type="sca:listOfQNames"/>
+
+ <!-- Global attribute defintion for @endsConversation to mark operations
+ as ending a conversation -->
+ <attribute name="endsConversation" type="boolean" default="false"/>
+
+ <simpleType name="listOfQNames">
+ <list itemType="QName"/>
+ </simpleType>
+
+ <simpleType name="listOfAnyURIs">
+ <list itemType="anyURI"/>
+ </simpleType>
+
+</schema> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-definitions.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-definitions.xsd
new file mode 100644
index 0000000000..0249882a92
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-definitions.xsd
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- (c) Copyright SCA Collaboration 2007 -->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <include schemaLocation="sca-core.xsd"/>
+ <include schemaLocation="sca-policy.xsd"/>
+
+ <element name="definitions">
+ <complexType>
+ <choice minOccurs="0" maxOccurs="unbounded">
+ <element ref="sca:intent"/>
+ <element ref="sca:policySet"/>
+ <element ref="sca:binding"/>
+ <element ref="sca:bindingType"/>
+ <element ref="sca:implementationType"/>
+ <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
+ </choice>
+ <attribute name="targetNamespace" type="anyURI" use="optional"/>
+ </complexType>
+ </element>
+
+</schema> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-bpel.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-bpel.xsd
new file mode 100644
index 0000000000..87b443fb36
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-bpel.xsd
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- (c) Copyright SCA Collaboration 2006 -->
+<xsd:schema xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ targetNamespace="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ elementFormDefault="qualified">
+
+ <xsd:include schemaLocation="sca-core.xsd" />
+
+ <xsd:element name="implementation.bpel" type="BpelImplementation"
+ substitutionGroup="implementation" />
+
+ <xsd:complexType name="BpelImplementation">
+ <xsd:complexContent>
+ <xsd:extension base="Implementation">
+ <xsd:sequence>
+ <xsd:any namespace="##other" processContents="lax"
+ minOccurs="0" maxOccurs="unbounded" />
+ </xsd:sequence>
+ <xsd:attribute name="process" type="xsd:QName" use="required" />
+ <xsd:anyAttribute namespace="##any" processContents="lax" />
+ </xsd:extension>
+ </xsd:complexContent>
+ </xsd:complexType>
+
+ <xsd:element name="interface.partnerLinkType" type="BpelPartnerLinkType"
+ substitutionGroup="interface" />
+
+ <xsd:complexType name="BpelPartnerLinkType">
+ <xsd:complexContent>
+ <xsd:extension base="Interface">
+ <xsd:sequence>
+ <xsd:any namespace="##other" processContents="lax"
+ minOccurs="0" maxOccurs="unbounded" />
+ </xsd:sequence>
+ <xsd:attribute name="type" type="xsd:QName" use="required" />
+ <xsd:attribute name="serviceRole" type="xsd:NCName" use="optional" />
+ <xsd:anyAttribute namespace="##any" processContents="lax" />
+ </xsd:extension>
+ </xsd:complexContent>
+ </xsd:complexType>
+
+</xsd:schema> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-composite.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-composite.xsd
new file mode 100644
index 0000000000..99669bc672
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-composite.xsd
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- (c) Copyright SCA Collaboration 2006 -->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <include schemaLocation="sca-core.xsd"/>
+ <element name="implementation.composite" type="sca:SCAImplementation"
+ substitutionGroup="sca:implementation"/>
+ <complexType name="SCAImplementation">
+ <complexContent>
+ <extension base="sca:Implementation">
+ <sequence>
+ <any namespace="##other" processContents="lax" minOccurs="0"
+ maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="name" type="QName" use="required"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </extension>
+ </complexContent>
+ </complexType>
+</schema>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-cpp.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-cpp.xsd
new file mode 100644
index 0000000000..6f1cf14a4b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-cpp.xsd
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- (c) Copyright SCA Collaboration 2006 -->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:sdo="commonj.sdo/XML"
+ elementFormDefault="qualified">
+
+ <include schemaLocation="sca-core.xsd"/>
+
+ <element name="implementation.cpp" type="sca:CPPImplementation" substitutionGroup="sca:implementation" />
+ <complexType name="CPPImplementation">
+ <complexContent>
+ <extension base="sca:Implementation">
+ <sequence>
+ <element name="method" type="sca:CPPImplementationMethod" minOccurs="0" maxOccurs="unbounded" />
+ <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="library" type="NCName" use="required"/>
+ <attribute name="header" type="NCName" use="required"/>
+ <attribute name="path" type="NCName" use="optional"/>
+ <attribute name="class" type="Name" use="optional"/>
+ <attribute name="scope" type="sca:CPPImplementationScope" use="optional"/>
+ <attribute name="eagerInit" type="boolean" use="optional"/>
+ <attribute name="allowsPassByReference" type="boolean" use="optional"/>
+ <attribute name="conversationMaxAge" type="string" use="optional"/>
+ <attribute name="conversationMaxIdle" type="string" use="optional"/>
+ <attribute name="conversationSinglePrincipal" type="boolean" use="optional"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <simpleType name="CPPImplementationScope">
+ <restriction base="string">
+ <enumeration value="stateless"/>
+ <enumeration value="composite"/>
+ <enumeration value="request"/>
+ <enumeration value="converstion"/>
+ </restriction>
+ </simpleType>
+
+ <complexType name="CPPImplementationMethod">
+ <complexContent>
+ <attribute name="name" type="NCName" use="required"/>
+ <attribute name="allowsPassByReference" type="boolean" use="optional"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </complexContent>
+ </complexType>
+
+</schema>
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-ejb.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-ejb.xsd
new file mode 100644
index 0000000000..a7e781b18f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-ejb.xsd
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- (c) Copyright SCA Collaboration 2006 -->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <include schemaLocation="sca-core.xsd"/>
+
+ <element name="implementation.ejb" type="sca:EJBImplementation"
+ substitutionGroup="sca:implementation"/>
+ <complexType name="EJBImplementation">
+ <complexContent>
+ <extension base="sca:Implementation">
+ <sequence>
+ <any namespace="##other" processContents="lax"
+ minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <!-- we might want to make this refer to the JEE ejb-link type -->
+ <attribute name="ejb-link" type="token" use="required"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </extension>
+ </complexContent>
+ </complexType>
+</schema> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-java.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-java.xsd
new file mode 100644
index 0000000000..f9d8171b8e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-java.xsd
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- (c) Copyright SCA Collaboration 2006 -->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <include schemaLocation="sca-core.xsd"/>
+
+ <element name="implementation.java" type="sca:JavaImplementation"
+ substitutionGroup="sca:implementation"/>
+ <complexType name="JavaImplementation">
+ <complexContent>
+ <extension base="sca:Implementation">
+ <sequence>
+ <any namespace="##other" processContents="lax"
+ minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="class" type="NCName" use="required"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </extension>
+ </complexContent>
+ </complexType>
+</schema> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-spring.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-spring.xsd
new file mode 100644
index 0000000000..1cf9fb3ea9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-spring.xsd
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- (c) Copyright SCA Collaboration 2006 -->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <include schemaLocation="sca-core.xsd"/>
+
+ <element name="implementation.spring" type="sca:SpringImplementation"
+ substitutionGroup="sca:implementation"/>
+ <complexType name="SpringImplementation">
+ <complexContent>
+ <extension base="sca:Implementation">
+ <sequence>
+ <any namespace="##other" processContents="lax"
+ minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="location" type="anyURI" use="required"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </extension>
+ </complexContent>
+ </complexType>
+</schema> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-web.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-web.xsd
new file mode 100644
index 0000000000..a1adf10fd9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-implementation-web.xsd
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- (c) Copyright SCA Collaboration 2006 -->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <include schemaLocation="sca-core.xsd"/>
+
+ <element name="implementation.web" type="sca:WebImplementation"
+ substitutionGroup="sca:implementation"/>
+ <complexType name="WebImplementation">
+ <complexContent>
+ <extension base="sca:Implementation">
+ <sequence>
+ <any namespace="##other" processContents="lax"
+ minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="web-uri" type="string" use="required"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </extension>
+ </complexContent>
+ </complexType>
+</schema> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-interface-cpp.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-interface-cpp.xsd
new file mode 100644
index 0000000000..44f14e5ed5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-interface-cpp.xsd
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- (c) Copyright SCA Collaboration 2006 -->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://www.commonj.org/xmlns/sca/1.0/"
+ xmlns:sca="http://www.commonj.org/xmlns/sca/1.0/"
+ xmlns:sdo="commonj.sdo/XML"
+ elementFormDefault="qualified">
+
+ <include schemaLocation="sca-core.xsd"/>
+
+ <element name="interface.cpp" type="sca:CPPInterface" substitutionGroup="sca:interface"/>
+
+ <complexType name="CPPInterface">
+ <complexContent>
+ <extension base="sca:Interface">
+ <sequence>
+ <element name="method" type="sca:CPPMethod" minOccurs="0" maxOccurs="unbounded" />
+ <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="header" type="NCName" use="required"/>
+ <attribute name="class" type="Name" use="required"/>
+ <attribute name="callbackHeader" type="NCName" use="optional"/>
+ <attribute name="callbackClass" type="Name" use="optional"/>
+ <attribute name="remotable" type="boolean" use="optional"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </extension>
+ </complexContent>
+ </complexType>
+
+ <complexType name="CPPMethod">
+ <complexContent>
+ <attribute name="name" type="NCName" use="required"/>
+ <attribute name="oneWay" type="boolean" use="optional"/>
+ <attribute name="endConversation" type="boolean" use="optional"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </complexContent>
+ </complexType>
+
+</schema>
+
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-interface-java.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-interface-java.xsd
new file mode 100644
index 0000000000..81f939bdb4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-interface-java.xsd
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- (c) Copyright SCA Collaboration 2006, 2007 -->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <include schemaLocation="sca-core.xsd"/>
+
+ <element name="interface.java" type="sca:JavaInterface" substitutionGroup="sca:interface"/>
+ <complexType name="JavaInterface">
+ <complexContent>
+ <extension base="sca:Interface">
+ <sequence>
+ <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="interface" type="NCName" use="required"/>
+ <attribute name="callbackInterface" type="NCName" use="optional"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </extension>
+ </complexContent>
+ </complexType>
+</schema> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-interface-wsdl.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-interface-wsdl.xsd
new file mode 100644
index 0000000000..c1fdfd8f3c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-interface-wsdl.xsd
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- (c) Copyright SCA Collaboration 2006, 2007 -->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <include schemaLocation="sca-core.xsd"/>
+
+ <element name="interface.wsdl" type="sca:WSDLPortType" substitutionGroup="sca:interface"/>
+ <complexType name="WSDLPortType">
+ <complexContent>
+ <extension base="sca:Interface">
+ <sequence>
+ <any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="interface" type="anyURI" use="required"/>
+ <attribute name="callbackInterface" type="anyURI" use="optional"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </extension>
+ </complexContent>
+ </complexType>
+</schema> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-policy.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-policy.xsd
new file mode 100644
index 0000000000..2c4875f36c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca-policy.xsd
@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- (c) Copyright SCA Collaboration 2006, 2007 -->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy"
+ elementFormDefault="qualified">
+
+ <include schemaLocation="sca-core.xsd"/>
+
+ <element name="intent" type="sca:Intent"/>
+ <complexType name="Intent">
+ <sequence>
+ <element name="description" type="string" minOccurs="0" maxOccurs="1" />
+ <any namespace="##other" processContents="lax"
+ minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="name" type="QName" use="required"/>
+ <attribute name="constrains" type="sca:listOfQNames" use="optional"/>
+ <attribute name="requires" type="sca:listOfQNames" use="optional"/>
+ <attribute name="excludes" type="sca:listOfQNames" use="optional"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </complexType>
+
+ <element name="policySet" type="sca:PolicySet"/>
+ <complexType name="PolicySet">
+ <choice minOccurs="0" maxOccurs="unbounded">
+ <element name="policySetReference" type="sca:PolicySetReference"/>
+ <element name="intentMap" type="sca:IntentMap"/>
+ <any namespace="##other" processContents="lax"/>
+ </choice>
+ <attribute name="name" type="QName" use="required"/>
+ <attribute name="provides" type="sca:listOfQNames" use="optional"/>
+ <attribute name="appliesTo" type="string" use="required"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </complexType>
+
+ <complexType name="PolicySetReference">
+ <attribute name="name" type="QName" use="required"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </complexType>
+
+ <complexType name="IntentMap">
+ <choice minOccurs="1" maxOccurs="unbounded">
+ <element name="qualifier" type="sca:Qualifier"/>
+ <any namespace="##other" processContents="lax"/>
+ </choice>
+ <attribute name="provides" type="QName" use="required"/>
+ <attribute name="default" type="string" use="optional"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </complexType>
+
+ <complexType name="Qualifier">
+ <choice minOccurs="1" maxOccurs="unbounded">
+ <element name="intentMap" type="sca:IntentMap"/>
+ <any namespace="##other" processContents="lax"/>
+ </choice>
+ <attribute name="name" type="string" use="required"/>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </complexType>
+
+ <element name="allow" type="sca:Allow"/>
+ <complexType name="Allow">
+ <attribute name="roles" type="string" use="required"/>
+ </complexType>
+
+ <element name="permitAll" type="sca:PermitAll"/>
+ <complexType name="PermitAll"/>
+
+ <element name="denyAll" type="sca:DenyAll"/>
+ <complexType name="DenyAll"/>
+
+ <element name="runAs" type="sca:RunAs"/>
+ <complexType name="RunAs">
+ <attribute name="role" type="string" use="required"/>
+ </complexType>
+</schema>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca.xsd
new file mode 100644
index 0000000000..88edad794c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/sca.xsd
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- (c) Copyright SCA Collaboration 2006, 2007 -->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0">
+
+ <include schemaLocation="sca-core.xsd"/>
+
+ <include schemaLocation="sca-interface-java.xsd"/>
+ <include schemaLocation="sca-interface-wsdl.xsd"/>
+
+ <include schemaLocation="sca-implementation-java.xsd"/>
+ <include schemaLocation="sca-implementation-composite.xsd"/>
+
+ <include schemaLocation="sca-binding-webservice.xsd"/>
+ <include schemaLocation="sca-binding-jms.xsd"/>
+ <include schemaLocation="sca-binding-sca.xsd"/>
+
+ <include schemaLocation="sca-contributions.xsd"/>
+
+ <include schemaLocation="sca-definitions.xsd"/>
+ <include schemaLocation="sca-policy.xsd"/>
+
+</schema> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-atom.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-atom.xsd
new file mode 100644
index 0000000000..c93a1d72de
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-atom.xsd
@@ -0,0 +1,41 @@
+<?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.
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <import namespace="http://www.osoa.org/xmlns/sca/1.0" schemaLocation="sca-core.xsd"/>
+
+ <element name="binding.atom" type="t:AtomBinding"/>
+
+ <complexType name="AtomBinding">
+ <complexContent>
+ <extension base="sca:Binding">
+ <sequence>
+ <any namespace="##targetNamespace" processContents="lax" minOccurs="0"
+ maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="title" type="string" use="optional"/>
+ </extension>
+ </complexContent>
+ </complexType>
+</schema>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-dwr.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-dwr.xsd
new file mode 100644
index 0000000000..d0da5421ec
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-dwr.xsd
@@ -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.
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <import namespace="http://www.osoa.org/xmlns/sca/1.0" schemaLocation="sca-core.xsd"/>
+
+ <element name="binding.dwr" type="t:DWRBinding"/>
+
+ <complexType name="DWRBinding">
+ <complexContent>
+ <extension base="sca:Binding">
+ <sequence>
+ <any namespace="##targetNamespace" processContents="lax" minOccurs="0"
+ maxOccurs="unbounded"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+</schema>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-http.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-http.xsd
new file mode 100644
index 0000000000..ff48b97d7a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-http.xsd
@@ -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.
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <import namespace="http://www.osoa.org/xmlns/sca/1.0" schemaLocation="sca-core.xsd"/>
+
+ <element name="binding.http" type="t:HTTPBinding"/>
+
+ <complexType name="HTTPBinding">
+ <complexContent>
+ <extension base="sca:Binding">
+ <sequence>
+ <any namespace="##targetNamespace" processContents="lax" minOccurs="0"
+ maxOccurs="unbounded"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+</schema>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-jsonrpc.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-jsonrpc.xsd
new file mode 100644
index 0000000000..7c79738898
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-jsonrpc.xsd
@@ -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.
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <import namespace="http://www.osoa.org/xmlns/sca/1.0" schemaLocation="sca-core.xsd"/>
+
+ <element name="binding.jsonrpc" type="t:JSONRPCBinding"/>
+
+ <complexType name="JSONRPCBinding">
+ <complexContent>
+ <extension base="sca:Binding">
+ <sequence>
+ <any namespace="##targetNamespace" processContents="lax" minOccurs="0"
+ maxOccurs="unbounded"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+</schema>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-notification.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-notification.xsd
new file mode 100644
index 0000000000..6d5468b2f9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-notification.xsd
@@ -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.
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <import namespace="http://www.osoa.org/xmlns/sca/1.0" schemaLocation="sca-core.xsd"/>
+
+ <element name="binding.notification" type="t:NotificationBinding"/>
+
+ <complexType name="NotificationBinding">
+ <complexContent>
+ <extension base="sca:Binding">
+ <sequence>
+ <any namespace="##targetNamespace" processContents="lax" minOccurs="0"
+ maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="ntm" type="anyURI" use="optional"/>
+ <attribute name="notificationType" type="anyURI" use="optional"/>
+ </extension>
+ </complexContent>
+ </complexType>
+</schema>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rmi.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rmi.xsd
new file mode 100644
index 0000000000..2697a1ea98
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rmi.xsd
@@ -0,0 +1,43 @@
+<?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.
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <import namespace="http://www.osoa.org/xmlns/sca/1.0" schemaLocation="sca-core.xsd"/>
+
+ <element name="binding.rmi" type="t:RMIBinding"/>
+
+ <complexType name="RMIBinding">
+ <complexContent>
+ <extension base="sca:Binding">
+ <sequence>
+ <any namespace="##targetNamespace" processContents="lax" minOccurs="0"
+ maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="host" type="anyURI" use="optional"/>
+ <attribute name="port" type="int" use="optional"/>
+ <attribute name="serviceName" type="anyURI" use="required"/>
+ </extension>
+ </complexContent>
+ </complexType>
+</schema>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rss.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rss.xsd
new file mode 100644
index 0000000000..821f323d73
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-binding-rss.xsd
@@ -0,0 +1,41 @@
+<?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.
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <import namespace="http://www.osoa.org/xmlns/sca/1.0" schemaLocation="sca-core.xsd"/>
+
+ <element name="binding.rss" type="t:RSSBinding"/>
+
+ <complexType name="RSSBinding">
+ <complexContent>
+ <extension base="sca:Binding">
+ <sequence>
+ <any namespace="##targetNamespace" processContents="lax" minOccurs="0"
+ maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="title" type="string" use="optional"/>
+ </extension>
+ </complexContent>
+ </complexType>
+</schema>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-data-helper.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-data-helper.xsd
new file mode 100644
index 0000000000..4331da0439
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-data-helper.xsd
@@ -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.
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://data.tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:data="http://data.tuscany.apache.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <complexType name="ConnectionProperties">
+ <attribute name="driverClass" type="string" />
+ <attribute name="databaseURL" type="string" />
+ <attribute name="userName" type="string" default="" />
+ <attribute name="password" type="string" default="" />
+ <attribute name="loginTimeout" type="int" default="0" />
+ </complexType>
+
+ <complexType name="ConnectionInfo">
+ <sequence>
+ <element maxOccurs="1" minOccurs="0"
+ name="ConnectionProperties" type="data:ConnectionProperties" />
+ </sequence>
+ <attribute name="dataSource" type="string" />
+ <attribute name="managedtx" type="boolean"
+ default="true" />
+ </complexType>
+</schema>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-das.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-das.xsd
new file mode 100644
index 0000000000..1f6f9abb16
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-das.xsd
@@ -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.
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:data="http://data.tuscany.apache.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <import namespace="http://www.osoa.org/xmlns/sca/1.0" schemaLocation="sca-core.xsd"/>
+ <import namespace="http://data.tuscany.apache.org/xmlns/sca/1.0" schemaLocation="tuscany-sca-data-helper.xsd"/>
+
+ <element name="implementation.das" type="t:DASImplementation"/>
+
+ <complexType name="DASImplementation">
+ <complexContent>
+ <extension base="sca:Implementation">
+ <sequence>
+ <any namespace="##targetNamespace" processContents="lax"
+ minOccurs="0" maxOccurs="unbounded"/>
+ <element maxOccurs="1" minOccurs="0" name="ConnectionInfo"
+ type="data:ConnectionInfo"/>
+ </sequence>
+ <attribute name="config" type="NCName" use="required"/>
+ <attribute name="dataAccessType" type="NCName" use="required"/>
+ </extension>
+ </complexContent>
+ </complexType>
+</schema>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-data-xml.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-data-xml.xsd
new file mode 100644
index 0000000000..4a06bdd36a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-data-xml.xsd
@@ -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.
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:data="http://data.tuscany.apache.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <import namespace="http://www.osoa.org/xmlns/sca/1.0" schemaLocation="sca-core.xsd"/>
+ <import namespace="http://data.tuscany.apache.org/xmlns/sca/1.0" schemaLocation="tuscany-sca-data-helper.xsd"/>
+
+ <element name="implementation.data" type="t:DATAImplementation"/>
+
+ <complexType name="DATAImplementation">
+ <complexContent>
+ <extension base="sca:Implementation">
+ <sequence>
+ <any namespace="##targetNamespace" processContents="lax"
+ minOccurs="0" maxOccurs="unbounded"/>
+ <element maxOccurs="1" minOccurs="0" name="ConnectionInfo"
+ type="data:ConnectionInfo"/>
+ </sequence>
+ </extension>
+ </complexContent>
+ </complexType>
+
+</schema>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-node.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-node.xsd
new file mode 100644
index 0000000000..1b5c8aece2
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-node.xsd
@@ -0,0 +1,43 @@
+<?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.
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <import namespace="http://www.osoa.org/xmlns/sca/1.0" schemaLocation="sca-core.xsd"/>
+
+ <element name="implementation.node" type="t:NodeImplementation"/>
+
+ <complexType name="NodeImplementation">
+ <complexContent>
+ <extension base="sca:Implementation">
+ <sequence>
+ <any namespace="##targetNamespace" processContents="lax"
+ minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="uri" type="string" use="required"/>
+ <attribute name="composite" type="QName" use="required"/>
+ </extension>
+ </complexContent>
+ </complexType>
+
+</schema>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-notification.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-notification.xsd
new file mode 100644
index 0000000000..f8d437310e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-notification.xsd
@@ -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.
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <import namespace="http://www.osoa.org/xmlns/sca/1.0" schemaLocation="sca-core.xsd"/>
+
+ <element name="implementation.notification" type="t:NotificationImplementation"/>
+
+ <complexType name="NotificationImplementation">
+ <complexContent>
+ <extension base="sca:Implementation">
+ <sequence>
+ <any namespace="##targetNamespace" processContents="lax"
+ minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="name" type="NCName" use="required"/>
+ </extension>
+ </complexContent>
+ </complexType>
+
+</schema>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-osgi.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-osgi.xsd
new file mode 100644
index 0000000000..f8ece54a07
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-osgi.xsd
@@ -0,0 +1,43 @@
+<?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.
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <import namespace="http://www.osoa.org/xmlns/sca/1.0" schemaLocation="sca-core.xsd"/>
+
+ <element name="implementation.osgi" type="t:OSGiImplementation"/>
+
+ <!-- TODO Declare the proper attributes and elements -->
+ <complexType name="OSGiImplementation">
+ <complexContent>
+ <extension base="sca:Implementation">
+ <sequence>
+ <any namespace="##any" processContents="lax"
+ minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <anyAttribute namespace="##any" processContents="lax"/>
+ </extension>
+ </complexContent>
+ </complexType>
+
+</schema>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-resource.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-resource.xsd
new file mode 100644
index 0000000000..dd596821ea
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-resource.xsd
@@ -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.
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <import namespace="http://www.osoa.org/xmlns/sca/1.0" schemaLocation="sca-core.xsd"/>
+
+ <element name="implementation.resource" type="t:ResourceImplementation"/>
+
+ <complexType name="ResourceImplementation">
+ <complexContent>
+ <extension base="sca:Implementation">
+ <sequence>
+ <any namespace="##targetNamespace" processContents="lax"
+ minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="location" type="anyURI" use="required"/>
+ </extension>
+ </complexContent>
+ </complexType>
+
+</schema>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-script.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-script.xsd
new file mode 100644
index 0000000000..e1723d65f0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-script.xsd
@@ -0,0 +1,43 @@
+<?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.
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <import namespace="http://www.osoa.org/xmlns/sca/1.0" schemaLocation="sca-core.xsd"/>
+
+ <element name="implementation.script" type="t:ScriptImplementation"/>
+
+ <complexType name="ScriptImplementation">
+ <complexContent mixed="true">
+ <extension base="sca:Implementation">
+ <sequence>
+ <any namespace="##targetNamespace" processContents="lax"
+ minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="script" type="anyURI" use="optional"/>
+ <attribute name="language" type="NCName" use="optional"/>
+ </extension>
+ </complexContent>
+ </complexType>
+
+</schema>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-widget.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-widget.xsd
new file mode 100644
index 0000000000..0c0998595f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-widget.xsd
@@ -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.
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <import namespace="http://www.osoa.org/xmlns/sca/1.0" schemaLocation="sca-core.xsd"/>
+
+ <element name="implementation.widget" type="t:WidgetImplementation"/>
+
+ <complexType name="WidgetImplementation">
+ <complexContent>
+ <extension base="sca:Implementation">
+ <sequence>
+ <any namespace="##targetNamespace" processContents="lax"
+ minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="location" type="anyURI" use="required"/>
+ </extension>
+ </complexContent>
+ </complexType>
+
+</schema>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-xquery.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-xquery.xsd
new file mode 100644
index 0000000000..cdabb697aa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca-implementation-xquery.xsd
@@ -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.
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
+ elementFormDefault="qualified">
+
+ <import namespace="http://www.osoa.org/xmlns/sca/1.0" schemaLocation="sca-core.xsd"/>
+
+ <element name="implementation.xquery" type="t:XQueryImplementation"/>
+
+ <complexType name="XQueryImplementation">
+ <complexContent>
+ <extension base="sca:Implementation">
+ <sequence>
+ <any namespace="##targetNamespace" processContents="lax"
+ minOccurs="0" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="location" type="anyURI" use="required"/>
+ </extension>
+ </complexContent>
+ </complexType>
+
+</schema>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca.xsd b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca.xsd
new file mode 100644
index 0000000000..032143bd13
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly-xsd/src/main/resources/tuscany-sca.xsd
@@ -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.
+-->
+<schema xmlns="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://tuscany.apache.org/xmlns/sca/1.0">
+
+ <import namespace="http://www.osoa.org/xmlns/sca/1.0" schemaLocation="sca-all.xsd"/>
+ <import namespace="http://data.tuscany.apache.org/xmlns/sca/1.0" schemaLocation="tuscany-sca-data-helper.xsd"/>
+
+ <include schemaLocation="tuscany-sca-binding-atom.xsd"/>
+ <include schemaLocation="tuscany-sca-binding-dwr.xsd"/>
+ <include schemaLocation="tuscany-sca-binding-http.xsd"/>
+ <include schemaLocation="tuscany-sca-binding-jsonrpc.xsd"/>
+ <include schemaLocation="tuscany-sca-binding-notification.xsd"/>
+ <include schemaLocation="tuscany-sca-binding-rmi.xsd"/>
+ <include schemaLocation="tuscany-sca-binding-rss.xsd"/>
+
+ <!--
+ <include schemaLocation="tuscany-sca-implementation-das.xsd"/>
+ <include schemaLocation="tuscany-sca-implementation-data-xml.xsd"/>
+ -->
+ <include schemaLocation="tuscany-sca-implementation-node.xsd"/>
+ <include schemaLocation="tuscany-sca-implementation-notification.xsd"/>
+ <include schemaLocation="tuscany-sca-implementation-osgi.xsd"/>
+ <include schemaLocation="tuscany-sca-implementation-resource.xsd"/>
+ <include schemaLocation="tuscany-sca-implementation-script.xsd"/>
+ <include schemaLocation="tuscany-sca-implementation-widget.xsd"/>
+ <include schemaLocation="tuscany-sca-implementation-xquery.xsd"/>
+
+</schema> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/LICENSE b/sca-java-1.x/branches/sca-android/modules/assembly/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/META-INF/README b/sca-java-1.x/branches/sca-android/modules/assembly/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/NOTICE b/sca-java-1.x/branches/sca-android/modules/assembly/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/pom.xml b/sca-java-1.x/branches/sca-android/modules/assembly/pom.xml
new file mode 100644
index 0000000000..5257d7ef63
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/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>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-assembly</artifactId>
+ <name>Apache Tuscany SCA Assembly Model</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-policy</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-interface</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-definitions</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-monitor</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.assembly</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.assembly*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractContract.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractContract.java
new file mode 100644
index 0000000000..b8487d95c5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractContract.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.policy.IntentAttachPoint;
+
+/**
+ * Interface contracts define one or more business functions. These business
+ * functions are provided by services and are used by references.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface AbstractContract extends Base, Extensible, IntentAttachPoint, OperationsConfigurator {
+
+ /**
+ * Returns the name of the contract.
+ *
+ * @return the name of the contract
+ */
+ String getName();
+
+ /**
+ * Sets the name of the contract.
+ *
+ * @param name the name of the contract
+ */
+ void setName(String name);
+
+ /**
+ * Returns the interface contract defining the interface and callback
+ * interface for the contract.
+ *
+ * @return the interface contract
+ */
+ InterfaceContract getInterfaceContract();
+
+ /**
+ * Sets the interface contract defining the interface and callback
+ * interface for the contract.
+ *
+ * @param interfaceContract the interface contract
+ */
+ void setInterfaceContract(InterfaceContract interfaceContract);
+
+ /**
+ * Returns true if this contract is a reference or service created internally
+ * to handle a callback interface of another contract, false otherwise.
+ *
+ * @return true for a callback contract, false otherwise
+ */
+ boolean isCallback();
+
+ /**
+ * Sets a flag indicating whether this is a callback contract.
+ *
+ * @param isCallback true for a callback contract, false otherwise
+ */
+ void setIsCallback(boolean isCallback);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractProperty.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractProperty.java
new file mode 100644
index 0000000000..05f0e60981
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractProperty.java
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.policy.IntentAttachPoint;
+
+/**
+ * A property allows for the configuration of an implementation with externally
+ * set data values. An implementation can have zero or more properties. Each
+ * property has a data type, which may be either simple or complex. An
+ * implementation may also define a default value for a property.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface AbstractProperty extends Base, Extensible, IntentAttachPoint {
+
+ /**
+ * Returns the property name.
+ *
+ * @return the property name
+ */
+ String getName();
+
+ /**
+ * Sets the property name.
+ *
+ * @param name the property name
+ */
+ void setName(String name);
+
+ /**
+ * Returns the default value of the property.
+ *
+ * @return the default value of this property
+ */
+ Object getValue();
+
+ /**
+ * Sets the default value of the property.
+ *
+ * @param defaultValue the default value of this property
+ */
+ void setValue(Object defaultValue);
+
+ /**
+ * Returns true if the property allows multiple values.
+ *
+ * @return true if the property allows multiple values
+ */
+ boolean isMany();
+
+ /**
+ * Sets whether or not the property allows multiple values.
+ *
+ * @param many true if the property should allow multiple values
+ */
+ void setMany(boolean many);
+
+ /**
+ * Returns true if a value must be supplied for the property.
+ *
+ * @return true is a value must be supplied for the property
+ */
+ boolean isMustSupply();
+
+ /**
+ * Sets whether a value must be supplied for the property.
+ *
+ * @param mustSupply set to true to require that a value be supplied for
+ * uses of this property
+ */
+ void setMustSupply(boolean mustSupply);
+
+ /**
+ * Returns the data type of this property. This is the qualified name of an
+ * XML schema type.
+ *
+ * @return the type of this property
+ */
+ QName getXSDType();
+
+ /**
+ * Sets the data type of this property. This is the qualified name of an XML
+ * schema type.
+ *
+ * @param type the type of this property
+ */
+ void setXSDType(QName type);
+
+ /**
+ * Returns the element defining the data type of this property. This is the
+ * qualified name of an XML schema element.
+ *
+ * @return the element defining the type of this property
+ */
+ QName getXSDElement();
+
+ /**
+ * Sets the element defining the data type of this property. This is the
+ * qualified name of an XML schema element.
+ *
+ * @param element the element defining the type of this property
+ */
+ void setXSDElement(QName element);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractReference.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractReference.java
new file mode 100644
index 0000000000..a9ef26bbb9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractReference.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+/**
+ * Represents a reference contract.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface AbstractReference extends AbstractContract {
+
+ /**
+ * Returns the multiplicity allowed for wires connected to this reference.
+ *
+ * @return the multiplicity allowed for wires connected to this reference
+ */
+ Multiplicity getMultiplicity();
+
+ /**
+ * Sets the multiplicity allowed for wires connected to this reference.
+ *
+ * @param multiplicity the multiplicity allowed for wires connected to this
+ * reference
+ */
+ void setMultiplicity(Multiplicity multiplicity);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractService.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractService.java
new file mode 100644
index 0000000000..9ae511c07b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AbstractService.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+/**
+ * Represents a service contract.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface AbstractService extends AbstractContract {
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AssemblyFactory.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AssemblyFactory.java
new file mode 100644
index 0000000000..8a4fc6dfda
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/AssemblyFactory.java
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+
+/**
+ * A factory for the assembly model
+ *
+ * @version $Rev$ $Date$
+ */
+public interface AssemblyFactory {
+
+ /**
+ * Create a new abstract property.
+ *
+ * @return a new abstract property
+ */
+ AbstractProperty createAbstractProperty();
+
+ /**
+ * Create a new abstract reference.
+ *
+ * @return a new abstract reference
+ */
+ AbstractReference createAbstractReference();
+
+ /**
+ * Create a new abstract service.
+ *
+ * @return a new abstract service
+ */
+ AbstractService createAbstractService();
+
+ /**
+ * Create a new callback.
+ *
+ * @return
+ */
+ Callback createCallback();
+
+ /**
+ * Create a new component.
+ *
+ * @return a new component
+ */
+ Component createComponent();
+
+ /**
+ * Create a new component property.
+ *
+ * @return a new component property
+ */
+ ComponentProperty createComponentProperty();
+
+ /**
+ * Create a new component reference.
+ *
+ * @return a new component reference
+ */
+ ComponentReference createComponentReference();
+
+ /**
+ * Create a new component service.
+ *
+ * @return a new component service
+ */
+ ComponentService createComponentService();
+
+ /**
+ * Create a new component type
+ *
+ * @return a new component type
+ */
+ ComponentType createComponentType();
+
+ /**
+ * Create a new composite.
+ *
+ * @return a new composite
+ */
+ Composite createComposite();
+
+ /**
+ * Create a new composite reference.
+ *
+ * @return a new composite reference
+ */
+ CompositeReference createCompositeReference();
+
+ /**
+ * Create a new composite service.
+ *
+ * @return a new composite service
+ */
+ CompositeService createCompositeService();
+
+ /**
+ * Create a new constraining type.
+ *
+ * @return a new constraining type
+ */
+ ConstrainingType createConstrainingType();
+
+ /**
+ * Create a new property.
+ *
+ * @return a new property
+ */
+ Property createProperty();
+
+ /**
+ * Create a new reference.
+ *
+ * @return a new reference
+ */
+ Reference createReference();
+
+ /**
+ * Create a new service.
+ *
+ * @return a new service
+ */
+ Service createService();
+
+ /**
+ * Create a new wire.
+ *
+ * @return a new wire
+ */
+ Wire createWire();
+
+ /**
+ * Create a new configured operation.
+ *
+ * @return a new ConfiguredOperation
+ */
+ ConfiguredOperation createConfiguredOperation();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Base.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Base.java
new file mode 100644
index 0000000000..76511d351d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Base.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+
+/**
+ * Base interface for all assembly model objects.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Base {
+
+ /**
+ * Returns true if the model element is unresolved.
+ *
+ * @return true if the model element is unresolved.
+ */
+ boolean isUnresolved();
+
+ /**
+ * Sets whether the model element is unresolved.
+ *
+ * @param unresolved whether the model element is unresolved
+ */
+ void setUnresolved(boolean unresolved);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Binding.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Binding.java
new file mode 100644
index 0000000000..f8b7d4d236
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Binding.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+
+/**
+ * Represents a binding.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Binding extends Base, Cloneable {
+
+ /**
+ * Returns the binding URI.
+ *
+ * @return the binding URI
+ */
+ String getURI();
+
+ /**
+ * Sets the binding URI.
+ *
+ * @param uri the binding URI
+ */
+ void setURI(String uri);
+
+ /**
+ * Returns the binding name.
+ *
+ * @return the binding name
+ */
+ String getName();
+
+ /**
+ * Sets the binding name.
+ *
+ * @param name the binding name
+ */
+ void setName(String name);
+
+ /**
+ * Clone the binding
+ *
+ * @return
+ */
+ Object clone() throws CloneNotSupportedException;
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java
new file mode 100644
index 0000000000..f49a653aa9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Callback.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.policy.IntentAttachPoint;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+
+/**
+ * Represents a callback object describing the bindings to use for callbacks.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Callback extends Base, Extensible, IntentAttachPoint, PolicySetAttachPoint, OperationsConfigurator {
+
+ /**
+ * Returns the bindings supported for callbacks.
+ *
+ * @return the bindings supported for callbacks
+ */
+ List<Binding> getBindings();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Component.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Component.java
new file mode 100644
index 0000000000..8e1943224c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Component.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+
+/**
+ * Represents a component. A component is a configured instance of an
+ * implementation.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Component extends Base, Extensible, PolicySetAttachPoint, Cloneable {
+
+ /**
+ * Returns the URI of the component.
+ *
+ * @return the URI of the component
+ */
+ String getURI();
+
+ /**
+ * Sets the URI of the component.
+ *
+ * @param uri the URI of the component
+ */
+ void setURI(String uri);
+
+ /**
+ * Returns the name of the component.
+ *
+ * @return the name of the component
+ */
+ String getName();
+
+ /**
+ * Sets the name of the component.
+ *
+ * @param name the name of the component
+ */
+ void setName(String name);
+
+ /**
+ * Returns the component implementation.
+ *
+ * @return the component implementation
+ */
+ Implementation getImplementation();
+
+ /**
+ * Sets the component implementation
+ *
+ * @param implementation the component implementation
+ */
+ void setImplementation(Implementation implementation);
+
+ /**
+ * Returns a list of references used by the component.
+ *
+ * @return a list of references used by the component
+ */
+ List<ComponentReference> getReferences();
+
+ /**
+ * Returns a list of services exposed by the component.
+ *
+ * @return a list of services exposed by the component
+ */
+ List<ComponentService> getServices();
+
+ /**
+ * Returns a list of properties for the component.
+ *
+ * @return a list of properties
+ */
+ List<ComponentProperty> getProperties();
+
+ /**
+ * Returns a constraining type defining the shape of the component.
+ *
+ * @return a constraining type
+ */
+ ConstrainingType getConstrainingType();
+
+ /**
+ * Sets a constraining type defining the shape of the component.
+ *
+ * @param constrainingType the constraining type
+ */
+ void setConstrainingType(ConstrainingType constrainingType);
+
+ /**
+ * Return the Boolean value of autowire
+ * @return null/TRUE/FALSE
+ */
+ Boolean getAutowire();
+
+ /**
+ * Sets whether component references should be autowired.
+ *
+ * @param autowire whether component references should be autowired
+ */
+ void setAutowire(Boolean autowire);
+
+
+ /**
+ * Returns a clone of the component.
+ *
+ * @return a clone of the component
+ * @throws CloneNotSupportedException
+ */
+ Object clone() throws CloneNotSupportedException;
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentProperty.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentProperty.java
new file mode 100644
index 0000000000..13d19b1757
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentProperty.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+import javax.xml.xpath.XPathExpression;
+
+/**
+ * Represents a configured property of a component.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ComponentProperty extends Property {
+
+ /**
+ * Returns the property defined by the component implementation.
+ *
+ * @return the property defined by the component implementation
+ */
+ Property getProperty();
+
+ /**
+ * Sets the property defined by this component implementation.
+ *
+ * @param property the property defined by this component implementation
+ */
+ void setProperty(Property property);
+
+ /**
+ * Returns an XPath expression referencing a property of the enclosing
+ * composite.
+ *
+ * @return an XPath expression referencing a property of the enclosing
+ * composite
+ */
+ String getSource();
+
+ /**
+ * Sets an XPath expression referencing a property of the enclosing
+ * composite.
+ *
+ * @param source an XPath expression referencing a property of the enclosing
+ * composite
+ */
+ void setSource(String source);
+
+ /**
+ * Get the XPath expression for the source attribute
+ * @return the XPath expression for the source attribute
+ */
+ XPathExpression getSourceXPathExpression();
+
+ /**
+ * Set the XPath expression for the source attribute
+ * @param sourceXPathExpression the XPath expression for the source attribute
+ */
+ void setSourceXPathExpression(XPathExpression sourceXPathExpression);
+
+ /**
+ * Returns a URI to a file containing the property value.
+ *
+ * @return a URI to a file containing the property value
+ */
+ String getFile();
+
+ /**
+ * Sets a URI to a file containing the property value.
+ *
+ * @param file a URI to a file containing the property value
+ */
+ void setFile(String file);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.java
new file mode 100644
index 0000000000..ce40bc089b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentReference.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+import java.util.List;
+
+
+
+/**
+ * An instance of a reference associated with a particular component.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ComponentReference extends Reference {
+
+ /**
+ * Returns the reference defined by the implementation for this reference.
+ *
+ * @return the implementation reference
+ */
+ Reference getReference();
+
+ /**
+ * Sets the reference defined by the implementation for this reference.
+ *
+ * @param reference the implementation reference
+ */
+ void setReference(Reference reference);
+
+ /**
+ * Return the Boolean value of autowire
+ * @return null/TRUE/FALSE
+ */
+ Boolean getAutowire();
+
+ /**
+ * Sets whether component references should be autowired.
+ *
+ * @param autowire whether component references should be autowired
+ */
+ void setAutowire(Boolean autowire);
+
+
+ /**
+ * Returns the callback service created internally as a target endpoint
+ * for callbacks to this reference.
+ *
+ * @return the callback service
+ */
+ ComponentService getCallbackService();
+
+ /**
+ * Sets the callback service created internally as a target endpoint
+ * for callbacks to this reference.
+ *
+ * @param callbackService the callback service
+ */
+ void setCallbackService(ComponentService callbackService);
+
+ /**
+ * Returns the endpoints implied by this reference.
+ *
+ * @return the endpoints implied by this reference
+ */
+ List<Endpoint> getEndpoints();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentService.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentService.java
new file mode 100644
index 0000000000..65945692f1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentService.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+
+/**
+ * An addressable instance of a service associated with a particular component.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ComponentService extends Service {
+
+ /**
+ * Returns the service defined by the implementation for this service.
+ *
+ * @return
+ */
+ Service getService();
+
+ /**
+ * Sets the service defined by the implementation for this service.
+ *
+ * @param service
+ */
+ void setService(Service service);
+
+ /**
+ * Returns the callback reference created internally as a source endpoint
+ * for callbacks from this service.
+ *
+ * @return the callback reference
+ */
+ ComponentReference getCallbackReference();
+
+ /**
+ * Sets the callback reference created internally as a source endpoint
+ * for callbacks from this service.
+ *
+ * @param callbackReference the callback reference
+ */
+ void setCallbackReference(ComponentReference callbackReference);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentType.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentType.java
new file mode 100644
index 0000000000..e1ea65ea39
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ComponentType.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+import java.util.List;
+
+/**
+ * Describes an implementation and represents its configurable aspects.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ComponentType extends Base {
+
+ /**
+ * Returns the URI of this component type.
+ * @return the URI of the component type
+ */
+ String getURI();
+
+ /**
+ * Sets the URI of this component type.
+ * @param uri the URI of the component type
+ */
+ void setURI(String uri);
+
+ /**
+ * Returns a list of services that are offered.
+ *
+ * @return a list of services that are offered
+ */
+ List<Service> getServices();
+
+ /**
+ * Returns the list of reference types that are used.
+ *
+ * @return the list of reference types that are used
+ */
+ List<Reference> getReferences();
+
+ /**
+ * Returns the list of properties that can be set.
+ *
+ * @return the list of properties that can be set
+ */
+ List<Property> getProperties();
+
+ /**
+ * Returns a constraining type defining the shape of the implementation.
+ *
+ * @return a constraining type
+ */
+ ConstrainingType getConstrainingType();
+
+ /**
+ * Sets a constraining type defining the shape of the implementation.
+ *
+ * @param constrainingType the constraining type to set
+ */
+ void setConstrainingType(ConstrainingType constrainingType);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Composite.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Composite.java
new file mode 100644
index 0000000000..2c7b7c6b9e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Composite.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+
+
+/**
+ * Represents a composite.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Composite extends Implementation, Extensible, Cloneable, PolicySetAttachPoint {
+
+ /**
+ * Returns the name of the composite.
+ *
+ * @return the name of the composite
+ */
+ QName getName();
+
+ /**
+ * Sets the name of the composite.
+ *
+ * @param name the name of the composite
+ */
+ void setName(QName name);
+
+ /**
+ * Returns a list of composites included in this composite.
+ *
+ * @return a list of composites included in this composite.
+ */
+ List<Composite> getIncludes();
+
+ /**
+ * Returns a list of components contained in this composite.
+ *
+ * @return a list of components contained in this composite
+ */
+ List<Component> getComponents();
+
+ /**
+ * Returns a list of wires contained in this composite.
+ *
+ * @return a list of wires contained in this composite
+ */
+ List<Wire> getWires();
+
+ /**
+ * Returns true if all the components within the composite must run in the
+ * same process.
+ *
+ * @return true if all the components within the composite must run in the
+ * same process
+ */
+ boolean isLocal();
+
+ /**
+ * Sets whether all the components within the composite must run in the same
+ * process.
+ *
+ * @param local whether all the components within the composite must run in
+ * the same process
+ */
+ void setLocal(boolean local);
+
+ /**
+ * Return the Boolean value of autowire
+ * @return null/TRUE/FALSE
+ */
+ Boolean getAutowire();
+
+ /**
+ * Sets whether component references should be autowired.
+ *
+ * @param autowire whether component references should be autowired
+ */
+ void setAutowire(Boolean autowire);
+
+
+ /**
+ * Returns a clone of the component type.
+ *
+ * @return a clone of the component type
+ * @throws CloneNotSupportedException
+ */
+ Object clone() throws CloneNotSupportedException;
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeReference.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeReference.java
new file mode 100644
index 0000000000..d3fa80ba74
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeReference.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+import java.util.List;
+
+/**
+ * Represents composite reference.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface CompositeReference extends Reference {
+
+ /**
+ * Returns the promoted composite references.
+ *
+ * @return the promoted composite references
+ */
+ List<ComponentReference> getPromotedReferences();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeService.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeService.java
new file mode 100644
index 0000000000..7143f571f9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/CompositeService.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+/**
+ * Represents a composite service.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface CompositeService extends Service {
+
+ /**
+ * Returns the promoted component.
+ *
+ * @return the promoted component.
+ */
+ Component getPromotedComponent();
+
+ /**
+ * Sets the promoted component
+ *
+ * @param promotedComponent the promoted component.
+ */
+ void setPromotedComponent(Component promotedComponent);
+
+ /**
+ * Returns the promoted component service .
+ *
+ * @return the promoted component service.
+ */
+ ComponentService getPromotedService();
+
+ /**
+ * Sets the promoted component service
+ *
+ * @param promotedService the promoted component service.
+ */
+ void setPromotedService(ComponentService promotedService);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ConfiguredOperation.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ConfiguredOperation.java
new file mode 100644
index 0000000000..8832597343
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ConfiguredOperation.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+
+/**
+ * Represents an Operation. Typically Operation elements are used when there is a
+ * need to apply certain facets such as intents and policysets only to a specific
+ * operation provided by a service or reference.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ConfiguredOperation extends Base, PolicySetAttachPoint {
+ /**
+ * Returns the name of the operation.
+ *
+ * @return the name of the operation
+ */
+ String getName();
+
+ /**
+ * Sets the name of the operation.
+ *
+ * @param name the name of the operation
+ */
+ void setName(String name);
+
+ /**
+ * Returns the name of the service or reference to which this operation belongs.
+ * This method is particularly useful when operation elements are specified under implementation
+ * elements and it is necessary to identify which of the various services provided by the
+ * implementation is referred to by the operation element in question
+ *
+ * @return the name of the contract to which this operation belongs
+ */
+ String getContractName();
+
+ /**
+ * Sets the name of the service or reference to which this operation belongs.
+ *
+ * @param contractName the name of the contract to which this operation belongs
+ */
+ void setContractName(String contractName);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ConstrainingType.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ConstrainingType.java
new file mode 100644
index 0000000000..9890bfed68
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/ConstrainingType.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.policy.IntentAttachPoint;
+
+/**
+ * A constrainingType provides the "shape" for a component and its
+ * implementation. Any component configuration that points to a constrainingType
+ * is constrained by this shape. The constrainingType specifies the services,
+ * references and properties that must be implemented.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ConstrainingType extends Base, Extensible, IntentAttachPoint {
+
+ /**
+ * Returns the name of the constrainingType.
+ *
+ * @return the name of the constrainingType
+ */
+ QName getName();
+
+ /**
+ * Sets the name of the constrainingType.
+ *
+ * @param name the name of the constrainingType
+ */
+ void setName(QName name);
+
+ /**
+ * Returns a list of services that are offered.
+ *
+ * @return a list of services that are offered
+ */
+ List<AbstractService> getServices();
+
+ /**
+ * Returns the list of references that are used.
+ *
+ * @return the list of references that are used
+ */
+ List<AbstractReference> getReferences();
+
+ /**
+ * Returns the list of properties that can be set.
+ *
+ * @return the list of properties that can be set
+ */
+ List<AbstractProperty> getProperties();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Contract.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Contract.java
new file mode 100644
index 0000000000..f9a62774e6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Contract.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+
+/**
+ * Represents a contract. A contract can be either a service or a reference.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Contract extends AbstractContract, PolicySetAttachPoint, Cloneable {
+
+ /**
+ * Returns the bindings supported by this contract.
+ *
+ * @return the bindings supported by this contract
+ */
+ List<Binding> getBindings();
+
+ /**
+ * Returns a binding of the specified type or null if there is no such
+ * binding configured on this contract.
+ *
+ * @param <B> the binding type
+ * @param bindingClass the binding type class
+ * @return the binding or null if there is no binding of the specified type
+ */
+ <B> B getBinding(Class<B> bindingClass);
+
+ /**
+ * Returns a callback binding of the specified type or null if there is no such
+ * callback binding configured on this contract.
+ *
+ * @param <B> the callback binding type
+ * @param bindingClass the callback binding type class
+ * @return the callback binding or null if there is no callback binding of the specified type
+ */
+ <B> B getCallbackBinding(Class<B> bindingClass);
+
+ /**
+ * Returns a callback definition of the bindings to use for callbacks.
+ *
+ * @return a definition of the bindings to use for callbacks
+ */
+ Callback getCallback();
+
+ /**
+ * Sets a callback definition of the bindings to use for callbacks
+ *
+ * @param callback a definition of the bindings to use for callbacks
+ */
+ void setCallback(Callback callback);
+
+ /**
+ * Returns a clone of the contract.
+ *
+ * @return a clone of the reference
+ * @throws CloneNotSupportedException
+ */
+ Object clone() throws CloneNotSupportedException;
+
+ /**
+ * Returns the interface contract given a binding. Important in the case where
+ * a reference with multiplicity > 1 has been promoted and has it's list of
+ * resolved bindings extended by a promoting reference. Here the binding
+ * from the promoting reference may need the interface contract from the
+ * promoting reference and not the promoted reference.
+ * TODO - remove this wrinkle with better endpoint support.
+ *
+ * @param binding the binding for which the interface contract is required
+ * @return the interface contract
+ */
+ InterfaceContract getInterfaceContract(Binding binding);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultAssemblyFactory.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultAssemblyFactory.java
new file mode 100644
index 0000000000..5dd256e3c4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultAssemblyFactory.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly;
+
+import org.apache.tuscany.sca.assembly.impl.AssemblyFactoryImpl;
+
+/**
+ * A factory for the assembly model.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultAssemblyFactory extends AssemblyFactoryImpl implements AssemblyFactory {
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultEndpointFactory.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultEndpointFactory.java
new file mode 100644
index 0000000000..6b0c076ee5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/DefaultEndpointFactory.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly;
+
+
+import org.apache.tuscany.sca.assembly.impl.EndpointFactoryImpl;
+
+/**
+ * A default factory for the Endpoint model.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultEndpointFactory extends EndpointFactoryImpl {
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint.java
new file mode 100644
index 0000000000..ee63497fbe
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Endpoint.java
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+
+/**
+ * Represents an endpoint (primarily a combination of a target service name and a set of
+ * candidate bindings)
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Endpoint extends Base, Cloneable {
+
+ /**
+ * Get the name of the target service that this endpoint refers to
+ *
+ * @return target service name
+ */
+ String getTargetName();
+
+ /**
+ * Set the name of the target service that this endpoint refers to
+ *
+ * @param targetName
+ */
+ void setTargetName(String targetName);
+
+ /**
+ * Get the source component model object
+ *
+ * @return source component
+ */
+ Component getSourceComponent();
+
+ /**
+ * Set the source component model object
+ *
+ * @param component the source component for the endpoint
+ */
+ void setSourceComponent(Component component);
+
+ /**
+ * Get the source component reference model object
+ *
+ * @return reference the source component reference for the endpoint
+ */
+ ComponentReference getSourceComponentReference();
+
+ /**
+ * Set the source component reference model object
+ *
+ * @param reference
+ */
+ void setSourceComponentReference(ComponentReference reference);
+
+ /**
+ * Get the resolved source binding
+ *
+ * @return binding the resolved source binding
+ */
+ Binding getSourceBinding();
+
+ /**
+ * Set the resolved source binding
+ *
+ * @param binding the resolved source binding
+ */
+ void setSourceBinding(Binding binding);
+
+ /**
+ * Get the resolved source callback binding
+ *
+ * @return binding the resolved source callback binding
+ */
+ Binding getSourceCallbackBinding();
+
+ /**
+ * Set the resolved source callback binding
+ *
+ * @param binding the resolved source callback binding
+ */
+ void setSourceCallbackBinding(Binding binding);
+
+ /**
+ * Get the list of candidate bindings that could be used to
+ * communication with the target service
+ *
+ * @return list of candidate bindings
+ */
+ List<Binding> getCandidateBindings();
+
+
+ /**
+ * Get the target component model object
+ *
+ * @return target component
+ */
+ Component getTargetComponent();
+
+ /**
+ * Set the target component model object
+ *
+ * @param component target component
+ */
+ void setTargetComponent(Component component);
+
+ /**
+ * Get the target component service model object
+ *
+ * @return target component service
+ */
+ ComponentService getTargetComponentService();
+
+ /**
+ * Set the target component service model object
+ *
+ * @param service
+ */
+ void setTargetComponentService(ComponentService service);
+
+ /**
+ * Get the resolved target binding
+ *
+ * @return target binding
+ */
+ Binding getTargetBinding();
+
+ /**
+ * Set the resolved target binding
+ *
+ * @param binding target binding
+ */
+ void setTargetBinding(Binding binding);
+
+ /**
+ * Returns the interface contract defining the interface
+ *
+ * @return the interface contract
+ */
+ InterfaceContract getInterfaceContract();
+
+ /**
+ * Sets the interface contract defining the interface
+ *
+ * @param interfaceContract the interface contract
+ */
+ void setInterfaceContract(InterfaceContract interfaceContract);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointFactory.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointFactory.java
new file mode 100644
index 0000000000..93e6c4d630
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/EndpointFactory.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+
+
+/**
+ * A factory for the endpoint model
+ *
+ * @version $Rev$ $Date$
+ */
+public interface EndpointFactory {
+
+ /**
+ * Create a new endpoint model object
+ *
+ * @return a new endpoint
+ */
+ Endpoint createEndpoint();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extensible.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extensible.java
new file mode 100644
index 0000000000..3577a94d1e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Extensible.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+import java.util.List;
+
+/**
+ * Base interface for extensible assembly model objects.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Extensible {
+
+ /**
+ * Returns a list of extension objects contained in this model object.
+ *
+ * @return a list of extension objects container in this model object
+ */
+ List<Object> getExtensions();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Implementation.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Implementation.java
new file mode 100644
index 0000000000..720a6801a2
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Implementation.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+/**
+ * Represents a component implementation.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Implementation extends ComponentType {
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Multiplicity.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Multiplicity.java
new file mode 100644
index 0000000000..5d15ce9938
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Multiplicity.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+/**
+ * Enumeration for multiplicity. Defines the number of wires that can connect a
+ * reference to target services.
+ *
+ * @version $Rev$ $Date$
+ */
+public enum Multiplicity {
+
+ /**
+ * Zero or one wire can have the reference as a source.
+ */
+ ZERO_ONE,
+
+ /**
+ * The default setting, one wire can have the reference as a source.
+ */
+ ONE_ONE,
+
+ /**
+ * Zero or more wires can have the reference as a source.
+ */
+ ZERO_N,
+
+ /**
+ * One or more wires can have the reference as a source.
+ */
+ ONE_N
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OperationsConfigurator.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OperationsConfigurator.java
new file mode 100644
index 0000000000..947fcd4c7c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OperationsConfigurator.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly;
+
+import java.util.List;
+
+/**
+ * Interface to be implemented by SCA artifacts that support configuration of 'operation' child
+ * elements for policies etc.
+ *
+ * @version $Rev$ $Date$
+ */
+
+public interface OperationsConfigurator {
+ List<ConfiguredOperation> getConfiguredOperations();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OptimizableBinding.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OptimizableBinding.java
new file mode 100644
index 0000000000..98ff92f15b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/OptimizableBinding.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+/**
+ * Represent a reference binding that supports optimized SCA local wiring between component
+ * references and services
+ *
+ * @version $Rev$ $Date$
+ *
+ */
+public interface OptimizableBinding extends Binding, Cloneable {
+
+ /**
+ * @param component
+ */
+ void setTargetComponent(Component component);
+
+ /**
+ * @param service
+ */
+ void setTargetComponentService(ComponentService service);
+
+ /**
+ * @param binding
+ */
+ void setTargetBinding(Binding binding);
+
+ /**
+ * @return
+ */
+ Binding getTargetBinding();
+
+ /**
+ * @return
+ */
+ Component getTargetComponent();
+
+ /**
+ * @return
+ */
+ ComponentService getTargetComponentService();
+
+ /**
+ * Clone the binding
+ * @return
+ */
+ Object clone() throws CloneNotSupportedException;
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Property.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Property.java
new file mode 100644
index 0000000000..683920da58
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Property.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+
+/**
+ * A property allows for the configuration of an implementation with externally
+ * set data values. An implementation can have zero or more properties. Each
+ * property has a data type, which may be either simple or complex. An
+ * implementation may also define a default value for a property.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Property extends AbstractProperty, PolicySetAttachPoint, Cloneable {
+
+ /**
+ * Returns a clone of the property.
+ *
+ * @return a clone of the property
+ * @throws CloneNotSupportedException
+ */
+ Object clone() throws CloneNotSupportedException;
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.java
new file mode 100644
index 0000000000..2eb1bf21b0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Reference.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+import java.util.List;
+
+/**
+ * Represents a reference. References within an implementation represent links
+ * to services that the implementation uses that must be provided by other
+ * components.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Reference extends AbstractReference, Contract {
+
+ /**
+ * Returns a boolean value, "false" by default, which indicates that the
+ * implementation wires this reference dynamically.
+ *
+ * @return true if the implementation wires this reference dynamically
+ */
+ boolean isWiredByImpl();
+
+ /**
+ * Sets a boolean value, "false" by default, which indicates that the
+ * implementation wires this reference dynamically.
+ *
+ * @param wiredByImpl whether the implementation wires this reference
+ * dynamically
+ */
+ void setWiredByImpl(boolean wiredByImpl);
+
+ /**
+ * Returns a boolean value, "false" by default, which indicates whether
+ * the configuration of this reference is a promotion override for
+ * another more deeply nested reference.
+ *
+ * @return true if the reference is a promotion override
+ */
+ boolean isPromotionOverride();
+
+ /**
+ * Sets a boolean value, "false" by default, which indicates whether
+ * the configuration of this reference is a promotion override for
+ * another more deeply nested reference.
+ *
+ * @param promotionOverride whether the reference is a promotion override
+ */
+ void setPromotionOverride(boolean promotionOverride);
+
+ /**
+ * Returns the targets of this reference.
+ *
+ * @return the targets of this reference.
+ */
+ List<ComponentService> getTargets();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABinding.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABinding.java
new file mode 100644
index 0000000000..2cf04277cd
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABinding.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+/**
+ * Represents an SCA binding.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface SCABinding extends Binding {
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABindingFactory.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABindingFactory.java
new file mode 100644
index 0000000000..0abfd13d10
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/SCABindingFactory.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+
+/**
+ * A factory for the SCA binding model
+ *
+ * @version $Rev$ $Date$
+ */
+public interface SCABindingFactory {
+
+ /**
+ * Create a new SCA binding.
+ *
+ * @return a new SCA binding
+ */
+ SCABinding createSCABinding();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Service.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Service.java
new file mode 100644
index 0000000000..020870cd34
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Service.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+/**
+ * Represents a service. Services are used to publish services provided by
+ * implementations, so that they are addressable by other components.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Service extends AbstractService, Contract {
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Wire.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Wire.java
new file mode 100644
index 0000000000..ee65e5746e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/Wire.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+import org.apache.tuscany.sca.policy.IntentAttachPoint;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+
+/**
+ * Represents a wire.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Wire extends Base, Extensible, IntentAttachPoint, PolicySetAttachPoint, Cloneable {
+
+ /**
+ * Returns the source of the wire.
+ *
+ * @return the source of the wire
+ */
+ ComponentReference getSource();
+
+ /**
+ * Sets the source of the wire.
+ *
+ * @param source the source of the wire
+ */
+ void setSource(ComponentReference source);
+
+ /**
+ * Returns the target of the wire.
+ *
+ * @return the target of the wire
+ */
+ ComponentService getTarget();
+
+ /**
+ * Sets the target of the wire.
+ *
+ * @param target the target of the wire
+ */
+ void setTarget(ComponentService target);
+
+ /**
+ * Returns a clone of the wire.
+ *
+ * @return a clone of the wire
+ * @throws CloneNotSupportedException
+ */
+ Object clone() throws CloneNotSupportedException;
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/AutomaticBinding.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/AutomaticBinding.java
new file mode 100644
index 0000000000..97708f9ef5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/AutomaticBinding.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly.builder;
+
+/**
+ * Represent a binding that has been added automatically to the model rather
+ * than being specified by the user through the composite file
+ *
+ * @version $Rev$ $Date$
+ *
+ */
+public interface AutomaticBinding extends Cloneable {
+
+ /**
+ * @param isAutomatic
+ */
+ void setIsAutomatic(boolean isAutomatic);
+
+ /**
+ * @return isAutomatic
+ */
+ boolean getIsAutomatic();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilder.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilder.java
new file mode 100644
index 0000000000..7bac630d5b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilder.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder;
+
+import org.apache.tuscany.sca.assembly.AbstractContract;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/**
+ * A builder that handles any build-time configuration needed by bindings.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface BindingBuilder {
+
+ /**
+ * Configure a binding.
+ *
+ * @param component The component for the binding's service or reference
+ * @param contract The binding's service or reference
+ */
+ void build(Component component, AbstractContract contract, Binding binding, Monitor monitor);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilderExtension.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilderExtension.java
new file mode 100644
index 0000000000..37ad8af0b3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/BindingBuilderExtension.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder;
+
+/**
+ * An extension that can be implemented by bindings to provide a binding builder.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface BindingBuilderExtension {
+
+ /**
+ * Returns the binding builder.
+ *
+ * @return the binding builder
+ */
+ BindingBuilder getBuilder();
+
+ /**
+ * Sets the binding builder.
+ *
+ * @param builder the binding builder
+ */
+ void setBuilder(BindingBuilder builder);
+
+}
+
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ComponentPreProcessor.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ComponentPreProcessor.java
new file mode 100644
index 0000000000..d2fae4d24a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/ComponentPreProcessor.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder;
+
+import org.apache.tuscany.sca.assembly.Component;
+
+/**
+ * Interface for Component Pre Processors.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ComponentPreProcessor {
+
+ void preProcess(Component component);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilder.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilder.java
new file mode 100644
index 0000000000..cf38894702
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilder.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder;
+
+import org.apache.tuscany.sca.assembly.Composite;
+
+/**
+ * A builder that handles the configuration of the components inside a
+ * composite and the wiring of component references to component services.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface CompositeBuilder {
+
+ /**
+ * Build a composite.
+ *
+ * @param composite
+ * @throws CompositeBuilderException
+ */
+ void build(Composite composite) throws CompositeBuilderException;
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderException.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderException.java
new file mode 100644
index 0000000000..5a2015f55e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/CompositeBuilderException.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder;
+
+/**
+ * Reports a composite builder exception.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeBuilderException extends Exception {
+ private static final long serialVersionUID = -8916323176803443856L;
+
+ public CompositeBuilderException() {
+ }
+
+ public CompositeBuilderException(String message) {
+ super(message);
+ }
+
+ public CompositeBuilderException(Throwable cause) {
+ super(cause);
+ }
+
+ public CompositeBuilderException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultEndpointBuilder.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultEndpointBuilder.java
new file mode 100644
index 0000000000..9743117174
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DefaultEndpointBuilder.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder;
+
+import org.apache.tuscany.sca.assembly.builder.impl.EndpointBuilderImpl;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/**
+ * A default builder.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultEndpointBuilder extends EndpointBuilderImpl {
+ public DefaultEndpointBuilder (Monitor monitor){
+ super(monitor);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DomainBuilder.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DomainBuilder.java
new file mode 100644
index 0000000000..20a17e1bd0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/DomainBuilder.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Service;
+
+/**
+ * A builder that handles the configuration of the components inside a
+ * composite and the wiring of component references to component services.
+ *
+ * @version $Rev: 563358 $ $Date: 2007-08-07 01:26:27 +0100 (Tue, 07 Aug 2007) $
+ */
+public interface DomainBuilder {
+
+ /**
+ * Wire up the references and service in a domain returning a list
+ * of the composites that have changed
+ *
+ * @param domainLevelCompsite
+ * @return a list of change composites
+ * @throws CompositeBuilderException
+ */
+ List<Composite> wireDomain(Composite domainLevelComposite);
+
+ /**
+ * Locates the referenced service and updates the URI on the identified binding
+ *
+ * @param domainLevelComposite
+ * @param referenceName
+ * @param bindingClassName
+ * @param URI
+ */
+ void updateDomainLevelServiceURI(Composite domainLevelComposite, String referenceName, String bindingClassName, String URI);
+
+ /**
+ * Get the component name out of the reference name that might look like Component/Service
+ *
+ * @param referenceName
+ * @return
+ */
+ String getComponentNameFromReference(String referenceName);
+
+ /**
+ * Get the service name out of the reference name that might look like Component/Service
+ *
+ * @param referenceName
+ * @return
+ */
+ String getServiceNameFromReference(String referenceName);
+
+ /**
+ * Find the service object given a reference name
+ *
+ * @param composite
+ * @param referenceName
+ * @return
+ */
+ Service findServiceForReference(Composite composite, String referenceName);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/EndpointBuilder.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/EndpointBuilder.java
new file mode 100644
index 0000000000..eb2977d87a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/EndpointBuilder.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder;
+
+import org.apache.tuscany.sca.assembly.Endpoint;
+
+/**
+ * A builder that handles the configuration of reference endpoints
+ * It collects together the logic so that it can be used at build time
+ * or later on during late binding scenarios
+ *
+ * @version $Rev$ $Date$
+ */
+public interface EndpointBuilder {
+
+ /**
+ * Build an endpoint.
+ *
+ * @param endpoint
+ */
+ void build(Endpoint endpoint);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java
new file mode 100644
index 0000000000..6f856986ad
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseConfigurationBuilderImpl.java
@@ -0,0 +1,1337 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.TransformerFactory;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentProperty;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Contract;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.builder.AutomaticBinding;
+import org.apache.tuscany.sca.assembly.builder.ComponentPreProcessor;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+import org.apache.tuscany.sca.policy.IntentAttachPoint;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+
+/**
+ * Base class for Builder implementations that handles configuration.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class BaseConfigurationBuilderImpl {
+ private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0";
+ private static final String BINDING_SCA = "binding.sca";
+ private static final QName BINDING_SCA_QNAME = new QName(SCA10_NS, BINDING_SCA);
+
+ private AssemblyFactory assemblyFactory;
+ private SCABindingFactory scaBindingFactory;
+ private Monitor monitor;
+ private InterfaceContractMapper interfaceContractMapper;
+ private SCADefinitions policyDefinitions;
+ private DocumentBuilderFactory documentBuilderFactory;
+ private TransformerFactory transformerFactory;
+
+ protected BaseConfigurationBuilderImpl(AssemblyFactory assemblyFactory,
+ SCABindingFactory scaBindingFactory,
+ DocumentBuilderFactory documentBuilderFactory,
+ TransformerFactory transformerFactory,
+ InterfaceContractMapper interfaceContractMapper,
+ SCADefinitions policyDefinitions,
+ Monitor monitor) {
+ this.assemblyFactory = assemblyFactory;
+ this.scaBindingFactory = scaBindingFactory;
+ this.documentBuilderFactory = documentBuilderFactory;
+ this.transformerFactory = transformerFactory;
+ this.interfaceContractMapper = interfaceContractMapper;
+ this.policyDefinitions = policyDefinitions;
+ this.monitor = monitor;
+ }
+
+ /**
+ * Configure components in the composite.
+ *
+ * @param composite
+ * @param problems
+ */
+ protected void configureComponents(Composite composite) throws CompositeBuilderException {
+ configureComponents(composite, null);
+ configureSourcedProperties(composite, null);
+ //configureBindingURIs(composite, null, null);
+ }
+
+ /**
+ * Configure components in the composite.
+ *
+ * @param composite
+ * @param uri
+ * @param problems
+ */
+ private void configureComponents(Composite composite, String uri) {
+ String parentURI = uri;
+
+ // Process nested composites recursively
+ for (Component component : composite.getComponents()) {
+
+ // Initialize component URI
+ String componentURI;
+ if (parentURI == null) {
+ componentURI = component.getName();
+ } else {
+ componentURI = URI.create(parentURI + '/').resolve(component.getName()).toString();
+ }
+ component.setURI(componentURI);
+
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+
+ // Process nested composite
+ configureComponents((Composite)implementation, componentURI);
+ }
+ }
+
+ // Initialize service bindings
+ List<Service> compositeServices = composite.getServices();
+ for (Service service : compositeServices) {
+ // Set default binding names
+
+ // Create default SCA binding
+ if (service.getBindings().isEmpty()) {
+ SCABinding scaBinding = createSCABinding();
+ service.getBindings().add(scaBinding);
+ }
+/*
+ // Initialize binding names and URIs
+ for (Binding binding : service.getBindings()) {
+
+ // Binding name defaults to the service name
+ if (binding.getName() == null) {
+ binding.setName(service.getName());
+ }
+ }
+
+ if (service.getCallback() != null) {
+ for (Binding binding : service.getCallback().getBindings()) {
+ if (binding.getName() == null) {
+ binding.setName(service.getName());
+ }
+ }
+ }
+*/
+ }
+
+ // Initialize reference bindings
+ for (Reference reference : composite.getReferences()) {
+ // Create default SCA binding
+ if (reference.getBindings().isEmpty()) {
+ SCABinding scaBinding = createSCABinding();
+ reference.getBindings().add(scaBinding);
+ }
+/*
+ // Set binding names
+ for (Binding binding : reference.getBindings()) {
+ if (binding.getName() == null) {
+ binding.setName(reference.getName());
+ }
+ }
+
+ if (reference.getCallback() != null) {
+ for (Binding binding : reference.getCallback().getBindings()) {
+ if (binding.getName() == null) {
+ binding.setName(reference.getName());
+ }
+ }
+ }
+*/
+ }
+
+ // Initialize all component services and references
+ Map<String, Component> components = new HashMap<String, Component>();
+ for (Component component : composite.getComponents()) {
+
+ // Index all components and check for duplicates
+ if (components.containsKey(component.getName())) {
+ error("DuplicateComponentName", component, composite.getName().toString(), component.getName());
+ } else {
+ components.put(component.getName(), component);
+ }
+
+ // Propagate the autowire flag from the composite to components
+ if (component.getAutowire() == null) {
+ component.setAutowire(composite.getAutowire());
+ }
+
+ if (component.getImplementation() instanceof ComponentPreProcessor) {
+ ((ComponentPreProcessor)component.getImplementation()).preProcess(component);
+ }
+
+ // Index properties, services and references
+ Map<String, Service> services = new HashMap<String, Service>();
+ Map<String, Reference> references = new HashMap<String, Reference>();
+ Map<String, Property> properties = new HashMap<String, Property>();
+ indexImplementationPropertiesServicesAndReferences(component,
+ services,
+ references,
+ properties);
+
+ // Index component services, references and properties
+ // Also check for duplicates
+ Map<String, ComponentService> componentServices =
+ new HashMap<String, ComponentService>();
+ Map<String, ComponentReference> componentReferences =
+ new HashMap<String, ComponentReference>();
+ Map<String, ComponentProperty> componentProperties =
+ new HashMap<String, ComponentProperty>();
+ indexComponentPropertiesServicesAndReferences(component,
+ componentServices,
+ componentReferences,
+ componentProperties);
+
+ // Reconcile component services/references/properties and
+ // implementation services/references and create component
+ // services/references/properties for the services/references
+ // declared by the implementation
+ reconcileServices(component, services, componentServices);
+ reconcileReferences(component, references, componentReferences);
+ reconcileProperties(component, properties, componentProperties);
+
+ // Configure or create callback services for component's references
+ // with callbacks
+ configureCallbackServices(component, componentServices);
+
+ // Configure or create callback references for component's services
+ // with callbacks
+ configureCallbackReferences(component, componentReferences);
+
+ // Create self references to the component's services
+// if (!(component.getImplementation() instanceof Composite)) {
+// createSelfReferences(component);
+// }
+
+ // Initialize service bindings
+ for (ComponentService componentService : component.getServices()) {
+
+ // Create default SCA binding
+ if (componentService.getBindings().isEmpty()) {
+ SCABinding scaBinding = createSCABinding();
+ componentService.getBindings().add(scaBinding);
+ }
+/*
+ // Set binding names
+ for (Binding binding : componentService.getBindings()) {
+
+ // Binding name defaults to the service name
+ if (binding.getName() == null) {
+ binding.setName(componentService.getName());
+ }
+ }
+ if (componentService.getCallback() != null) {
+ for (Binding binding : componentService.getCallback().getBindings()) {
+ if (binding.getName() == null) {
+ binding.setName(componentService.getName());
+ }
+ }
+ }
+*/
+ }
+
+ // Initialize reference bindings
+ for (ComponentReference componentReference : component.getReferences()) {
+
+ // Create default SCA binding
+ if (componentReference.getBindings().isEmpty()) {
+ SCABinding scaBinding = createSCABinding();
+ componentReference.getBindings().add(scaBinding);
+ }
+/*
+ // Set binding names
+ for (Binding binding : componentReference.getBindings()) {
+ if (binding.getName() == null) {
+ binding.setName(componentReference.getName());
+ }
+ }
+ if (componentReference.getCallback() != null) {
+ for (Binding binding : componentReference.getCallback().getBindings()) {
+ if (binding.getName() == null) {
+ binding.setName(componentReference.getName());
+ }
+ }
+ }
+*/
+ }
+ }
+ }
+
+ /**
+ * Report a warning.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void warning(String message, Object model, String... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "assembly-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, String... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "assembly-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Reconcile component properties and the properties defined by the
+ * component type.
+ *
+ * @param component
+ * @param properties
+ * @param componentProperties
+ * @param problems
+ */
+ private void reconcileProperties(Component component,
+ Map<String, Property> properties,
+ Map<String, ComponentProperty> componentProperties) {
+
+ // Connect component properties to their properties
+ for (ComponentProperty componentProperty : component.getProperties()) {
+ Property property = properties.get(componentProperty.getName());
+ if (property != null) {
+ componentProperty.setProperty(property);
+ } else {
+ warning("PropertyNotFound", component, component.getName(), componentProperty.getName());
+ }
+ }
+
+ // Create component properties for all properties
+ if (component.getImplementation() != null) {
+ for (Property property : component.getImplementation().getProperties()) {
+ if (!componentProperties.containsKey(property.getName())) {
+ ComponentProperty componentProperty = assemblyFactory.createComponentProperty();
+ componentProperty.setName(property.getName());
+ componentProperty.setMany(property.isMany());
+ componentProperty.setXSDElement(property.getXSDElement());
+ componentProperty.setXSDType(property.getXSDType());
+ componentProperty.setProperty(property);
+ component.getProperties().add(componentProperty);
+ }
+ }
+ }
+
+ // Reconcile component properties and their properties
+ for (ComponentProperty componentProperty : component.getProperties()) {
+ Property property = componentProperty.getProperty();
+ if (property != null) {
+
+ // Check that a component property does not override the
+ // mustSupply attribute
+ if (!property.isMustSupply() && componentProperty.isMustSupply()) {
+ warning("PropertyMustSupplyIncompatible", component, component.getName(), componentProperty.getName());
+ }
+
+ // Default to the mustSupply attribute specified on the property
+ if (!componentProperty.isMustSupply())
+ componentProperty.setMustSupply(property.isMustSupply());
+
+ // Default to the value specified on the property
+ if (componentProperty.getValue() == null) {
+ componentProperty.setValue(property.getValue());
+ }
+
+ // Override the property value for the composite
+ if(component.getImplementation() instanceof Composite) {
+ property.setValue(componentProperty.getValue());
+ }
+
+ // Check that a value is supplied
+ if (componentProperty.getValue() == null && property.isMustSupply()) {
+ warning("PropertyMustSupplyNull", component, component.getName(), componentProperty.getName());
+ }
+
+ // Check that a a component property does not override the
+ // many attribute
+ if (!property.isMany() && componentProperty.isMany()) {
+
+ warning("PropertyOverrideManyAttribute", component, component.getName(), componentProperty.getName());
+ }
+
+ // Default to the many attribute defined on the property
+ componentProperty.setMany(property.isMany());
+
+ // Default to the type and element defined on the property
+ if (componentProperty.getXSDType() == null) {
+ componentProperty.setXSDType(property.getXSDType());
+ }
+ if (componentProperty.getXSDElement() == null) {
+ componentProperty.setXSDElement(property.getXSDElement());
+ }
+
+ // Check that a type or element are specified
+ if (componentProperty.getXSDElement() == null && componentProperty.getXSDType() == null) {
+ warning("NoTypeForComponentProperty", component, component.getName(), componentProperty.getName());
+ }
+ }
+ }
+ }
+
+ /**
+ * Reconcile component references with the references defined on the
+ * component type.
+ *
+ * @param component
+ * @param references
+ * @param componentReferences
+ * @param problems
+ */
+ private void reconcileReferences(Component component,
+ Map<String, Reference> references,
+ Map<String, ComponentReference> componentReferences) {
+
+ // Connect each component reference to the corresponding reference
+ for (ComponentReference componentReference : component.getReferences()) {
+ if (componentReference.getReference() != null || componentReference.isCallback()) {
+ continue;
+ }
+ Reference reference = references.get(componentReference.getName());
+ if (reference != null) {
+ componentReference.setReference(reference);
+ } else {
+ if (!componentReference.getName().startsWith("$self$.")) {
+ error("ReferenceNotFound", component, component.getName(), componentReference.getName());
+ }
+ }
+ }
+
+ // Create a component reference for each reference
+ if (component.getImplementation() != null) {
+ for (Reference reference : component.getImplementation().getReferences()) {
+ if (!componentReferences.containsKey(reference.getName())) {
+ ComponentReference componentReference =
+ assemblyFactory.createComponentReference();
+ componentReference.setIsCallback(reference.isCallback());
+ componentReference.setName(reference.getName());
+ componentReference.setReference(reference);
+ component.getReferences().add(componentReference);
+ }
+ }
+ }
+
+ // Reconcile each component reference with its reference
+ for (ComponentReference componentReference : component.getReferences()) {
+ Reference reference = componentReference.getReference();
+ if (reference != null) {
+ // Reconcile multiplicity
+ if (componentReference.getMultiplicity() != null) {
+ if (!ReferenceConfigurationUtil.isValidMultiplicityOverride(reference.getMultiplicity(),
+ componentReference
+ .getMultiplicity())) {
+ warning("ReferenceIncompatibleMultiplicity", component, component.getName(), componentReference.getName());
+ }
+ } else {
+ componentReference.setMultiplicity(reference.getMultiplicity());
+ }
+
+ // Reconcile interface
+ InterfaceContract interfaceContract = reference.getInterfaceContract();
+ if (componentReference.getInterfaceContract() != null) {
+ if (interfaceContract != null && !componentReference.getInterfaceContract().equals(reference
+ .getInterfaceContract())) {
+ if (!interfaceContractMapper.isCompatible(componentReference.getInterfaceContract(),
+ interfaceContract)) {
+ warning("ReferenceIncompatibleComponentInterface", component, component.getName(), componentReference.getName());
+ }
+ }
+ } else {
+ componentReference.setInterfaceContract(interfaceContract);
+ }
+
+ // Reconcile bindings
+ if (componentReference.getBindings().isEmpty()) {
+ componentReference.getBindings().addAll(reference.getBindings());
+ }
+
+ // Reconcile callback bindings
+ if (componentReference.getCallback() == null) {
+ componentReference.setCallback(reference.getCallback());
+ if (componentReference.getCallback() == null) {
+ // Create an empty callback to avoid null check
+ componentReference.setCallback(assemblyFactory.createCallback());
+ }
+
+ } else if (componentReference.getCallback().getBindings().isEmpty() && reference
+ .getCallback() != null) {
+ componentReference.getCallback().getBindings().addAll(reference.getCallback()
+ .getBindings());
+ }
+
+ // Propagate autowire setting from the component
+ if (componentReference.getAutowire() == null) {
+ componentReference.setAutowire(component.getAutowire());
+ }
+
+ // Reconcile targets
+ if (componentReference.getTargets().isEmpty()) {
+ componentReference.getTargets().addAll(reference.getTargets());
+ }
+ }
+ }
+ }
+
+ /**
+ * Reconcile component services and services defined on the component type.
+ *
+ * @param component
+ * @param services
+ * @param componentServices
+ * @param problems
+ */
+ private void reconcileServices(Component component,
+ Map<String, Service> services,
+ Map<String, ComponentService> componentServices) {
+
+ // Connect each component service to the corresponding service
+ for (ComponentService componentService : component.getServices()) {
+ if (componentService.getService() != null || componentService.isCallback()) {
+ continue;
+ }
+ Service service = services.get(componentService.getName());
+ if (service != null) {
+ componentService.setService(service);
+ } else {
+ warning("ServiceNotFoundForComponentService", component, component.getName(), componentService.getName());
+ }
+ }
+
+ // Create a component service for each service
+ if (component.getImplementation() != null) {
+ for (Service service : component.getImplementation().getServices()) {
+ if (!componentServices.containsKey(service.getName())) {
+ ComponentService componentService = assemblyFactory.createComponentService();
+ componentService.setIsCallback(service.isCallback());
+ String name = service.getName();
+ componentService.setName(name);
+ componentService.setService(service);
+ component.getServices().add(componentService);
+ componentServices.put(name, componentService);
+ }
+ }
+ }
+
+ //Reconcile each component service with its service
+ for (ComponentService componentService : component.getServices()) {
+ Service service = componentService.getService();
+ if (service != null) {
+ // Reconcile interface
+ InterfaceContract interfaceContract = service.getInterfaceContract();
+ if (componentService.getInterfaceContract() != null) {
+ if (interfaceContract != null && !componentService.getInterfaceContract().equals(interfaceContract)) {
+ if (!interfaceContractMapper.isCompatible(componentService.getInterfaceContract(),
+ interfaceContract)) {
+ warning("ServiceIncompatibleComponentInterface", component, component.getName(), componentService.getName());
+ }
+ }
+ } else {
+ componentService.setInterfaceContract(interfaceContract);
+ }
+
+ // Reconcile bindings
+ if (componentService.getBindings().isEmpty()) {
+ componentService.getBindings().addAll(service.getBindings());
+ }
+
+ // Reconcile callback bindings
+ if (componentService.getCallback() == null) {
+ componentService.setCallback(service.getCallback());
+ if (componentService.getCallback() == null) {
+ // Create an empty callback to avoid null check
+ componentService.setCallback(assemblyFactory.createCallback());
+ }
+ } else if (componentService.getCallback().getBindings().isEmpty() && service
+ .getCallback() != null) {
+ componentService.getCallback().getBindings().addAll(service.getCallback()
+ .getBindings());
+ }
+ }
+ }
+ }
+
+ private void indexComponentPropertiesServicesAndReferences(Component component,
+ Map<String, ComponentService> componentServices,
+ Map<String, ComponentReference> componentReferences,
+ Map<String, ComponentProperty> componentProperties) {
+ for (ComponentService componentService : component.getServices()) {
+ if (componentServices.containsKey(componentService.getName())) {
+ warning("DuplicateComponentServiceName", component, component.getName(), componentService.getName());
+ } else {
+ componentServices.put(componentService.getName(), componentService);
+ }
+ }
+ for (ComponentReference componentReference : component.getReferences()) {
+ if (componentReferences.containsKey(componentReference.getName())) {
+ warning("DuplicateComponentReferenceName", component, component.getName(), componentReference.getName());
+ } else {
+ componentReferences.put(componentReference.getName(), componentReference);
+ }
+ }
+ for (ComponentProperty componentProperty : component.getProperties()) {
+ if (componentProperties.containsKey(componentProperty.getName())) {
+ warning("DuplicateComponentPropertyName", component, component.getName(), componentProperty.getName());
+ } else {
+ componentProperties.put(componentProperty.getName(), componentProperty);
+ }
+ }
+
+ }
+
+ private void indexImplementationPropertiesServicesAndReferences(Component component,
+ Map<String, Service> services,
+ Map<String, Reference> references,
+ Map<String, Property> properties) {
+ // First check that the component has a resolved implementation
+ Implementation implementation = component.getImplementation();
+ if (implementation == null) {
+ // A component must have an implementation
+ warning("NoComponentImplementation", component, component.getName());
+
+ } else if (implementation.isUnresolved()) {
+
+ // The implementation must be fully resolved
+ warning("UnresolvedComponentImplementation", component, component.getName(), implementation.getURI());
+
+ } else {
+
+ // Index properties, services and references, also check for
+ // duplicates
+ for (Property property : implementation.getProperties()) {
+ if (properties.containsKey(property.getName())) {
+ warning("DuplicateImplementationPropertyName", component, component.getName(), property.getName());
+ } else {
+ properties.put(property.getName(), property);
+ }
+ }
+ for (Service service : implementation.getServices()) {
+ if (services.containsKey(service.getName())) {
+ warning("DuplicateImplementationServiceName", component, component.getName(), service.getName());
+ } else {
+ services.put(service.getName(), service);
+ }
+ }
+ for (Reference reference : implementation.getReferences()) {
+ if (references.containsKey(reference.getName())) {
+ warning("DuplicateImplementationReferenceName", component, component.getName(), reference.getName());
+ } else {
+ references.put(reference.getName(), reference);
+ }
+ }
+ }
+
+ }
+
+ /**
+ * For all the references with callbacks, create a corresponding callback
+ * service.
+ *
+ * @param component
+ */
+ private void configureCallbackServices(Component component,
+ Map<String, ComponentService> componentServices) {
+ for (ComponentReference reference : component.getReferences()) {
+ if (reference.getInterfaceContract() != null && // can be null in
+ // unit tests
+ reference.getInterfaceContract().getCallbackInterface() != null) {
+ ComponentService service =
+ componentServices.get(reference.getName());
+ if (service == null) {
+ service = createCallbackService(component, reference);
+ }
+ if (reference.getCallback() != null) {
+ if (service.getBindings().isEmpty()) {
+ service.getBindings().addAll(reference.getCallback().getBindings());
+ }
+ }
+ reference.setCallbackService(service);
+ }
+ }
+ }
+
+ /**
+ * Create a callback service for a component reference
+ *
+ * @param component
+ * @param reference
+ */
+ private ComponentService createCallbackService(Component component, ComponentReference reference) {
+ ComponentService componentService = assemblyFactory.createComponentService();
+ componentService.setIsCallback(true);
+ componentService.setName(reference.getName());
+ try {
+ InterfaceContract contract =
+ (InterfaceContract)reference.getInterfaceContract().clone();
+ contract.setInterface(contract.getCallbackInterface());
+ contract.setCallbackInterface(null);
+ componentService.setInterfaceContract(contract);
+ } catch (CloneNotSupportedException e) {
+ // will not happen
+ }
+ Reference implReference = reference.getReference();
+ if (implReference != null) {
+ Service implService = assemblyFactory.createService();
+ implService.setName(implReference.getName());
+ try {
+ InterfaceContract implContract =
+ (InterfaceContract)implReference.getInterfaceContract().clone();
+ implContract.setInterface(implContract.getCallbackInterface());
+ implContract.setCallbackInterface(null);
+ implService.setInterfaceContract(implContract);
+ } catch (CloneNotSupportedException e) {
+ // will not happen
+ }
+ componentService.setService(implService);
+ }
+ component.getServices().add(componentService);
+ return componentService;
+ }
+
+ /**
+ * For all the services with callbacks, create a corresponding callback
+ * reference.
+ *
+ * @param component
+ */
+ private void configureCallbackReferences(Component component,
+ Map<String, ComponentReference> componentReferences) {
+ for (ComponentService service : component.getServices()) {
+ if (service.getInterfaceContract() != null && // can be null in
+ // unit tests
+ service.getInterfaceContract().getCallbackInterface() != null) {
+ ComponentReference reference =
+ componentReferences.get(service.getName());
+ if (reference == null) {
+ reference = createCallbackReference(component, service);
+ }
+ if (service.getCallback() != null) {
+ if (reference.getBindings().isEmpty()) {
+ reference.getBindings().addAll(service.getCallback().getBindings());
+ }
+ }
+ service.setCallbackReference(reference);
+ }
+ }
+ }
+
+ /**
+ * Create a callback reference for a component service
+ *
+ * @param component
+ * @param service
+ */
+ private ComponentReference createCallbackReference(Component component, ComponentService service) {
+ ComponentReference componentReference = assemblyFactory.createComponentReference();
+ componentReference.setIsCallback(true);
+ componentReference.setName(service.getName());
+ try {
+ InterfaceContract contract = (InterfaceContract)service.getInterfaceContract().clone();
+ contract.setInterface(contract.getCallbackInterface());
+ contract.setCallbackInterface(null);
+ componentReference.setInterfaceContract(contract);
+ } catch (CloneNotSupportedException e) {
+ // will not happen
+ }
+ Service implService = service.getService();
+ if (implService != null) {
+ Reference implReference = assemblyFactory.createReference();
+ implReference.setName(implService.getName());
+ try {
+ InterfaceContract implContract =
+ (InterfaceContract)implService.getInterfaceContract().clone();
+ implContract.setInterface(implContract.getCallbackInterface());
+ implContract.setCallbackInterface(null);
+ implReference.setInterfaceContract(implContract);
+ } catch (CloneNotSupportedException e) {
+ // will not happen
+ }
+ componentReference.setReference(implReference);
+ }
+ component.getReferences().add(componentReference);
+ return componentReference;
+ }
+
+ /**
+ * @param composite
+ */
+ private void configureSourcedProperties(Composite composite, List<ComponentProperty> propertySettings) {
+ // Resolve properties
+ Map<String, Property> compositeProperties = new HashMap<String, Property>();
+ ComponentProperty componentProperty = null;
+ for (Property p : composite.getProperties()) {
+ componentProperty = getComponentPropertyByName(p.getName(), propertySettings);
+ if (componentProperty != null) {
+ compositeProperties.put(p.getName(), componentProperty);
+ } else {
+ compositeProperties.put(p.getName(), p);
+ }
+ }
+
+ for (Component component : composite.getComponents()) {
+ try {
+ PropertyConfigurationUtil.sourceComponentProperties(compositeProperties, component,
+ documentBuilderFactory, transformerFactory);
+ } catch (Exception e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ Implementation impl = component.getImplementation();
+ if (impl instanceof Composite) {
+ configureSourcedProperties((Composite)impl, component.getProperties());
+ }
+ }
+ }
+
+ private ComponentProperty getComponentPropertyByName(String propertyName, List<ComponentProperty> properties) {
+ if (properties != null) {
+ for (ComponentProperty aProperty : properties) {
+ if (aProperty.getName().equals(propertyName)) {
+ return aProperty;
+ }
+ }
+ }
+ return null;
+ }
+
+ private SCABinding createSCABinding() {
+ SCABinding scaBinding = scaBindingFactory.createSCABinding();
+
+ // mark the bindings that are added automatically so that they can
+ // be disregarded for overriding purposes
+ if (scaBinding instanceof AutomaticBinding){
+ ((AutomaticBinding)scaBinding).setIsAutomatic(true);
+ }
+
+ if ( policyDefinitions != null ) {
+ for ( IntentAttachPointType attachPointType : policyDefinitions.getBindingTypes() ) {
+ if ( attachPointType.getName().equals(BINDING_SCA_QNAME)) {
+ ((IntentAttachPoint)scaBinding).setType(attachPointType);
+ }
+ }
+ }
+
+ return scaBinding;
+ }
+
+ /**
+ * Called by CompositeBindingURIBuilderImpl
+ *
+ * @param composite the composite to be configured
+ */
+ protected void configureBindingURIsAndNames(Composite composite) throws CompositeBuilderException {
+ configureBindingURIs(composite, null, null);
+ configureBindingNames(composite);
+ }
+
+ /**
+ * Fully resolve the binding URIs based on available information. This includes information
+ * from the ".composite" files, from resources associated with the binding, e.g. WSDL files,
+ * from any associated policies and from the default information for each binding type.
+ *
+ * @param composite the composite to be configured
+ * @param defaultBindings list of default binding configurations
+ */
+ protected void configureBindingURIs(Composite composite, List<Binding> defaultBindings) throws CompositeBuilderException {
+ configureBindingURIs(composite, null, defaultBindings);
+ }
+
+ /**
+ * Fully resolve the binding URIs based on available information. This includes information
+ * from the ".composite" files, from resources associated with the binding, e.g. WSDL files,
+ * from any associated policies and from the default information for each binding type.
+ *
+ * NOTE: This method repeats some of the processing performed by the configureComponents()
+ * method above. The duplication is needed because NodeConfigurationServiceImpl
+ * calls this method without previously calling configureComponents(). In the
+ * normal builder sequence used by CompositeBuilderImpl, both of these methods
+ * are called.
+ *
+ * TODO: Share the URL calculation algorithm with the configureComponents() method above
+ * although keeping the configureComponents() methods signature as is because when
+ * a composite is actually build in a node the node default information is currently
+ * available
+ *
+ * @param composite the composite to be configured
+ * @param uri the path to the composite provided through any nested composite component implementations
+ * @param defaultBindings list of default binding configurations
+ */
+ private void configureBindingURIs(Composite composite, String uri, List<Binding> defaultBindings) throws CompositeBuilderException {
+
+ String parentComponentURI = uri;
+
+ // Process nested composites recursively
+ for (Component component : composite.getComponents()) {
+
+ // Initialize component URI
+ String componentURI;
+ if (parentComponentURI == null) {
+ componentURI = component.getName();
+ } else {
+ componentURI = URI.create(parentComponentURI + '/').resolve(component.getName()).toString();
+ }
+ component.setURI(componentURI);
+
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+
+ // Process nested composite
+ configureBindingURIs((Composite)implementation, componentURI, defaultBindings);
+ }
+ }
+
+ // Initialize composite service binding URIs
+ List<Service> compositeServices = composite.getServices();
+ for (Service service : compositeServices) {
+ // Set default binding names
+
+ // Create default SCA binding
+ if (service.getBindings().isEmpty()) {
+ SCABinding scaBinding = createSCABinding();
+ service.getBindings().add(scaBinding);
+ }
+
+ // Initialize binding names and URIs
+ for (Binding binding : service.getBindings()) {
+ constructBindingName(service, binding);
+ constructBindingURI(parentComponentURI, composite, service, binding, defaultBindings);
+ }
+ }
+
+ // Initialize component service binding URIs
+ for (Component component : composite.getComponents()) {
+
+ // Index properties, services and references
+ Map<String, Service> services = new HashMap<String, Service>();
+ Map<String, Reference> references = new HashMap<String, Reference>();
+ Map<String, Property> properties = new HashMap<String, Property>();
+ indexImplementationPropertiesServicesAndReferences(component,
+ services,
+ references,
+ properties);
+
+ // Index component services, references and properties
+ // Also check for duplicates
+ Map<String, ComponentService> componentServices =
+ new HashMap<String, ComponentService>();
+ Map<String, ComponentReference> componentReferences =
+ new HashMap<String, ComponentReference>();
+ Map<String, ComponentProperty> componentProperties =
+ new HashMap<String, ComponentProperty>();
+ indexComponentPropertiesServicesAndReferences(component,
+ componentServices,
+ componentReferences,
+ componentProperties);
+
+ // Reconcile component services/references/properties and
+ // implementation services/references and create component
+ // services/references/properties for the services/references
+ // declared by the implementation
+ reconcileServices(component, services, componentServices);
+ reconcileReferences(component, references, componentReferences);
+ reconcileProperties(component, properties, componentProperties);
+
+ for (ComponentService service : component.getServices()) {
+
+ // Create default SCA binding
+ if (service.getBindings().isEmpty()) {
+ SCABinding scaBinding = createSCABinding();
+ service.getBindings().add(scaBinding);
+ }
+
+ // Initialize binding names and URIs
+ for (Binding binding : service.getBindings()) {
+
+ constructBindingName(service, binding);
+ constructBindingURI(component, service, binding, defaultBindings);
+ }
+ }
+ }
+ }
+
+ /**
+ * Add default names for callback bindings and reference bindings. Needs to be
+ * separate from configureBindingURIs() because configureBindingURIs() is called
+ * by NodeConfigurationServiceImpl as well as by CompositeBuilderImpl.
+ */
+ private void configureBindingNames(Composite composite) {
+
+ // Process nested composites recursively
+ for (Component component : composite.getComponents()) {
+
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+
+ // Process nested composite
+ configureBindingNames((Composite)implementation);
+ }
+ }
+
+ // Initialize composite service callback binding names
+ for (Service service : composite.getServices()) {
+
+ if (service.getCallback() != null) {
+ for (Binding binding : service.getCallback().getBindings()) {
+ constructBindingName(service, binding);
+ }
+ }
+ }
+
+ // Initialize composite reference binding names
+ for (Reference reference : composite.getReferences()) {
+
+ for (Binding binding : reference.getBindings()) {
+ constructBindingName(reference, binding);
+ }
+
+ if (reference.getCallback() != null) {
+ for (Binding binding : reference.getCallback().getBindings()) {
+ constructBindingName(reference, binding);
+ }
+ }
+ }
+
+ // Initialize component service and reference binding names
+ for (Component component : composite.getComponents()) {
+
+ // Initialize component service callback binding names
+ for (ComponentService service : component.getServices()) {
+
+ if (service.getCallback() != null) {
+ for (Binding binding : service.getCallback().getBindings()) {
+ constructBindingName(service, binding);
+ }
+ }
+ }
+
+ // Initialize component reference binding names
+ for (ComponentReference reference : component.getReferences()) {
+
+ // Initialize binding names
+ for (Binding binding : reference.getBindings()) {
+ constructBindingName(reference, binding);
+ }
+
+ if (reference.getCallback() != null) {
+ for (Binding binding : reference.getCallback().getBindings()) {
+ constructBindingName(reference, binding);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * If a binding name is not provided by the user, construct it based on the service
+ * or reference name
+ *
+ * @param contract the service or reference
+ * @param binding
+ */
+ private void constructBindingName(Contract contract, Binding binding) {
+
+ // set the default binding name if one is required
+ // if there is no name on the binding then set it to the service or reference name
+ if (binding.getName() == null){
+ binding.setName(contract.getName());
+ }
+
+ // Check that multiple bindings do not have the same name
+ for (Binding otherBinding : contract.getBindings()) {
+ if (otherBinding == binding) {
+ // Skip the current binding
+ continue;
+ }
+ if (binding.getClass() != otherBinding.getClass()) {
+ // Look for a binding of the same type
+ continue;
+ }
+ if (binding.getName().equals(otherBinding.getName())) {
+ warning(contract instanceof Service ? "MultipleBindingsForService" : "MultipleBindingsForReference",
+ binding, contract.getName(), binding.getName());
+ }
+ }
+ }
+
+ /**
+ * URI construction for composite bindings based on Assembly Specification section 1.7.2, This method
+ * assumes that the component URI part of the binding URI is formed from the part to the
+ * composite in question and just calls the generic constructBindingURI method with this
+ * information
+ *
+ * @param parentComponentURI
+ * @param composite
+ * @param service
+ * @param binding
+ * @param defaultBindings
+ */
+ private void constructBindingURI(String parentComponentURI, Composite composite, Service service, Binding binding, List<Binding> defaultBindings)
+ throws CompositeBuilderException{
+ // This is a composite service so there is no component to provide a component URI
+ // The path to this composite (through nested composites) is used.
+ boolean includeBindingName = composite.getServices().size() != 1;
+ constructBindingURI(parentComponentURI, service, binding, includeBindingName, defaultBindings);
+ }
+
+ /**
+ * URI construction for component bindings based on Assembly Specification section 1.7.2. This method
+ * calculates the component URI part based on component information before calling the generic
+ * constructBindingURI method
+ *
+ * @param component the component that holds the service
+ * @param service the service that holds the binding
+ * @param binding the binding for which the URI is being constructed
+ * @param defaultBindings the list of default binding configurations
+ */
+ private void constructBindingURI(Component component, Service service, Binding binding, List<Binding> defaultBindings)
+ throws CompositeBuilderException{
+ boolean includeBindingName = component.getServices().size() != 1;
+ constructBindingURI(component.getURI(), service, binding, includeBindingName, defaultBindings);
+ }
+
+ /**
+ * Generic URI construction for bindings based on Assembly Specification section 1.7.2
+ *
+ * @param componentURIString the string version of the URI part that comes from the component name
+ * @param service the service in question
+ * @param binding the binding for which the URI is being constructed
+ * @param includeBindingName when set true the serviceBindingURI part should be used
+ * @param defaultBindings the list of default binding configurations
+ * @throws CompositeBuilderException
+ */
+ private void constructBindingURI(String componentURIString, Service service, Binding binding, boolean includeBindingName, List<Binding> defaultBindings)
+ throws CompositeBuilderException{
+
+ try {
+ // calculate the service binding URI
+ URI bindingURI;
+ if (binding.getURI() != null){
+ bindingURI = new URI(binding.getURI());
+
+ // if the user has provided an absolute binding URI then use it
+ if (bindingURI.isAbsolute()){
+ binding.setURI(bindingURI.toString());
+ return;
+ }
+ } else {
+ bindingURI = null;
+ }
+
+ // Get the service binding name
+ URI bindingName;
+ if (binding.getName() != null) {
+ bindingName = new URI(binding.getName());
+ } else {
+ bindingName = new URI("");
+ }
+
+ // calculate the component URI
+ URI componentURI;
+ if (componentURIString != null) {
+ componentURI = new URI(addSlashToPath(componentURIString));
+ } else {
+ componentURI = null;
+ }
+
+ // if the user has provided an absolute component URI then use it
+ if (componentURI != null && componentURI.isAbsolute()){
+ binding.setURI(constructBindingURI(null, componentURI, bindingURI, includeBindingName, bindingName));
+ return;
+ }
+
+ // calculate the base URI
+
+ // get the protocol for this binding/URI
+/* some code that allows binding specific code to run. Being discussed on ML
+ BindingURICalculator uriCalculator = bindingURICalcualtorExtensionPoint.getBindingURICalculator(binding);
+
+ if (uriCalculator != null){
+ String protocol = uriCalculator.getProtocol(binding);
+
+ // find the default binding with the right protocol
+ Binding defaultBinding = nodeInfo.getBindingDefault(binding, protocol);
+
+ if (defaultBinding != null){
+ baseURI = new URI(defaultBinding.getURI());
+ } else {
+ baseURI = null;
+ }
+
+ } else {
+ baseURI = null;
+ }
+*/
+ // as a simpler alternative to the above commented out code.
+ URI baseURI = null;
+ if (defaultBindings != null) {
+ for (Binding defaultBinding : defaultBindings){
+ if (binding.getClass() == defaultBinding.getClass()){
+ baseURI = new URI(addSlashToPath(defaultBinding.getURI()));
+ break;
+ }
+ }
+ }
+
+ binding.setURI(constructBindingURI(baseURI, componentURI, bindingURI, includeBindingName, bindingName));
+ } catch (URISyntaxException ex) {
+ error("URLSyntaxException", binding, componentURIString, service.getName(), binding.getName());
+ }
+ }
+
+ /**
+ * Use to ensure that URI paths end in "/" as here we want to maintain the
+ * last path element of an base URI when other URI are resolved against it. This is
+ * not the default behaviour of URI resolution as defined in RFC 2369
+ *
+ * @param path the path string to which the "/" is to be added
+ * @return the resulting path with a "/" added if it not already there
+ */
+ private static String addSlashToPath(String path){
+ if (path.endsWith("/") || path.endsWith("#")){
+ return path;
+ } else {
+ return path + "/";
+ }
+ }
+
+ /**
+ * Concatenate binding URI parts together based on Assembly Specification section 1.7.2
+ *
+ * @param baseURI the base of the binding URI
+ * @param componentURI the middle part of the binding URI derived from the component name
+ * @param bindingURI the end part of the binding URI
+ * @param includeBindingName when set true the binding name part should be used
+ * @param bindingName the binding name
+ * @return the resulting URI as a string
+ */
+ private static String constructBindingURI(URI baseURI, URI componentURI, URI bindingURI, boolean includeBindingName, URI bindingName){
+ String uriString;
+
+ if (baseURI == null) {
+ if (componentURI == null){
+ if (bindingURI != null ) {
+ uriString = bindingURI.toString();
+ } else {
+ uriString = bindingName.toString();
+ }
+ } else {
+ if (bindingURI != null ) {
+ uriString = componentURI.resolve(bindingURI).toString();
+ } else {
+ if (includeBindingName) {
+ uriString = componentURI.resolve(bindingName).toString();
+ } else {
+ uriString = componentURI.toString();
+ }
+ }
+ }
+ } else {
+ if (componentURI == null) {
+ if (bindingURI != null ) {
+ uriString = basedURI(baseURI, bindingURI).toString();
+ } else {
+ if (includeBindingName) {
+ uriString = basedURI(baseURI, bindingName).toString();
+ } else {
+ uriString = baseURI.toString();
+ }
+ }
+ } else {
+ if (bindingURI != null ) {
+ uriString = basedURI(baseURI, componentURI.resolve(bindingURI)).toString();
+ } else {
+ if (includeBindingName) {
+ uriString = basedURI(baseURI, componentURI.resolve(bindingName)).toString();
+ } else {
+ uriString = basedURI(baseURI, componentURI).toString();
+ }
+ }
+ }
+ }
+
+ // tidy up by removing any trailing "/"
+ if (uriString.endsWith("/")){
+ uriString = uriString.substring(0, uriString.length()-1);
+ }
+
+ URI uri = URI.create(uriString);
+ if (!uri.isAbsolute()) {
+ uri = URI.create("/").resolve(uri);
+ }
+ return uri.toString();
+ }
+
+ /**
+ * Combine a URI with a base URI.
+ *
+ * @param baseURI
+ * @param uri
+ * @return
+ */
+ private static URI basedURI(URI baseURI, URI uri) {
+ if (uri.getScheme() != null) {
+ return uri;
+ }
+ String str = uri.toString();
+ if (str.startsWith("/")) {
+ str = str.substring(1);
+ }
+ return URI.create(baseURI.toString() + str).normalize();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java
new file mode 100644
index 0000000000..0c2d02ab48
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BaseWireBuilderImpl.java
@@ -0,0 +1,1149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeReference;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.ConfiguredOperation;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointFactory;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.Multiplicity;
+import org.apache.tuscany.sca.assembly.OperationsConfigurator;
+import org.apache.tuscany.sca.assembly.OptimizableBinding;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.Wire;
+import org.apache.tuscany.sca.assembly.builder.DefaultEndpointBuilder;
+import org.apache.tuscany.sca.assembly.builder.EndpointBuilder;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+import org.apache.tuscany.sca.policy.util.PolicyComputationUtils;
+
+/**
+ * A composite builder that handles wiring inside a composite.
+ *
+ * @version $Rev$ $Date$
+ */
+class BaseWireBuilderImpl {
+
+ private Monitor monitor;
+ private AssemblyFactory assemblyFactory;
+ private EndpointFactory endpointFactory;
+ private InterfaceContractMapper interfaceContractMapper;
+ private EndpointBuilder endpointBuilder;
+
+
+ protected BaseWireBuilderImpl(AssemblyFactory assemblyFactory, EndpointFactory endpointFactory, InterfaceContractMapper interfaceContractMapper, Monitor monitor) {
+ this.assemblyFactory = assemblyFactory;
+ this.endpointFactory = endpointFactory;
+ this.interfaceContractMapper = interfaceContractMapper;
+ this.monitor = monitor;
+ this.endpointBuilder = new DefaultEndpointBuilder(monitor);
+
+ }
+
+ /**
+ * Wire component references to component services and connect promoted
+ * services/references to component services/references inside a composite.
+ *
+ * @param composite
+ */
+ protected void wireComponentReferences(Composite composite) {
+
+ // Wire nested composites recursively
+ for (Component component : composite.getComponents()) {
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ wireComponentReferences((Composite)implementation);
+ }
+ }
+
+ // Index components, services and references
+ Map<String, Component> components = new HashMap<String, Component>();
+ Map<String, ComponentService> componentServices = new HashMap<String, ComponentService>();
+ Map<String, ComponentReference> componentReferences = new HashMap<String, ComponentReference>();
+ indexComponentsServicesAndReferences(composite, components, componentServices, componentReferences);
+
+ // Connect composite services and references to the component
+ // services and references that they promote
+ //connectCompositeServices(composite, components, componentServices);
+ //connectCompositeReferences(composite, componentReferences);
+
+ // Compute the policies before connecting component references
+ //computePolicies(composite);
+
+ // Connect component references as described in wires
+ connectWires(composite, componentServices, componentReferences);
+
+ // Connect component references to their targets
+ connectComponentReferences(composite, components, componentServices, componentReferences);
+
+ // Validate that references are wired or promoted, according
+ // to their multiplicity
+ for (ComponentReference componentReference : componentReferences.values()) {
+ if (!ReferenceConfigurationUtil.validateMultiplicityAndTargets(componentReference.getMultiplicity(), componentReference
+ .getTargets(), componentReference.getBindings())) {
+ if (componentReference.getTargets().isEmpty()) {
+
+ // No warning if the reference is promoted out of the current composite
+ boolean promoted = false;
+ for (Reference reference : composite.getReferences()) {
+ CompositeReference compositeReference = (CompositeReference)reference;
+ if (compositeReference.getPromotedReferences().contains(componentReference)) {
+ promoted = true;
+ break;
+ }
+ }
+ if (!promoted && !componentReference.isCallback()) {
+ warning("ReferenceWithoutTargets", composite, composite.getName().toString(), componentReference.getName());
+ }
+ } else {
+ warning("TooManyReferenceTargets", composite, componentReference.getName());
+ }
+ }
+ }
+
+ // Finally clear the original reference target lists as we now have
+ // bindings to represent the targets
+ for (ComponentReference componentReference : componentReferences.values()) {
+ componentReference.getTargets().clear();
+ }
+ }
+
+ /**
+ * Index components, services and references inside a composite.
+ * @param composite
+ * @param components
+ * @param componentServices
+ * @param componentReferences
+ */
+ private void indexComponentsServicesAndReferences(Composite composite,
+ Map<String, Component> components,
+ Map<String, ComponentService> componentServices,
+ Map<String, ComponentReference> componentReferences) {
+
+ for (Component component : composite.getComponents()) {
+
+ // Index components by name
+ components.put(component.getName(), component);
+
+ ComponentService nonCallbackService = null;
+ int nonCallbackServices = 0;
+ for (ComponentService componentService : component.getServices()) {
+
+ // Index component services by component name / service name
+ String uri = component.getName() + '/' + componentService.getName();
+ componentServices.put(uri, componentService);
+
+ boolean promotedService = false;
+ if (componentService.getName() != null && componentService.getName().indexOf("$promoted$") > -1) {
+ promotedService = true;
+ }
+
+ // count how many non-callback, non-promoted services there are
+ // if there is only one the component name also acts as the service name
+ if ((!componentService.isCallback()) && (!promotedService)) {
+
+ // Check how many non callback non-promoted services we have
+ if (nonCallbackServices == 0) {
+ nonCallbackService = componentService;
+ }
+ nonCallbackServices++;
+ }
+
+ }
+
+ if (nonCallbackServices == 1) {
+ // If we have a single non callback service, index it by
+ // component name as well
+ componentServices.put(component.getName(), nonCallbackService);
+ }
+
+ // Index references by component name / reference name
+ for (ComponentReference componentReference : component.getReferences()) {
+ String uri = component.getName() + '/' + componentReference.getName();
+ componentReferences.put(uri, componentReference);
+ }
+ }
+ }
+
+ /**
+ * Report a warning.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void warning(String message, Object model, String... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "assembly-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = null;
+ problem = new ProblemImpl(this.getClass().getName(), "assembly-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Connect composite references and services to the reference and services that they promote.
+ *
+ * @param composite
+ * @param componentServices
+ * @param problems
+ */
+ protected void connectCompositeReferencesAndServices(Composite composite){
+ // Wire nested composites recursively
+ for (Component component : composite.getComponents()) {
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ connectCompositeReferencesAndServices((Composite)implementation);
+ }
+ }
+
+ // Index components, services and references
+ Map<String, Component> components = new HashMap<String, Component>();
+ Map<String, ComponentService> componentServices = new HashMap<String, ComponentService>();
+ Map<String, ComponentReference> componentReferences = new HashMap<String, ComponentReference>();
+ indexComponentsServicesAndReferences(composite, components, componentServices, componentReferences);
+
+ // Connect composite services and references to the component
+ // services and references that they promote
+ connectCompositeServices(composite, components, componentServices);
+ connectCompositeReferences(composite, componentReferences);
+ }
+
+ /**
+ * Connect composite services to the component services that they promote.
+ *
+ * @param composite
+ * @param componentServices
+ * @param problems
+ */
+ private void connectCompositeServices(Composite composite,
+ Map<String, Component> components,
+ Map<String, ComponentService> componentServices) {
+
+ // Propagate interfaces from inner composite components' services to
+ // their component services
+ for (Component component : composite.getComponents()) {
+ if (component.getImplementation() instanceof Composite) {
+ for (ComponentService componentService : component.getServices()) {
+ Service service = componentService.getService();
+ if (service != null) {
+ if (componentService.getInterfaceContract() == null) {
+ componentService.setInterfaceContract(service.getInterfaceContract());
+ }
+ }
+ }
+ }
+ }
+
+ // Connect composite services to the component services that they
+ // promote
+ for (Service service : composite.getServices()) {
+ CompositeService compositeService = (CompositeService)service;
+ ComponentService componentService = compositeService.getPromotedService();
+ if (componentService != null && componentService.isUnresolved()) {
+
+ String promotedComponentName = compositeService.getPromotedComponent().getName();
+ String promotedServiceName;
+ if (componentService.getName() != null) {
+ promotedServiceName = promotedComponentName + '/' + componentService.getName();
+ } else {
+ promotedServiceName = promotedComponentName;
+ }
+ ComponentService promotedService = componentServices.get(promotedServiceName);
+ if (promotedService != null) {
+
+ // Point to the resolved component
+ Component promotedComponent = components.get(promotedComponentName);
+ compositeService.setPromotedComponent(promotedComponent);
+
+ // Point to the resolved component service
+ compositeService.setPromotedService(promotedService);
+
+ // Use the interface contract from the component service if
+ // none is specified on the composite service
+ InterfaceContract compositeServiceInterfaceContract = compositeService.getInterfaceContract();
+ InterfaceContract promotedServiceInterfaceContract = promotedService.getInterfaceContract();
+ if (compositeServiceInterfaceContract == null) {
+ compositeService.setInterfaceContract(promotedServiceInterfaceContract);
+ } else if (promotedServiceInterfaceContract != null) {
+ // Check the compositeServiceInterfaceContract and promotedServiceInterfaceContract
+ boolean isCompatible = interfaceContractMapper.isCompatible(compositeServiceInterfaceContract, promotedServiceInterfaceContract);
+ if(!isCompatible){
+ warning("ServiceInterfaceNotSubSet", compositeService, promotedServiceName);
+ }
+ }
+
+ } else {
+ warning("PromotedServiceNotFound", composite, composite.getName().toString(), promotedServiceName);
+ }
+ }
+ }
+
+ }
+
+ /**
+ * Resolves promoted references.
+ *
+ * @param composite
+ * @param componentReferences
+ * @param problems
+ */
+ private void connectCompositeReferences(Composite composite, Map<String, ComponentReference> componentReferences) {
+
+ // Propagate interfaces from inner composite components' references to
+ // their component references
+ for (Component component : composite.getComponents()) {
+ if (component.getImplementation() instanceof Composite) {
+ for (ComponentReference componentReference : component.getReferences()) {
+ Reference reference = componentReference.getReference();
+ if (reference != null) {
+ if (componentReference.getInterfaceContract() == null) {
+ componentReference.setInterfaceContract(reference.getInterfaceContract());
+ }
+ }
+ }
+ }
+ }
+
+ // Connect composite references to the component references
+ // that they promote
+ for (Reference reference : composite.getReferences()) {
+ CompositeReference compositeReference = (CompositeReference)reference;
+ List<ComponentReference> promotedReferences = compositeReference.getPromotedReferences();
+ for (int i = 0, n = promotedReferences.size(); i < n; i++) {
+ ComponentReference componentReference = promotedReferences.get(i);
+ if (componentReference.isUnresolved()) {
+ String componentReferenceName = componentReference.getName();
+ componentReference = componentReferences.get(componentReferenceName);
+ if (componentReference != null) {
+
+ // Point to the resolved component reference
+ promotedReferences.set(i, componentReference);
+
+ // Use the interface contract from the component
+ // reference if none
+ // is specified on the composite reference
+
+ InterfaceContract compositeReferenceInterfaceContract = compositeReference.getInterfaceContract();
+ InterfaceContract componentReferenceInterfaceContract = componentReference.getInterfaceContract();
+ if (compositeReferenceInterfaceContract == null) {
+ compositeReference.setInterfaceContract(componentReferenceInterfaceContract);
+ } else if (componentReferenceInterfaceContract != null) {
+ // Check the compositeInterfaceContract and componentInterfaceContract
+ boolean isCompatible = interfaceContractMapper.isCompatible(compositeReferenceInterfaceContract, componentReferenceInterfaceContract);
+ if (!isCompatible) {
+ warning("ReferenceInterfaceNotSubSet", compositeReference, componentReferenceName);
+ }
+ }
+ } else {
+ warning("PromotedReferenceNotFound", composite, composite.getName().toString(), componentReferenceName);
+ }
+ }
+ }
+ }
+ }
+
+ private List<Endpoint> createComponentReferenceTargets(Composite composite,
+ Map<String, Component> components,
+ Map<String, ComponentService> componentServices,
+ ComponentReference componentReference) {
+
+ List<Endpoint> endpoints = new ArrayList<Endpoint>();
+
+ if (componentReference.getAutowire() == Boolean.TRUE) {
+
+ // Find suitable targets in the current composite for an
+ // autowired reference
+ Multiplicity multiplicity = componentReference.getMultiplicity();
+ for (Component targetComponent : composite.getComponents()) {
+ // prevent autowire connecting to self
+ boolean skipSelf = false;
+ for (ComponentReference targetComponentReference : targetComponent.getReferences()) {
+ if (componentReference == targetComponentReference){
+ skipSelf = true;
+ }
+ }
+
+ if (!skipSelf){
+ for (ComponentService targetComponentService : targetComponent.getServices()) {
+ if (componentReference.getInterfaceContract() == null ||
+ interfaceContractMapper.isCompatible(componentReference.getInterfaceContract(), targetComponentService.getInterfaceContract())) {
+
+ Endpoint endpoint = endpointFactory.createEndpoint();
+ endpoint.setTargetName(targetComponent.getName());
+ endpoint.setSourceComponent(null); // TODO - fixed up at start
+ endpoint.setSourceComponentReference(componentReference);
+ endpoint.setInterfaceContract(componentReference.getInterfaceContract());
+ endpoint.setTargetComponent(targetComponent);
+ endpoint.setTargetComponentService(targetComponentService);
+ endpoint.getCandidateBindings().addAll(componentReference.getBindings());
+ endpoints.add(endpoint);
+
+ if (multiplicity == Multiplicity.ZERO_ONE || multiplicity == Multiplicity.ONE_ONE) {
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ if (multiplicity == Multiplicity.ONE_N || multiplicity == Multiplicity.ONE_ONE) {
+ if (endpoints.size() == 0) {
+ warning("NoComponentReferenceTarget", componentReference, componentReference.getName());
+ }
+ }
+
+ } else if (!componentReference.getTargets().isEmpty()) {
+
+ // Check if the component reference does not mix the use of endpoints specified via
+ // binding elements with target endpoints specified via the target attribute
+ for (Binding binding : componentReference.getBindings()) {
+ if (binding.getURI() != null) {
+ warning("ReferenceEndPointMixWithTarget", composite, componentReference.getName());
+ }
+ }
+
+ // Resolve targets specified on the component reference
+ for (ComponentService componentService : componentReference.getTargets()) {
+
+ // Resolve the target component and service
+ String name = componentService.getName();
+ ComponentService targetComponentService = componentServices.get(name);
+ Component targetComponent;
+ int s = name.indexOf('/');
+ if (s == -1) {
+ targetComponent = components.get(name);
+ } else {
+ targetComponent = components.get(name.substring(0, s));
+ }
+
+ if (targetComponentService != null) {
+
+ // Check that the target component service provides
+ // a superset of the component reference interface
+ if (componentReference.getInterfaceContract() == null ||
+ interfaceContractMapper.isCompatible(componentReference.getInterfaceContract(), targetComponentService.getInterfaceContract())) {
+
+ Endpoint endpoint = endpointFactory.createEndpoint();
+ endpoint.setTargetName(targetComponent.getName());
+ endpoint.setSourceComponent(null); // TODO - fixed up at start
+ endpoint.setSourceComponentReference(componentReference);
+ endpoint.setInterfaceContract(componentReference.getInterfaceContract());
+ endpoint.setTargetComponent(targetComponent);
+ endpoint.setTargetComponentService(targetComponentService);
+ endpoint.getCandidateBindings().addAll(componentReference.getBindings());
+ endpoints.add(endpoint);
+
+ // mark the reference target as resolved. Used later when we are looking to
+ // see if an sca binding is associated with a resolved target or not
+ componentService.setUnresolved(false);
+ } else {
+ warning("ReferenceIncompatibleInterface", composite, composite.getName().toString(),
+ componentReference.getName(), componentService.getName());
+ }
+ } else {
+ // add all the reference bindings into the target so that they
+ // can be used for comparison when the target is resolved at runtime
+ componentService.getBindings().addAll(componentReference.getBindings());
+
+ Endpoint endpoint = endpointFactory.createEndpoint();
+ endpoint.setTargetName(name);
+ endpoint.setSourceComponent(null); // TODO - fixed up at start
+ endpoint.setSourceComponentReference(componentReference);
+ endpoint.setInterfaceContract(componentReference.getInterfaceContract());
+ endpoint.getCandidateBindings().addAll(componentReference.getBindings());
+ endpoints.add(endpoint);
+
+ // The bindings will be cloned back into the reference when the
+ // target is finally resolved.
+ warning("ComponentReferenceTargetNotFound", composite,
+ composite.getName().toString(), componentService.getName());
+ }
+ }
+ } else if (componentReference.getReference() != null) {
+
+ // Resolve targets from the corresponding reference in the
+ // componentType
+ for (ComponentService componentService : componentReference.getReference().getTargets()) {
+
+ // Resolve the target component and service
+ String name = componentService.getName();
+ ComponentService targetComponentService = componentServices.get(name);
+ Component targetComponent;
+ int s = name.indexOf('/');
+ if (s == -1) {
+ targetComponent = components.get(name);
+ } else {
+ targetComponent = components.get(name.substring(0, s));
+ }
+
+ if (targetComponentService != null) {
+
+ // Check that the target component service provides
+ // a superset of
+ // the component reference interface
+ if (componentReference.getInterfaceContract() == null ||
+ interfaceContractMapper.isCompatible(componentReference.getInterfaceContract(), targetComponentService.getInterfaceContract())) {
+
+ Endpoint endpoint = endpointFactory.createEndpoint();
+ endpoint.setTargetName(targetComponent.getName());
+ endpoint.setSourceComponent(null); // TODO - fixed up at start
+ endpoint.setSourceComponentReference(componentReference);
+ endpoint.setInterfaceContract(componentReference.getInterfaceContract());
+ endpoint.setTargetComponent(targetComponent);
+ endpoint.setTargetComponentService(targetComponentService);
+ endpoint.getCandidateBindings().addAll(componentReference.getBindings());
+ endpoints.add(endpoint);
+
+ // mark the reference target as resolved. Used later when we are looking to
+ // see if an sca binding is associated with a resolved target or not
+ componentService.setUnresolved(false);
+ } else {
+ warning("ComponentIncompatibleInterface", composite,
+ componentReference.getName(), componentService.getName());
+ }
+ } else {
+ // add all the reference bindings into the target so that they
+ // can be used for comparison when the target is resolved at runtime
+ componentService.getBindings().addAll(componentReference.getBindings());
+
+ // The bindings will be cloned back into the reference when the
+ // target is finally resolved.
+
+ Endpoint endpoint = endpointFactory.createEndpoint();
+ endpoint.setTargetName(name);
+ endpoint.setSourceComponent(null); // TODO - fixed up at start
+ endpoint.setSourceComponentReference(componentReference);
+ endpoint.setInterfaceContract(componentReference.getInterfaceContract());
+ endpoint.getCandidateBindings().addAll(componentReference.getBindings());
+ endpoints.add(endpoint);
+
+ warning("ComponentReferenceTargetNotFound", composite,
+ composite.getName().toString(), componentService.getName());
+ }
+ }
+ }
+
+
+ // if no endpoints have found so far retrieve any target names that are in binding URIs
+ if (endpoints.isEmpty()){
+ for (Binding binding : componentReference.getBindings()) {
+
+ String uri = binding.getURI();
+
+ // user hasn't put a uri on the binding so it's not a target name
+ if (uri == null) {
+ continue;
+ }
+
+ // user might have put a local target name in the uri so get
+ // the path part and see if it refers to a target we know about
+ // - if it does the reference binding will be matched with a service binding
+ // - if it doesn't it is assumed to be an external reference
+ Component targetComponent = null;
+ ComponentService targetComponentService = null;
+ String path = null;
+
+ try {
+ path = URI.create(uri).getPath();
+ } catch(Exception ex){
+ // just assume that no target is identified if
+ // a URI related exception is thrown
+ }
+
+ if (path != null) {
+ if (path.startsWith("/")) {
+ path = path.substring(1);
+ }
+
+ // Resolve the target component and service
+ targetComponentService = componentServices.get(path);
+ int s = path.indexOf('/');
+ if (s == -1) {
+ targetComponent = components.get(path);
+ } else {
+ targetComponent = components.get(path.substring(0, s));
+ }
+ }
+
+ // if the path of the binding URI matches a component in the
+ // composite then configure an endpoint with this component as the target
+ // if not then the binding URI will be assumed to reference an external service
+ if (targetComponentService != null) {
+
+ // Check that the target component service provides
+ // a superset of the component reference interface
+ if (componentReference.getInterfaceContract() == null ||
+ interfaceContractMapper.isCompatible(componentReference.getInterfaceContract(), targetComponentService.getInterfaceContract())) {
+
+ Endpoint endpoint = endpointFactory.createEndpoint();
+ endpoint.setTargetName(targetComponent.getName());
+ endpoint.setSourceComponent(null); // TODO - fixed up at start
+ endpoint.setSourceComponentReference(componentReference);
+ endpoint.setInterfaceContract(componentReference.getInterfaceContract());
+ endpoint.setTargetComponent(targetComponent);
+ endpoint.setTargetComponentService(targetComponentService);
+ endpoint.getCandidateBindings().add(binding);
+ endpoints.add(endpoint);
+ } else {
+ warning("ReferenceIncompatibleInterface",
+ composite,
+ composite.getName().toString(),
+ componentReference.getName(),
+ uri);
+ }
+ } else {
+
+ // create endpoints for manually configured bindings
+ Endpoint endpoint = endpointFactory.createEndpoint();
+ endpoint.setTargetName(uri);
+ endpoint.setSourceComponent(null); // TODO - fixed up at start
+ endpoint.setSourceComponentReference(componentReference);
+ endpoint.setInterfaceContract(componentReference.getInterfaceContract());
+ endpoint.setSourceBinding(binding);
+ endpoints.add(endpoint);
+ }
+ }
+ }
+
+ return endpoints;
+ }
+
+
+ /**
+ * Connect references to their targets.
+ *
+ * @param composite
+ * @param componentServices
+ * @param componentReferences
+ * @param problems
+ */
+ private void connectComponentReferences(Composite composite,
+ Map<String, Component> components,
+ Map<String, ComponentService> componentServices,
+ Map<String, ComponentReference> componentReferences){
+
+ for (ComponentReference componentReference : componentReferences.values()) {
+
+ List<Endpoint> endpoints = createComponentReferenceTargets(composite,
+ components,
+ componentServices,
+ componentReference);
+
+ componentReference.getEndpoints().addAll(endpoints);
+
+ // the result of calculating the endpoints is either that bindings have been
+ // configured manually using a URI or that targets have been provided and the
+ // endpoint remains unresolved. So all endpoints should be either resved or uresolved.
+ boolean endpointsRequireAutomaticResolution = false;
+ for(Endpoint endpoint : endpoints){
+ endpointsRequireAutomaticResolution = endpoint.isUnresolved();
+ }
+
+ // build each endpoint
+ if (endpointsRequireAutomaticResolution) {
+
+ for(Endpoint endpoint : endpoints){
+ endpointBuilder.build(endpoint);
+ }
+
+ // TODO - The following step ensures that the reference binding list remains
+ // as the record of resolved targets for now. This needs fixing so
+ // that the endpoint takes on this responsibility.
+ componentReference.getBindings().clear();
+
+ if (componentReference.getCallback() != null){
+ componentReference.getCallback().getBindings().clear();
+ }
+
+ for(Endpoint endpoint : endpoints){
+ if (endpoint.isUnresolved() == false){
+ componentReference.getBindings().add(endpoint.getSourceBinding());
+
+ if (componentReference.getCallback() != null){
+ componentReference.getCallback().getBindings().add(endpoint.getSourceCallbackBinding());
+ }
+ }
+ }
+
+ } else {
+ // do nothing as no targets have been specified so the bindings
+ // in the reference binding list are assumed to be manually configured
+ }
+
+
+/*
+ // Select the reference bindings matching the target service bindings
+ List<Binding> selectedBindings = new ArrayList<Binding>();
+ List<Binding> selectedCallbackBindings = null;
+
+ // Handle callback
+ boolean bidirectional = false;
+
+ if (componentReference.getInterfaceContract() != null && componentReference.getInterfaceContract().getCallbackInterface() != null) {
+ bidirectional = true;
+ selectedCallbackBindings = new ArrayList<Binding>();
+ }
+
+ for (Target target : targets) {
+
+ Component targetComponent = target.getComponent();
+ ComponentService targetComponentService = target.getService();
+ if (targetComponentService.getService() instanceof CompositeService) {
+ CompositeService compositeService = (CompositeService) targetComponentService.getService();
+ // Find the promoted component service
+ targetComponentService = ServiceConfigurationUtil.getPromotedComponentService(compositeService);
+ }
+
+ try {
+ PolicyConfigurationUtil.determineApplicableBindingPolicySets(componentReference, targetComponentService);
+ } catch ( Exception e ) {
+ warning("Policy related exception: " + e, e);
+ //throw new RuntimeException(e);
+ }
+
+ // Match the binding against the bindings of the target service
+ Binding selected = BindingConfigurationUtil.resolveBindings(componentReference, targetComponent, targetComponentService);
+ if (selected == null) {
+ warning("NoMatchingBinding", componentReference, componentReference.getName(), targetComponentService.getName());
+ } else {
+ selectedBindings.add(selected);
+ }
+ if (bidirectional) {
+ Binding selectedCallback = BindingConfigurationUtil.resolveCallbackBindings(componentReference, targetComponent, targetComponentService);
+ if (selectedCallback != null) {
+ selectedCallbackBindings.add(selectedCallback);
+ }
+ }
+ }
+*/
+
+ // Need to tidy up the reference binding list and add in the bindings that
+ // have been selected above. The situation so far...
+ // Wired reference (1 or more targets are specified)
+ // Binding.uri = null - remove as it's left over from target resolution
+ // the binding will have been moved to the target from where
+ // it will be resolved later
+ // Binding.uri != null - the selected and resolved reference binding
+ // Unwired reference (0 targets)
+ // Binding.uri = null - Either a callback reference or the reference is yet to be wired
+ // by the implementation so leave the binding where it is
+ // Binding.uri != null - from the composite file so leave it
+/*
+ if ((componentReference.getTargets().size() > 0) ||
+ (!targets.isEmpty())) {
+
+ // Add all the effective bindings
+ componentReference.getBindings().clear();
+ componentReference.getBindings().addAll(selectedBindings);
+ if (bidirectional) {
+ componentReference.getCallback().getBindings().clear();
+ componentReference.getCallback().getBindings().addAll(selectedCallbackBindings);
+ }
+
+ // add in sca bindings to represent all unresolved targets. The sca binding
+ // will try to resolve the target at a later date.
+ for (ComponentService service : componentReference.getTargets()) {
+ if (service.isUnresolved()) {
+ SCABinding scaBinding = null;
+
+ // find the sca binding amongst the candidate binding list. We want to
+ // find this one and clone it as it may have been configured with
+ // policies
+ for (Binding binding : service.getBindings()) {
+
+ if (binding instanceof SCABinding) {
+ try {
+ scaBinding = (SCABinding)((OptimizableBinding)binding).clone();
+ } catch (CloneNotSupportedException ex){
+ // we know it is supported on the SCA binding
+ }
+ break;
+ }
+ }
+
+ if (scaBinding != null) {
+ // configure the cloned SCA binding for this reference target
+ scaBinding.setName(service.getName());
+
+ // this service object holds the list of candidate bindings which
+ // can be used for later matching
+ ((OptimizableBinding)scaBinding).setTargetComponentService(service);
+ componentReference.getBindings().add(scaBinding);
+ } else {
+ // not sure we need to raise a warning here as a warning will already been
+ // thrown previously to indicate the reason why there is no sca binding
+ // warning("NoSCABindingAvailableForUnresolvedService", componentReference, componentReference.getName(), service.getName());
+ }
+ }
+ }
+ }
+
+*/
+ // Connect the optimizable bindings to their target component and
+ // service
+/*
+ for (Binding binding : componentReference.getBindings()) {
+ if (!(binding instanceof OptimizableBinding)) {
+ continue;
+ }
+ OptimizableBinding optimizableBinding = (OptimizableBinding)binding;
+ if (optimizableBinding.getTargetComponentService() != null) {
+ continue;
+ }
+ String uri = optimizableBinding.getURI();
+ if (uri == null) {
+ continue;
+ }
+ uri = URI.create(uri).getPath();
+ if (uri.startsWith("/")) {
+ uri = uri.substring(1);
+ }
+
+ // Resolve the target component and service
+ ComponentService targetComponentService = componentServices.get(uri);
+ Component targetComponent;
+ int s = uri.indexOf('/');
+ if (s == -1) {
+ targetComponent = components.get(uri);
+ } else {
+ targetComponent = components.get(uri.substring(0, s));
+ }
+
+ if (targetComponentService != null) {
+
+ // Check that the target component service provides
+ // a superset of the component reference interface
+ if (componentReference.getInterfaceContract() == null ||
+ interfaceContractMapper.isCompatible(componentReference.getInterfaceContract(), targetComponentService.getInterfaceContract())) {
+
+ } else {
+ warning("ReferenceIncompatibleInterface",
+ composite,
+ composite.getName().toString(),
+ componentReference.getName(),
+ uri);
+ }
+ optimizableBinding.setTargetComponent(targetComponent);
+ optimizableBinding.setTargetComponentService(targetComponentService);
+ optimizableBinding.setTargetBinding(targetComponentService.getBinding(optimizableBinding.getClass()));
+ }
+ }
+*/
+ }
+ }
+
+ /**
+ * Resolve wires and connect the sources to their targets
+ *
+ * @param composite
+ * @param componentServices
+ * @param componentReferences
+ * @param problems
+ */
+ private void connectWires(Composite composite,
+ Map<String, ComponentService> componentServices,
+ Map<String, ComponentReference> componentReferences) {
+
+ // For each wire, resolve the source reference, the target service, and
+ // add it to the list of targets of the reference
+ List<Wire> wires = composite.getWires();
+ for (int i = 0, n = wires.size(); i < n; i++) {
+ Wire wire = wires.get(i);
+
+ ComponentReference resolvedReference;
+ ComponentService resolvedService;
+
+ // Resolve the source reference
+ ComponentReference source = wire.getSource();
+ if (source != null && source.isUnresolved()) {
+ resolvedReference = componentReferences.get(source.getName());
+ if (resolvedReference != null) {
+ wire.setSource(resolvedReference);
+ } else {
+ warning("WireSourceNotFound", composite, source.getName());
+ }
+ } else {
+ resolvedReference = wire.getSource();
+ }
+
+ // Resolve the target service
+ ComponentService target = wire.getTarget();
+ if (target != null && target.isUnresolved()) {
+ resolvedService = componentServices.get(target.getName());
+ if (resolvedService != null) {
+ wire.setTarget(target);
+ } else {
+ warning("WireTargetNotFound", composite, source.getName());
+ }
+ } else {
+ resolvedService = wire.getTarget();
+ }
+
+ // Add the target service to the list of targets of the
+ // reference
+ if (resolvedReference != null && resolvedService != null) {
+ // Check that the target component service provides
+ // a superset of
+ // the component reference interface
+ if (resolvedReference.getInterfaceContract() == null || interfaceContractMapper
+ .isCompatible(resolvedReference.getInterfaceContract(), resolvedService.getInterfaceContract())) {
+
+ //resolvedReference.getTargets().add(resolvedService);
+ resolvedReference.getTargets().add(wire.getTarget());
+ } else {
+ warning("WireIncompatibleInterface", composite, source.getName(), target.getName());
+ }
+ }
+ }
+
+ // Clear the list of wires
+ composite.getWires().clear();
+ }
+
+ private void addPoliciesFromPromotedService(CompositeService compositeService) {
+ //inherit intents and policies from promoted service
+ PolicyComputationUtils.addInheritedIntents(compositeService.getPromotedService().getRequiredIntents(),
+ compositeService.getRequiredIntents());
+ PolicyComputationUtils.addInheritedPolicySets(compositeService.getPromotedService().getPolicySets(),
+ compositeService.getPolicySets(), true);
+ addInheritedOperationConfigurations(compositeService.getPromotedService(), compositeService);
+ }
+
+ private void addPoliciesFromPromotedReference(CompositeReference compositeReference) {
+ for ( Reference promotedReference : compositeReference.getPromotedReferences() ) {
+ PolicyComputationUtils.addInheritedIntents(promotedReference.getRequiredIntents(),
+ compositeReference.getRequiredIntents());
+
+ PolicyComputationUtils.addInheritedPolicySets(promotedReference.getPolicySets(),
+ compositeReference.getPolicySets(), true);
+ addInheritedOperationConfigurations(promotedReference, compositeReference);
+ }
+ }
+
+
+ protected void computePolicies(Composite composite) {
+
+ // compute policies recursively
+ for (Component component : composite.getComponents()) {
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ computePolicies((Composite)implementation);
+ }
+ }
+
+ for (Component component : composite.getComponents()) {
+
+ // Inherit default policies from the component to component-level contracts.
+ // This must be done BEFORE computing implementation policies because the
+ // implementation policy computer removes from the component any
+ // intents and policy sets that don't apply to implementations.
+ PolicyConfigurationUtil.inheritDefaultPolicies(component, component.getServices());
+ PolicyConfigurationUtil.inheritDefaultPolicies(component, component.getReferences());
+
+ Implementation implemenation = component.getImplementation();
+ try {
+ PolicyConfigurationUtil.computeImplementationIntentsAndPolicySets(implemenation, component);
+ } catch ( Exception e ) {
+ error("PolicyRelatedException", implemenation, e);
+ //throw new RuntimeException(e);
+ }
+
+ for (ComponentService componentService : component.getServices()) {
+ Service service = componentService.getService();
+ if (service != null) {
+ // reconcile intents and policysets from componentType
+ PolicyComputationUtils.addInheritedIntents(service.getRequiredIntents(), componentService.getRequiredIntents());
+ PolicyComputationUtils.addInheritedPolicySets(service.getPolicySets(), componentService.getPolicySets(), true);
+
+ //reconcile intents and policysets for operations
+ boolean notFound;
+ List<ConfiguredOperation> opsFromComponentType = new ArrayList<ConfiguredOperation>();
+ for ( ConfiguredOperation ctsConfOp : service.getConfiguredOperations() ) {
+ notFound = true;
+ for ( ConfiguredOperation csConfOp : componentService.getConfiguredOperations() ) {
+ if ( csConfOp.getName().equals(ctsConfOp.getName()) ) {
+ PolicyComputationUtils.addInheritedIntents(ctsConfOp.getRequiredIntents(), csConfOp.getRequiredIntents());
+ PolicyComputationUtils.addInheritedPolicySets(ctsConfOp.getPolicySets(), csConfOp.getPolicySets(), true);
+ notFound = false;
+ }
+ }
+
+ if ( notFound ) {
+ opsFromComponentType.add(ctsConfOp);
+ }
+ }
+ componentService.getConfiguredOperations().addAll(opsFromComponentType);
+ }
+
+ try {
+ //compute the intents for operations under service element
+ PolicyConfigurationUtil.computeIntentsForOperations(componentService);
+ //compute intents and policyset for each binding
+ //addInheritedOpConfOnBindings(componentService);
+ PolicyConfigurationUtil.computeBindingIntentsAndPolicySets(componentService);
+ PolicyConfigurationUtil.determineApplicableBindingPolicySets(componentService, null);
+
+ } catch ( Exception e ) {
+ error("PolicyRelatedException", componentService, e);
+ //throw new RuntimeException(e);
+ }
+ }
+
+ for (ComponentReference componentReference : component.getReferences()) {
+ Reference reference = componentReference.getReference();
+ if (reference != null) {
+ // reconcile intents and policysets
+ PolicyComputationUtils.addInheritedIntents(reference.getRequiredIntents(), componentReference.getRequiredIntents());
+ PolicyComputationUtils.addInheritedPolicySets(reference.getPolicySets(), componentReference.getPolicySets(), true);
+ }
+
+
+ try {
+ //compute the intents for operations under reference element
+ PolicyConfigurationUtil.computeIntentsForOperations(componentReference);
+ //compute intents and policyset for each binding
+ //addInheritedOpConfOnBindings(componentReference);
+ PolicyConfigurationUtil.computeBindingIntentsAndPolicySets(componentReference);
+ PolicyConfigurationUtil.determineApplicableBindingPolicySets(componentReference, null);
+
+
+ if ( componentReference.getCallback() != null ) {
+ PolicyComputationUtils.addInheritedIntents(componentReference.getRequiredIntents(),
+ componentReference.getCallback().getRequiredIntents());
+ PolicyComputationUtils.addInheritedPolicySets(componentReference.getPolicySets(),
+ componentReference.getCallback().getPolicySets(),
+ false);
+ }
+ } catch ( Exception e ) {
+ error("PolicyRelatedException", componentReference, e);
+ //throw new RuntimeException(e);
+ }
+ }
+ }
+
+ PolicyConfigurationUtil.inheritDefaultPolicies(composite, composite.getServices());
+ PolicyConfigurationUtil.inheritDefaultPolicies(composite, composite.getReferences());
+
+ //compute policies for composite service bindings
+ for (Service service : composite.getServices()) {
+ addPoliciesFromPromotedService((CompositeService)service);
+ try {
+ //compute the intents for operations under service element
+ PolicyConfigurationUtil.computeIntentsForOperations(service);
+ //add or merge service operations to the binding
+ //addInheritedOpConfOnBindings(service);
+ PolicyConfigurationUtil.computeBindingIntentsAndPolicySets(service);
+ PolicyConfigurationUtil.determineApplicableBindingPolicySets(service, null);
+ } catch ( Exception e ) {
+ error("PolicyRelatedException", service, e);
+ //throw new RuntimeException(e);
+ }
+
+ }
+
+ for (Reference reference : composite.getReferences()) {
+ CompositeReference compReference = (CompositeReference)reference;
+ addPoliciesFromPromotedReference(compReference);
+ try {
+ //compute the intents for operations under service element
+ PolicyConfigurationUtil.computeIntentsForOperations(reference);
+ //addInheritedOpConfOnBindings(reference);
+
+ if (compReference.getCallback() != null) {
+ PolicyComputationUtils.addInheritedIntents(compReference.getRequiredIntents(),
+ compReference.getCallback().getRequiredIntents());
+ PolicyComputationUtils.addInheritedPolicySets(compReference.getPolicySets(),
+ compReference.getCallback().getPolicySets(),
+ false);
+ }
+
+ PolicyConfigurationUtil.computeBindingIntentsAndPolicySets(reference);
+ PolicyConfigurationUtil.determineApplicableBindingPolicySets(reference, null);
+ } catch ( Exception e ) {
+ error("PolicyRelatedException", reference, e);
+ //throw new RuntimeException(e);
+ }
+ }
+
+ }
+
+ private void addInheritedOperationConfigurations(OperationsConfigurator source,
+ OperationsConfigurator target) {
+ boolean found = false;
+
+ List<ConfiguredOperation> additionalOperations = new ArrayList<ConfiguredOperation>();
+ for ( ConfiguredOperation sourceConfOp : source.getConfiguredOperations() ) {
+ for ( ConfiguredOperation targetConfOp : target.getConfiguredOperations() ) {
+ if ( sourceConfOp.getName().equals(targetConfOp.getName())) {
+ PolicyComputationUtils.addInheritedIntents(sourceConfOp.getRequiredIntents(),
+ targetConfOp.getRequiredIntents());
+ PolicyComputationUtils.addInheritedPolicySets(sourceConfOp.getPolicySets(),
+ targetConfOp.getPolicySets(), true);
+ found = true;
+ break;
+ }
+ }
+
+ if ( !found ) {
+ additionalOperations.add(sourceConfOp);
+ }
+ }
+
+ if ( !additionalOperations.isEmpty() ) {
+ target.getConfiguredOperations().addAll(additionalOperations);
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingConfigurationUtil.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingConfigurationUtil.java
new file mode 100644
index 0000000000..4016d02a36
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/BindingConfigurationUtil.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.assembly.builder.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.OptimizableBinding;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+
+/**
+ * This class encapsulates utility methods to deal with binding definitions
+ *
+ * @version $Rev$ $Date$
+ */
+abstract class BindingConfigurationUtil {
+ private static boolean hasCompatiblePolicySets(Binding refBinding, Binding svcBinding) {
+ boolean isCompatible = true;
+ if ( refBinding instanceof PolicySetAttachPoint && svcBinding instanceof PolicySetAttachPoint ) {
+ //TODO : need to add more compatibility checks at the policy attachment levels
+ for ( PolicySet svcPolicySet : ((PolicySetAttachPoint)svcBinding).getPolicySets() ) {
+ isCompatible = false;
+ for ( PolicySet refPolicySet : ((PolicySetAttachPoint)refBinding).getPolicySets() ) {
+ if ( svcPolicySet.equals(refPolicySet) ) {
+ isCompatible = true;
+ break;
+ }
+ }
+ //if there exists no matching policy set in the reference binding
+ if ( !isCompatible ) {
+ return isCompatible;
+ }
+ }
+ }
+ return isCompatible;
+ }
+
+
+ static Binding matchBinding(Component targetComponent, ComponentService targetComponentService, List<Binding> source, List<Binding> target) {
+ List<Binding> matched = new ArrayList<Binding>();
+ // Find the corresponding bindings from the service side
+ for (Binding binding : source) {
+ for (Binding serviceBinding : target) {
+ if (binding.getClass() == serviceBinding.getClass() &&
+ hasCompatiblePolicySets(binding, serviceBinding)) {
+
+ try {
+ Binding cloned = (Binding)binding.clone();
+
+ //Customise the binding name to make it unique
+ // regardless of how many bindings or targets there are
+ if ( targetComponent != null){
+ cloned.setName(binding.getName() + "#" + targetComponent.getName() + "/" + serviceBinding.getName());
+ } else {
+ cloned.setName(binding.getName() + "#" + serviceBinding.getName());
+ }
+
+ // Set the binding URI to the URI of the target service
+ // that has been matched
+ if (binding.getURI() == null) {
+ cloned.setURI(serviceBinding.getURI());
+ }
+
+ if (binding instanceof OptimizableBinding) {
+ OptimizableBinding endpoint = ((OptimizableBinding)cloned);
+ endpoint.setTargetComponent(targetComponent);
+ endpoint.setTargetComponentService(targetComponentService);
+ endpoint.setTargetBinding(serviceBinding);
+ }
+
+ matched.add(cloned);
+ break;
+ } catch (Exception ex) {
+ // do nothing
+ }
+ }
+ }
+ }
+ if (matched.isEmpty()) {
+ // No matching binding
+ return null;
+ } else {
+ for (Binding binding : matched) {
+ // If binding.sca is present, use it
+ if (SCABinding.class.isInstance(binding)) {
+ return binding;
+ }
+ }
+ // Use the first one
+ return matched.get(0);
+ }
+ }
+
+ /**
+ * Choose a binding for the reference based on the bindings available on the
+ * service
+ *
+ * @param reference The component reference
+ * @param service The component service
+ * @return Resolved binding
+ */
+ static Binding resolveBindings(ComponentReference reference, Component component, ComponentService service) {
+ List<Binding> source = reference.getBindings();
+ List<Binding> target = service.getBindings();
+
+ return matchBinding(component, service, source, target);
+
+ }
+
+
+ /**
+ * @param reference
+ * @param service
+ * @return
+ */
+ static Binding resolveCallbackBindings(ComponentReference reference, Component component, ComponentService service) {
+ List<Binding> source = reference.getCallback().getBindings();
+ List<Binding> target = service.getCallback().getBindings();
+
+ return matchBinding(component, service, source, target);
+ }
+
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentConfigurationBuilderImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentConfigurationBuilderImpl.java
new file mode 100644
index 0000000000..0643421a45
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentConfigurationBuilderImpl.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.TransformerFactory;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/**
+ * A composite builder that handles the configuration of components.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentConfigurationBuilderImpl extends BaseConfigurationBuilderImpl implements CompositeBuilder {
+
+ @Deprecated
+ public ComponentConfigurationBuilderImpl(AssemblyFactory assemblyFactory,
+ SCABindingFactory scaBindingFactory,
+ InterfaceContractMapper interfaceContractMapper,
+ SCADefinitions policyDefinitions,
+ Monitor monitor) {
+ super(assemblyFactory, scaBindingFactory,
+ null, null,
+ interfaceContractMapper, policyDefinitions, monitor);
+ }
+
+ public ComponentConfigurationBuilderImpl(AssemblyFactory assemblyFactory,
+ SCABindingFactory scaBindingFactory,
+ DocumentBuilderFactory documentBuilderFactory,
+ TransformerFactory transformerFactory,
+ InterfaceContractMapper interfaceContractMapper,
+ SCADefinitions policyDefinitions,
+ Monitor monitor) {
+ super(assemblyFactory, scaBindingFactory,
+ documentBuilderFactory, transformerFactory,
+ interfaceContractMapper, policyDefinitions, monitor);
+ }
+
+ public void build(Composite composite) throws CompositeBuilderException {
+ configureComponents(composite);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java
new file mode 100644
index 0000000000..4913705e91
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceBindingBuilderImpl.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.builder.BindingBuilderExtension;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/**
+ * A composite builder that performs any additional building steps that
+ * component reference bindings may need. Used for WSDL generation.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentReferenceBindingBuilderImpl implements CompositeBuilder {
+ private Monitor monitor;
+
+ public ComponentReferenceBindingBuilderImpl(Monitor monitor) {
+ this.monitor = monitor;
+ }
+
+ public void build(Composite composite) throws CompositeBuilderException {
+ buildReferenceBindings(composite);
+ }
+
+ private void buildReferenceBindings(Composite composite) {
+
+ // find all the component reference bindings (starting at top level)
+ for (Component component : composite.getComponents()) {
+ for (ComponentReference componentReference : component.getReferences()) {
+ for (Binding binding : componentReference.getBindings()) {
+ if (binding instanceof BindingBuilderExtension) {
+ ((BindingBuilderExtension)binding).getBuilder().build(component, componentReference, binding, monitor);
+ }
+ }
+ }
+ }
+
+ // build bindings recursively
+ for (Component component : composite.getComponents()) {
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ buildReferenceBindings((Composite)implementation);
+ }
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionWireBuilderImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionWireBuilderImpl.java
new file mode 100644
index 0000000000..c0702c87b3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferencePromotionWireBuilderImpl.java
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeReference;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.EndpointFactory;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.Multiplicity;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/**
+ * A composite builder that handles the creation of promoted composite services.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentReferencePromotionWireBuilderImpl implements CompositeBuilder {
+ private AssemblyFactory assemblyFactory;
+ private EndpointFactory endpointFactory;
+ private Monitor monitor;
+
+ public ComponentReferencePromotionWireBuilderImpl(AssemblyFactory assemblyFactory, EndpointFactory endpointFactory, Monitor monitor) {
+ this.assemblyFactory = assemblyFactory;
+ this.endpointFactory = endpointFactory;
+ this.monitor = monitor;
+ }
+
+ public void build(Composite composite) throws CompositeBuilderException {
+ wireCompositeReferences(composite);
+ }
+
+ /**
+ * Wire composite references in nested composites.
+ *
+ * @param composite
+ * @param problems
+ */
+ private void wireCompositeReferences(Composite composite) {
+
+ // Process nested composites recursively
+ for (Component component : composite.getComponents()) {
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ wireCompositeReferences((Composite)implementation);
+ }
+ }
+
+ // Process component references declared on components in this composite
+ for (Component component : composite.getComponents()) {
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ for (ComponentReference componentReference : component.getReferences()) {
+ Reference implReference = componentReference.getReference();
+ if (implReference != null && implReference instanceof CompositeReference) {
+
+ // If the component reference is wired, it is a promotion override
+ if (!componentReference.getEndpoints().isEmpty()) {
+ componentReference.setPromotionOverride(true);
+ }
+
+ // If the component reference is a promotion override, override the
+ // configuration of the promoted reference
+ if (componentReference.isPromotionOverride()) {
+ CompositeReference compositeReference = (CompositeReference)implReference;
+ List<ComponentReference> promotedReferences =
+ ReferenceConfigurationUtil.getPromotedComponentReferences(compositeReference);
+ for (ComponentReference promotedReference : promotedReferences) {
+ ReferenceConfigurationUtil.reconcileReferenceBindings(
+ componentReference, promotedReference, assemblyFactory, endpointFactory, monitor);
+ if (componentReference.getInterfaceContract() != null && // can be null in unit tests
+ componentReference.getInterfaceContract().getCallbackInterface() != null) {
+ SCABinding scaCallbackBinding = promotedReference.getCallbackBinding(SCABinding.class);
+ if (promotedReference.getCallback() != null) {
+ promotedReference.getCallback().getBindings().clear();
+ } else {
+ promotedReference.setCallback(assemblyFactory.createCallback());
+ }
+ if (scaCallbackBinding != null) {
+ promotedReference.getCallback().getBindings().add(scaCallbackBinding);
+ }
+ if (componentReference.getCallback() != null) {
+ promotedReference.getCallback().getBindings().addAll(componentReference
+ .getCallback().getBindings());
+ }
+ }
+
+ // Wire the promoted reference to the actual non-composite component services
+ if (promotedReference.getMultiplicity() == Multiplicity.ONE_ONE) {
+ // promotedReference.getTargets().clear();
+ }
+ for (ComponentService target : componentReference.getTargets()) {
+ if (target.getService() instanceof CompositeService) {
+
+ // Wire to the actual component service
+ // promoted by a composite service
+ CompositeService compositeService = (CompositeService)target.getService();
+ // Find the promoted component service
+ ComponentService componentService =
+ ServiceConfigurationUtil.getPromotedComponentService(compositeService);
+ if (componentService != null) {
+ promotedReference.getTargets().add(componentService);
+ }
+ } else {
+
+ // Wire to a non-composite target service
+ promotedReference.getTargets().add(target);
+ }
+ }
+ }
+ }
+ }
+ }
+ } else {
+ for (ComponentReference componentReference : component.getReferences()) {
+
+ // Wire the component reference to the actual
+ // non-composite component services
+ List<ComponentService> targets = componentReference.getTargets();
+ for (int i = 0, n = targets.size(); i < n; i++) {
+ ComponentService target = targets.get(i);
+ if (target.getService() instanceof CompositeService) {
+
+ // Wire to the actual component service
+ // promoted by a composite service
+ CompositeService compositeService = (CompositeService)target.getService();
+ ComponentService componentService = compositeService.getPromotedService();
+ if (componentService != null) {
+ targets.set(i, componentService);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java
new file mode 100644
index 0000000000..927330b139
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentReferenceWireBuilderImpl.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.EndpointFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/**
+ * A composite builder that wires component references.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentReferenceWireBuilderImpl extends BaseWireBuilderImpl implements CompositeBuilder {
+
+ public ComponentReferenceWireBuilderImpl(AssemblyFactory assemblyFactory, EndpointFactory endpointFactory, InterfaceContractMapper interfaceContractMapper, Monitor monitor) {
+ super(assemblyFactory, endpointFactory, interfaceContractMapper, monitor);
+ }
+
+ public void build(Composite composite) throws CompositeBuilderException {
+ wireComponentReferences(composite);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceBindingBuilderImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceBindingBuilderImpl.java
new file mode 100644
index 0000000000..12ea86eac3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServiceBindingBuilderImpl.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.builder.BindingBuilder;
+import org.apache.tuscany.sca.assembly.builder.BindingBuilderExtension;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/**
+ * A composite builder that performs any additional building steps that
+ * component service bindings may need. Used for WSDL generation.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentServiceBindingBuilderImpl implements CompositeBuilder {
+ private Monitor monitor;
+
+ public ComponentServiceBindingBuilderImpl(Monitor monitor) {
+ this.monitor = monitor;
+ }
+
+ public void build(Composite composite) throws CompositeBuilderException {
+ buildServiceBindings(composite);
+ }
+
+ private void buildServiceBindings(Composite composite) {
+
+ // build bindings recursively
+ for (Component component : composite.getComponents()) {
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ buildServiceBindings((Composite)implementation);
+ }
+ }
+
+ // find all the component service bindings
+ for (Component component : composite.getComponents()) {
+ for (ComponentService componentService : component.getServices()) {
+ for (Binding binding : componentService.getBindings()) {
+ if (binding instanceof BindingBuilderExtension) {
+ BindingBuilder builder = ((BindingBuilderExtension)binding).getBuilder();
+ if (builder != null) {
+ builder.build(component, componentService, binding, monitor);
+ }
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java
new file mode 100644
index 0000000000..d73286f7ab
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ComponentServicePromotionBuilderImpl.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+
+/**
+ * A composite builder that handles the creation of promoted services.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentServicePromotionBuilderImpl implements CompositeBuilder {
+ private AssemblyFactory assemblyFactory;
+
+ public ComponentServicePromotionBuilderImpl(AssemblyFactory assemblyFactory) {
+ this.assemblyFactory = assemblyFactory;
+ }
+
+ public void build(Composite composite) throws CompositeBuilderException {
+
+ // Process nested composites recursively
+ configureNestedCompositeServices(composite);
+ }
+
+ private void configureNestedCompositeServices(Composite composite) {
+
+ // Process nested composites recursively
+ for (Component component : composite.getComponents()) {
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+
+ // First process nested composites
+ configureNestedCompositeServices((Composite)implementation);
+
+ // Process the component services declared on components in this composite
+ for (ComponentService componentService : component.getServices()) {
+ Service implService = componentService.getService();
+ if (implService != null && implService instanceof CompositeService) {
+ CompositeService compositeService = (CompositeService)implService;
+
+ // Get the innermost promoted service
+ ComponentService promotedService =
+ ServiceConfigurationUtil.getPromotedComponentService(compositeService);
+ if (promotedService != null) {
+ Component promotedComponent = ServiceConfigurationUtil.getPromotedComponent(compositeService);
+
+ // Create a new component service to represent this
+ // component service on the promoted component
+ ComponentService newComponentService = assemblyFactory.createComponentService();
+ newComponentService.setName("$promoted$" + component.getName() + "$slash$" + componentService.getName());
+ promotedComponent.getServices().add(newComponentService);
+ newComponentService.setService(promotedService.getService());
+ newComponentService.getBindings().addAll(componentService.getBindings());
+ newComponentService.setInterfaceContract(componentService.getInterfaceContract());
+
+ if (componentService.getInterfaceContract() != null &&
+ componentService.getInterfaceContract().getCallbackInterface() != null) {
+ newComponentService.setCallback(assemblyFactory.createCallback());
+ newComponentService.getCallback().getBindings()
+ .addAll(componentService.getCallback().getBindings());
+ }
+
+ // Change the composite service to now promote the
+ // newly created component service directly
+ compositeService.setPromotedComponent(promotedComponent);
+ compositeService.setPromotedService(newComponentService);
+ }
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java
new file mode 100644
index 0000000000..85af173c0d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBindingURIBuilderImpl.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.TransformerFactory;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/**
+ * A composite builder that handles the configuration of binding URIs.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeBindingURIBuilderImpl extends BaseConfigurationBuilderImpl implements CompositeBuilder {
+
+ @Deprecated
+ public CompositeBindingURIBuilderImpl(AssemblyFactory assemblyFactory,
+ SCABindingFactory scaBindingFactory,
+ InterfaceContractMapper interfaceContractMapper,
+ SCADefinitions policyDefinitions,
+ Monitor monitor) {
+ super(assemblyFactory, scaBindingFactory,
+ null, null,
+ interfaceContractMapper, policyDefinitions, monitor);
+ }
+
+ public CompositeBindingURIBuilderImpl(AssemblyFactory assemblyFactory,
+ SCABindingFactory scaBindingFactory,
+ DocumentBuilderFactory documentBuilderFactory,
+ TransformerFactory transformerFactory,
+ InterfaceContractMapper interfaceContractMapper,
+ SCADefinitions policyDefinitions,
+ Monitor monitor) {
+ super(assemblyFactory, scaBindingFactory,
+ documentBuilderFactory, transformerFactory,
+ interfaceContractMapper, policyDefinitions, monitor);
+ }
+
+ public void build(Composite composite) throws CompositeBuilderException {
+ configureBindingURIsAndNames(composite);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.java
new file mode 100644
index 0000000000..282fe032ba
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderImpl.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.sca.assembly.builder.impl;
+
+import java.util.logging.Logger;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.TransformerFactory;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.DefaultEndpointFactory;
+import org.apache.tuscany.sca.assembly.EndpointFactory;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
+
+/**
+ * A builder that handles the configuration of the components inside a composite
+ * and the wiring of component references to component services.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeBuilderImpl implements CompositeBuilder {
+ private static final Logger logger = Logger.getLogger(CompositeBuilderImpl.class.getName());
+ private CompositeBuilder compositeIncludeBuilder;
+ private CompositeBuilder componentReferenceWireBuilder;
+ private CompositeBuilder componentReferencePromotionWireBuilder;
+ private CompositeBuilder compositeReferenceWireBuilder;
+ private CompositeBuilder compositeCloneBuilder;
+ private CompositeBuilder componentConfigurationBuilder;
+ private CompositeBuilder compositeServiceConfigurationBuilder;
+ private CompositeBuilder compositeReferenceConfigurationBuilder;
+ private CompositeBuilder compositeBindingURIBuilder;
+ private CompositeBuilder componentServicePromotionBuilder;
+ private CompositeBuilder compositeServicePromotionBuilder;
+ private CompositeBuilder compositePromotionBuilder;
+ private CompositeBuilder compositePolicyBuilder;
+ private CompositeBuilder componentServiceBindingBuilder;
+ private CompositeBuilder componentReferenceBindingBuilder;
+
+ /**
+ * Constructs a new composite builder.
+ *
+ * @param assemblyFactory
+ * @param scaBindingFactory
+ * @param endpointFactory
+ * @param intentAttachPointTypeFactory
+ * @param interfaceContractMapper
+ * @param policyDefinitions
+ * @param monitor
+ */
+ @Deprecated
+ public CompositeBuilderImpl(AssemblyFactory assemblyFactory,
+ EndpointFactory endpointFactory,
+ SCABindingFactory scaBindingFactory,
+ IntentAttachPointTypeFactory intentAttachPointTypeFactory,
+ InterfaceContractMapper interfaceContractMapper,
+ SCADefinitions policyDefinitions,
+ Monitor monitor) {
+ this(assemblyFactory, endpointFactory, scaBindingFactory, intentAttachPointTypeFactory,
+ null, null, interfaceContractMapper, policyDefinitions, monitor);
+ }
+
+ /**
+ * Constructs a new composite builder.
+ *
+ * @param assemblyFactory
+ * @param scaBindingFactory
+ * @param endpointFactory
+ * @param intentAttachPointTypeFactory
+ * @param interfaceContractMapper
+ * @param policyDefinitions
+ * @param monitor
+ */
+ @Deprecated
+ public CompositeBuilderImpl(AssemblyFactory assemblyFactory,
+ SCABindingFactory scaBindingFactory,
+ IntentAttachPointTypeFactory intentAttachPointTypeFactory,
+ InterfaceContractMapper interfaceContractMapper,
+ Monitor monitor) {
+ this(assemblyFactory, null, scaBindingFactory, intentAttachPointTypeFactory,
+ null, null, interfaceContractMapper, null, monitor);
+ }
+
+ /**
+ * Constructs a new composite builder.
+ *
+ * @param assemblyFactory
+ * @param scaBindingFactory
+ * @param intentAttachPointTypeFactory
+ * @param documentBuilderFactory
+ * @param transformerFactory
+ * @param interfaceContractMapper
+ * @param monitor
+ */
+ public CompositeBuilderImpl(AssemblyFactory assemblyFactory,
+ SCABindingFactory scaBindingFactory,
+ IntentAttachPointTypeFactory intentAttachPointTypeFactory,
+ DocumentBuilderFactory documentBuilderFactory,
+ TransformerFactory transformerFactory,
+ InterfaceContractMapper interfaceContractMapper,
+ Monitor monitor) {
+ this(assemblyFactory, null, scaBindingFactory, intentAttachPointTypeFactory,
+ documentBuilderFactory, transformerFactory, interfaceContractMapper, null, monitor);
+ }
+
+ /**
+ * Constructs a new composite builder.
+ *
+ * @param assemblyFactory
+ * @param scaBindingFactory
+ * @param endpointFactory
+ * @param intentAttachPointTypeFactory
+ * @param interfaceContractMapper
+ * @param policyDefinitions
+ * @param monitor
+ */
+ public CompositeBuilderImpl(AssemblyFactory assemblyFactory,
+ EndpointFactory endpointFactory,
+ SCABindingFactory scaBindingFactory,
+ IntentAttachPointTypeFactory intentAttachPointTypeFactory,
+ DocumentBuilderFactory documentBuilderFactory,
+ TransformerFactory transformerFactory,
+ InterfaceContractMapper interfaceContractMapper,
+ SCADefinitions policyDefinitions,
+ Monitor monitor) {
+
+ if (endpointFactory == null){
+ endpointFactory = new DefaultEndpointFactory();
+ }
+
+ compositeIncludeBuilder = new CompositeIncludeBuilderImpl(monitor);
+ componentReferenceWireBuilder = new ComponentReferenceWireBuilderImpl(assemblyFactory, endpointFactory, interfaceContractMapper, monitor);
+ componentReferencePromotionWireBuilder = new ComponentReferencePromotionWireBuilderImpl(assemblyFactory, endpointFactory, monitor);
+ compositeReferenceWireBuilder = new CompositeReferenceWireBuilderImpl(assemblyFactory, endpointFactory, monitor);
+ compositeCloneBuilder = new CompositeCloneBuilderImpl(monitor);
+ componentConfigurationBuilder = new ComponentConfigurationBuilderImpl(assemblyFactory, scaBindingFactory, documentBuilderFactory, transformerFactory, interfaceContractMapper, policyDefinitions, monitor);
+ compositeServiceConfigurationBuilder = new CompositeServiceConfigurationBuilderImpl(assemblyFactory);
+ compositeReferenceConfigurationBuilder = new CompositeReferenceConfigurationBuilderImpl(assemblyFactory);
+ compositeBindingURIBuilder = new CompositeBindingURIBuilderImpl(assemblyFactory, scaBindingFactory, documentBuilderFactory, transformerFactory, interfaceContractMapper, policyDefinitions, monitor);
+ componentServicePromotionBuilder = new ComponentServicePromotionBuilderImpl(assemblyFactory);
+ compositeServicePromotionBuilder = new CompositeServicePromotionBuilderImpl(assemblyFactory);
+ compositePromotionBuilder = new CompositePromotionBuilderImpl(assemblyFactory, endpointFactory, interfaceContractMapper, monitor);
+ compositePolicyBuilder = new CompositePolicyBuilderImpl(assemblyFactory, endpointFactory, interfaceContractMapper, monitor);
+ componentServiceBindingBuilder = new ComponentServiceBindingBuilderImpl(monitor);
+ componentReferenceBindingBuilder = new ComponentReferenceBindingBuilderImpl(monitor);
+ }
+
+ public void build(Composite composite) throws CompositeBuilderException {
+
+ // Collect and fuse includes
+ compositeIncludeBuilder.build(composite);
+
+ // Expand nested composites
+ compositeCloneBuilder.build(composite);
+
+ // Configure all components
+ componentConfigurationBuilder.build(composite);
+
+ // Connect composite services/references to promoted services/references
+ compositePromotionBuilder.build(composite);
+
+ // Compute the policies across the model hierarchy
+ compositePolicyBuilder.build(composite);
+
+ // Configure composite services
+ compositeServiceConfigurationBuilder.build(composite);
+
+ // Configure composite references
+ compositeReferenceConfigurationBuilder.build(composite);
+
+ // Configure binding URIs
+ compositeBindingURIBuilder.build(composite);
+
+ // Create promoted component services
+ componentServicePromotionBuilder.build(composite);
+
+ // Create promoted composite services
+ compositeServicePromotionBuilder.build(composite);
+
+ // Build component service binding-related information
+ componentServiceBindingBuilder.build(composite);
+
+ // Wire the components
+ componentReferenceWireBuilder.build(composite);
+
+ // Wire the promoted component references
+ componentReferencePromotionWireBuilder.build(composite);
+
+ // Wire the composite references
+ compositeReferenceWireBuilder.build(composite);
+
+ // Build component reference binding-related information
+ componentReferenceBindingBuilder.build(composite);
+
+ // Fuse nested composites
+ //FIXME do this later
+ //cloneBuilder.fuseCompositeImplementations(composite);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeCloneBuilderImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeCloneBuilderImpl.java
new file mode 100644
index 0000000000..5779ddbc78
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeCloneBuilderImpl.java
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/**
+ * A composite builder that clones nested composites.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeCloneBuilderImpl implements CompositeBuilder {
+
+ public CompositeCloneBuilderImpl(Monitor monitor) {
+ }
+
+ public void build(Composite composite) throws CompositeBuilderException {
+ expandCompositeImplementations(composite);
+ }
+
+ /**
+ * Expand composite component implementations.
+ *
+ * @param composite
+ * @param problems
+ */
+ private void expandCompositeImplementations(Composite composite) {
+ for (Component component : composite.getComponents()) {
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+
+ Composite compositeImplementation = (Composite)implementation;
+ Composite clone;
+ try {
+ clone = (Composite)compositeImplementation.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeException(e);
+ }
+ component.setImplementation(clone);
+ expandCompositeImplementations(clone);
+ }
+ }
+ }
+
+ /**
+ * Collect all nested composite implementations in a graph of composites.
+ *
+ * @param composite
+ * @param nested
+ */
+ private void collectNestedComposites(Composite composite, List<Composite> nested) {
+ for (Component component : composite.getComponents()) {
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ Composite nestedComposite = (Composite)implementation;
+ nested.add(nestedComposite);
+ collectNestedComposites(nestedComposite, nested);
+ }
+ }
+ }
+
+ /**
+ * Fuse nested composites into a top level composite.
+ *
+ * @param composite
+ */
+ private void fuseCompositeImplementations(Composite composite) {
+
+ // First collect all nested composites
+ List<Composite> nested = new ArrayList<Composite>();
+ collectNestedComposites(composite, nested);
+
+ // Then add all the non-composite components they contain
+ for (Composite nestedComposite : nested) {
+ for (Component component: nestedComposite.getComponents()) {
+ Implementation implementation = component.getImplementation();
+ if (!(implementation instanceof Composite)) {
+ composite.getComponents().add(component);
+ }
+ }
+ }
+
+ // Clear the initial list of composite components
+ for (Iterator<Component> i = composite.getComponents().iterator(); i.hasNext();) {
+ Component component = i.next();
+ if (component.getImplementation() instanceof Composite) {
+ i.remove();
+ }
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java
new file mode 100644
index 0000000000..539ad8d137
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeIncludeBuilderImpl.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ * Implementation of a CompositeBuilder.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeIncludeBuilderImpl implements CompositeBuilder {
+
+ private Monitor monitor;
+
+ public CompositeIncludeBuilderImpl(Monitor monitor) {
+ this.monitor = monitor;
+ }
+
+ public void build(Composite composite) throws CompositeBuilderException {
+ fuseIncludes(composite);
+ }
+
+ private void warning(String message, Object model, String... messageParameters) {
+ if (monitor != null){
+ Problem problem = new ProblemImpl(this.getClass().getName(), "assembly-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Collect all includes in a graph of includes.
+ *
+ * @param composite
+ * @param includes
+ */
+ private void collectIncludes(Composite composite, List<Composite> includes, Set<Composite> visited) {
+ for (Composite include : composite.getIncludes()) {
+ if (visited.contains(include)) {
+ warning("CompositeAlreadyIncluded", composite, include.getName().toString());
+ continue;
+ }
+
+ includes.add(include);
+ visited.add(include);
+ collectIncludes(include, includes, visited);
+ }
+ }
+
+ /**
+ * Copy a list of includes into a composite.
+ *
+ * @param composite
+ */
+ private void fuseIncludes(Composite composite) {
+
+ // First collect all includes
+ List<Composite> includes = new ArrayList<Composite>();
+ Set<Composite> visited = new HashSet<Composite>();
+ visited.add(composite);
+ collectIncludes(composite, includes, visited);
+ // Then clone them
+ for (Composite include : includes) {
+ Composite clone;
+ try {
+ clone = (Composite)include.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new RuntimeException(e);
+ }
+ composite.getComponents().addAll(clone.getComponents());
+ composite.getServices().addAll(clone.getServices());
+ composite.getReferences().addAll(clone.getReferences());
+ composite.getProperties().addAll(clone.getProperties());
+ composite.getWires().addAll(clone.getWires());
+ composite.getPolicySets().addAll(clone.getPolicySets());
+ composite.getRequiredIntents().addAll(clone.getRequiredIntents());
+ }
+
+ // Clear the list of includes
+ composite.getIncludes().clear();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePolicyBuilderImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePolicyBuilderImpl.java
new file mode 100644
index 0000000000..76ed861167
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePolicyBuilderImpl.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.EndpointFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/**
+ * A composite builder that computes policy sets based on attached intents and policy sets.
+ * Useful if you want to build the model without making any runtime decisions such as
+ * reference/services matching
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositePolicyBuilderImpl extends BaseWireBuilderImpl implements CompositeBuilder {
+
+ public CompositePolicyBuilderImpl(AssemblyFactory assemblyFactory, EndpointFactory endpointFactory, InterfaceContractMapper interfaceContractMapper, Monitor monitor) {
+ super(assemblyFactory, endpointFactory, interfaceContractMapper, monitor);
+ }
+
+ public void build(Composite composite) throws CompositeBuilderException {
+ computePolicies(composite);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePromotionBuilderImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePromotionBuilderImpl.java
new file mode 100644
index 0000000000..5a6437b3a3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositePromotionBuilderImpl.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.EndpointFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/**
+ * A composite builder that makes the connections between composite services and references
+ * and the services and references that they promote
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositePromotionBuilderImpl extends BaseWireBuilderImpl implements CompositeBuilder {
+
+ public CompositePromotionBuilderImpl(AssemblyFactory assemblyFactory, EndpointFactory endpointFactory, InterfaceContractMapper interfaceContractMapper, Monitor monitor) {
+ super(assemblyFactory, endpointFactory, interfaceContractMapper, monitor);
+ }
+
+ public void build(Composite composite) throws CompositeBuilderException {
+ connectCompositeReferencesAndServices(composite);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java
new file mode 100644
index 0000000000..41462b151d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceConfigurationBuilderImpl.java
@@ -0,0 +1,224 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import java.util.List;
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeReference;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.builder.AutomaticBinding;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+
+/**
+ * A composite builder that handles the configuration of composite references.
+ *
+ * @version $Rev: 651179 $ $Date: 2008-04-24 08:21:13 +0100 (Thu, 24 Apr 2008) $
+ */
+public class CompositeReferenceConfigurationBuilderImpl implements CompositeBuilder {
+ private AssemblyFactory assemblyFactory;
+
+ public CompositeReferenceConfigurationBuilderImpl(AssemblyFactory assemblyFactory) {
+ this.assemblyFactory = assemblyFactory;
+ }
+
+ public void build(Composite composite) throws CompositeBuilderException {
+
+ // Process nested composites recursively
+ configureNestedCompositeReferences(composite);
+
+ // Process top level composite references
+ for (Reference reference : composite.getReferences()) {
+ CompositeReference compositeReference = (CompositeReference)reference;
+
+ // Get the next lower level promoted reference
+ List<ComponentReference> promotedRefs = compositeReference.getPromotedReferences();
+ if (!promotedRefs.isEmpty()) {
+ if (promotedRefs.size() == 1) {
+ ComponentReference promotedReference = promotedRefs.get(0);
+
+ // Set the bindings using the top level bindings to override the lower level bindings
+ if (bindingsSpecifiedManually(compositeReference.getBindings())) {
+ compositeReference.setPromotionOverride(true);
+ } else if (bindingsSpecifiedManually(promotedReference.getBindings()) ) {
+ compositeReference.getBindings().clear();
+ for (Binding binding : promotedReference.getBindings()) {
+ try {
+ compositeReference.getBindings().add((Binding)binding.clone());
+ } catch (CloneNotSupportedException ex) {
+ // this binding can't be used in the promoted reference
+ }
+ }
+ }
+ if (compositeReference.getInterfaceContract() != null &&
+ compositeReference.getInterfaceContract().getCallbackInterface() != null) {
+ if (compositeReference.getCallback() != null &&
+ bindingsSpecifiedManually(compositeReference.getCallback().getBindings())) {
+ compositeReference.setPromotionOverride(true);
+ } else if (promotedReference.getCallback() != null &&
+ bindingsSpecifiedManually(promotedReference.getCallback().getBindings())) {
+ if (compositeReference.getCallback() != null) {
+ compositeReference.getCallback().getBindings().clear();
+ } else {
+ compositeReference.setCallback(assemblyFactory.createCallback());
+ }
+ for (Binding binding : promotedReference.getCallback().getBindings()) {
+ try {
+ compositeReference.getCallback().getBindings().add((Binding)binding.clone());
+ } catch (CloneNotSupportedException ex) {
+ // this binding can't be used in the promoted reference
+ }
+ }
+ }
+ }
+ } else {
+ // This composite reference promotes multiple component references.
+ // Because the component reference bindings can all be different, we don't
+ // copy any of them up to this composite reference, which will therefore always
+ // have its own binding, even if it's only the default SCA binding.
+ if (bindingsSpecifiedManually(compositeReference.getBindings()) ||
+ (compositeReference.getCallback() != null &&
+ bindingsSpecifiedManually(compositeReference.getCallback().getBindings()))) {
+ compositeReference.setPromotionOverride(true);
+ }
+ }
+ }
+ }
+ }
+
+ private void configureNestedCompositeReferences(Composite composite) {
+
+ // Process nested composites recursively
+ for (Component component : composite.getComponents()) {
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+
+ // First process nested composites
+ configureNestedCompositeReferences((Composite)implementation);
+
+ // Process the component references declared on components in this composite
+ for (ComponentReference componentReference : component.getReferences()) {
+ Reference implReference = componentReference.getReference();
+ if (implReference != null && implReference instanceof CompositeReference) {
+ CompositeReference compositeReference = (CompositeReference)implReference;
+
+ // Get the next lower level promoted reference
+ List<ComponentReference> promotedRefs = compositeReference.getPromotedReferences();
+ if (!promotedRefs.isEmpty()) {
+ if (promotedRefs.size() == 1) {
+ ComponentReference promotedReference = promotedRefs.get(0);
+
+ // Set the bindings using the top level bindings to override the lower level bindings
+ if (!bindingsSpecifiedManually(compositeReference.getBindings()) &&
+ bindingsSpecifiedManually(promotedReference.getBindings()) ) {
+ compositeReference.getBindings().clear();
+ for (Binding binding : promotedReference.getBindings()) {
+ try {
+ compositeReference.getBindings().add((Binding)binding.clone());
+ } catch (CloneNotSupportedException ex) {
+ // this binding can't be used in the promoted reference
+ }
+ }
+ }
+ if (bindingsSpecifiedManually(componentReference.getBindings())) {
+ componentReference.setPromotionOverride(true);
+ } else if (bindingsSpecifiedManually(compositeReference.getBindings()) ) {
+ componentReference.getBindings().clear();
+ componentReference.getBindings().addAll(compositeReference.getBindings());
+ }
+ if (componentReference.getInterfaceContract() != null &&
+ componentReference.getInterfaceContract().getCallbackInterface() != null) {
+ if (!(compositeReference.getCallback() != null &&
+ bindingsSpecifiedManually(compositeReference.getCallback().getBindings())) &&
+ promotedReference.getCallback() != null &&
+ bindingsSpecifiedManually(promotedReference.getCallback().getBindings())) {
+ if (compositeReference.getCallback() != null) {
+ compositeReference.getCallback().getBindings().clear();
+ } else {
+ compositeReference.setCallback(assemblyFactory.createCallback());
+ }
+ compositeReference.getCallback().getBindings().addAll(
+ promotedReference.getCallback().getBindings());
+ }
+ if (componentReference.getCallback() != null &&
+ bindingsSpecifiedManually(componentReference.getCallback().getBindings())) {
+ componentReference.setPromotionOverride(true);
+ } else if (compositeReference.getCallback() != null &&
+ bindingsSpecifiedManually(compositeReference.getCallback().getBindings())) {
+ if (componentReference.getCallback() != null) {
+ componentReference.getCallback().getBindings().clear();
+ } else {
+ componentReference.setCallback(assemblyFactory.createCallback());
+ }
+ for (Binding binding : compositeReference.getCallback().getBindings()) {
+ try {
+ componentReference.getCallback().getBindings().add((Binding)binding.clone());
+ } catch (CloneNotSupportedException ex) {
+ // this binding can't be used in the promoted reference
+ }
+ }
+ }
+ }
+ } else {
+ // This component reference promotes multiple lower-level component references.
+ // Because the lower-level component reference bindings can all be different,
+ // we don't copy any of them up to this component reference, which will therefore
+ // always have its own binding, even if it's only the default SCA binding.
+ if (bindingsSpecifiedManually(componentReference.getBindings()) ||
+ (componentReference.getCallback() != null &&
+ bindingsSpecifiedManually(componentReference.getCallback().getBindings()))) {
+ componentReference.setPromotionOverride(true);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * If the bindings are specified in the composite file return true as they should
+ * otherwise return false
+ *
+ * @param bindings
+ * @return true if the bindings were specified manually
+ */
+ private boolean bindingsSpecifiedManually(List<Binding> bindings) {
+
+ if (bindings.size() > 1) {
+ return true;
+ } else if (bindings.size() == 1 &&
+ bindings.get(0) instanceof AutomaticBinding &&
+ ((AutomaticBinding)bindings.get(0)).getIsAutomatic()) {
+ return false;
+ } else if (bindings.size() == 1) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java
new file mode 100644
index 0000000000..8aa1897311
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeReferenceWireBuilderImpl.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeReference;
+import org.apache.tuscany.sca.assembly.EndpointFactory;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/**
+ * A composite builder that wires composite references.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeReferenceWireBuilderImpl implements CompositeBuilder {
+ private AssemblyFactory assemblyFactory;
+ private EndpointFactory endpointFactory;
+ private Monitor monitor;
+
+ public CompositeReferenceWireBuilderImpl(AssemblyFactory assemblyFactory, EndpointFactory endpointFactory, Monitor monitor) {
+ this.assemblyFactory = assemblyFactory;
+ this.endpointFactory = endpointFactory;
+ this.monitor = monitor;
+ }
+
+ /**
+ * Wire composite references in a deployment composite.
+ *
+ * @param composite
+ */
+ public void build(Composite composite) throws CompositeBuilderException {
+
+ // Process composite references declared in this composite
+ for (Reference reference : composite.getReferences()) {
+ CompositeReference compositeReference = (CompositeReference)reference;
+
+ // If the composite reference is a promotion override, override the
+ // configuration of the promoted reference.
+ //FIXME: Policy configuration or wiring of domain-level composite references
+ // doesn't cause a promotion override, unless the composite reference has
+ // additional bindings. Do we need to detect this and force an override?
+ if (compositeReference.isPromotionOverride()) {
+ List<ComponentReference> promotedReferences =
+ ReferenceConfigurationUtil.getPromotedComponentReferences(compositeReference);
+ for (ComponentReference promotedReference : promotedReferences) {
+ ReferenceConfigurationUtil.reconcileReferenceBindings(
+ compositeReference, promotedReference, assemblyFactory, endpointFactory, monitor);
+ if (compositeReference.getInterfaceContract() != null && // can be null in unit tests
+ compositeReference.getInterfaceContract().getCallbackInterface() != null) {
+ SCABinding scaCallbackBinding = promotedReference.getCallbackBinding(SCABinding.class);
+ if (promotedReference.getCallback() != null) {
+ promotedReference.getCallback().getBindings().clear();
+ } else {
+ promotedReference.setCallback(assemblyFactory.createCallback());
+ }
+ if (scaCallbackBinding != null) {
+ promotedReference.getCallback().getBindings().add(scaCallbackBinding);
+ }
+ if (compositeReference.getCallback() != null) {
+ promotedReference.getCallback().getBindings().addAll(compositeReference.getCallback()
+ .getBindings());
+ }
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java
new file mode 100644
index 0000000000..3aa9f3bf85
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceBindingBuilderImpl.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.builder.BindingBuilderExtension;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/**
+ * A composite builder that performs any additional building steps that
+ * composite service bindings may need. Used for WSDL generation.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeServiceBindingBuilderImpl implements CompositeBuilder {
+ private Monitor monitor;
+
+ public CompositeServiceBindingBuilderImpl(Monitor monitor) {
+ this.monitor = monitor;
+ }
+
+ public void build(Composite composite) throws CompositeBuilderException {
+ buildServiceBindings(composite);
+ }
+
+ private void buildServiceBindings(Composite composite) {
+
+ // build bindings recursively
+ for (Component component : composite.getComponents()) {
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ buildServiceBindings((Composite)implementation);
+ }
+ }
+
+ // find all the composite service bindings
+ for (Service service : composite.getServices()) {
+ for (Binding binding : service.getBindings()) {
+ if (binding instanceof BindingBuilderExtension) {
+ Component component = ServiceConfigurationUtil.getPromotedComponent((CompositeService)service);
+ ((BindingBuilderExtension)binding).getBuilder().build(component, service, binding, monitor);
+ }
+ }
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceConfigurationBuilderImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceConfigurationBuilderImpl.java
new file mode 100644
index 0000000000..a3f31ea2fa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServiceConfigurationBuilderImpl.java
@@ -0,0 +1,194 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import java.util.List;
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.builder.AutomaticBinding;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+
+/**
+ * A composite builder that handles the configuration of composite services.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeServiceConfigurationBuilderImpl implements CompositeBuilder {
+ private AssemblyFactory assemblyFactory;
+
+ public CompositeServiceConfigurationBuilderImpl(AssemblyFactory assemblyFactory) {
+ this.assemblyFactory = assemblyFactory;
+ }
+
+ public void build(Composite composite) throws CompositeBuilderException {
+
+ // Process nested composites recursively
+ configureNestedCompositeServices(composite);
+
+ // Process top level composite services
+ for (Service service : composite.getServices()) {
+ CompositeService compositeService = (CompositeService)service;
+
+ // Get the next lower level promoted service
+ ComponentService promotedService = compositeService.getPromotedService();
+ if (promotedService != null) {
+
+ // Set the bindings using the top level bindings to override the lower level bindings
+ if (!bindingsSpecifiedManually(compositeService.getBindings()) &&
+ bindingsSpecifiedManually(promotedService.getBindings())) {
+ compositeService.getBindings().clear();
+ for (Binding binding : promotedService.getBindings()) {
+ try {
+ compositeService.getBindings().add((Binding)binding.clone());
+ } catch (CloneNotSupportedException ex) {
+ // this binding can't be used in the promoted service
+ }
+ }
+ }
+ if (compositeService.getInterfaceContract() != null &&
+ compositeService.getInterfaceContract().getCallbackInterface() != null) {
+ if (!(compositeService.getCallback() != null &&
+ bindingsSpecifiedManually(compositeService.getCallback().getBindings())) &&
+ promotedService.getCallback() != null &&
+ bindingsSpecifiedManually(promotedService.getCallback().getBindings())) {
+ if (compositeService.getCallback() != null) {
+ compositeService.getCallback().getBindings().clear();
+ } else {
+ compositeService.setCallback(assemblyFactory.createCallback());
+ }
+ for (Binding binding : promotedService.getCallback().getBindings()) {
+ try {
+ compositeService.getCallback().getBindings().add((Binding)binding.clone());
+ } catch (CloneNotSupportedException ex) {
+ // this binding can't be used in the promoted service
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private void configureNestedCompositeServices(Composite composite) {
+
+ // Process nested composites recursively
+ for (Component component : composite.getComponents()) {
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+
+ // First process nested composites
+ configureNestedCompositeServices((Composite)implementation);
+
+ // Process the component services declared on components in this composite
+ for (ComponentService componentService : component.getServices()) {
+ Service implService = componentService.getService();
+ if (implService != null && implService instanceof CompositeService) {
+ CompositeService compositeService = (CompositeService)implService;
+
+ // Get the next lower level promoted service
+ ComponentService promotedService = compositeService.getPromotedService();
+ if (promotedService != null) {
+
+ // Set the bindings using the top level bindings to override the lower level bindings
+ if (!bindingsSpecifiedManually(compositeService.getBindings()) &&
+ bindingsSpecifiedManually(promotedService.getBindings()) ) {
+ compositeService.getBindings().clear();
+ for (Binding binding : promotedService.getBindings()) {
+ try {
+ compositeService.getBindings().add((Binding)binding.clone());
+ } catch (CloneNotSupportedException ex) {
+ // this binding can't be used in the promoted service
+ }
+ }
+ }
+ if (!bindingsSpecifiedManually(componentService.getBindings()) &&
+ bindingsSpecifiedManually(compositeService.getBindings()) ) {
+ componentService.getBindings().clear();
+ componentService.getBindings().addAll(compositeService.getBindings());
+ }
+ if (componentService.getInterfaceContract() != null &&
+ componentService.getInterfaceContract().getCallbackInterface() != null) {
+ if (!(compositeService.getCallback() != null &&
+ bindingsSpecifiedManually(compositeService.getCallback().getBindings())) &&
+ promotedService.getCallback() != null &&
+ bindingsSpecifiedManually(promotedService.getCallback().getBindings())) {
+ if (compositeService.getCallback() != null) {
+ compositeService.getCallback().getBindings().clear();
+ } else {
+ compositeService.setCallback(assemblyFactory.createCallback());
+ }
+ for (Binding binding : promotedService.getCallback().getBindings()) {
+ try {
+ compositeService.getCallback().getBindings().add((Binding)binding.clone());
+ } catch (CloneNotSupportedException ex) {
+ // this binding can't be used in the promoted service
+ }
+ }
+ }
+ if (!(componentService.getCallback() != null &&
+ bindingsSpecifiedManually(componentService.getCallback().getBindings())) &&
+ compositeService.getCallback() != null &&
+ bindingsSpecifiedManually(compositeService.getCallback().getBindings())) {
+ if (componentService.getCallback() != null) {
+ componentService.getCallback().getBindings().clear();
+ } else {
+ componentService.setCallback(assemblyFactory.createCallback());
+ }
+ componentService.getCallback().getBindings().addAll(
+ compositeService.getCallback().getBindings());
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * If the bindings are specified in the composite file return true as they should
+ * otherwise return false
+ *
+ * @param bindings
+ * @return true if the bindings were specified manually
+ */
+ private boolean bindingsSpecifiedManually(List<Binding> bindings) {
+
+ if (bindings.size() > 1) {
+ return true;
+ } else if (bindings.size() == 1 &&
+ bindings.get(0) instanceof AutomaticBinding &&
+ ((AutomaticBinding)bindings.get(0)).getIsAutomatic()) {
+ return false;
+ } else if (bindings.size() == 1) {
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServicePromotionBuilderImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServicePromotionBuilderImpl.java
new file mode 100644
index 0000000000..ea0e88ac24
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeServicePromotionBuilderImpl.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+
+/**
+ * A composite builder that handles the creation of promoted composite services.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeServicePromotionBuilderImpl implements CompositeBuilder {
+ private AssemblyFactory assemblyFactory;
+
+ public CompositeServicePromotionBuilderImpl(AssemblyFactory assemblyFactory) {
+ this.assemblyFactory = assemblyFactory;
+ }
+
+ public void build(Composite composite) throws CompositeBuilderException {
+
+ // Process top level composite services
+ for (Service service : composite.getServices()) {
+ CompositeService compositeService = (CompositeService)service;
+
+ // Get the innermost promoted service
+ ComponentService promotedService = ServiceConfigurationUtil.getPromotedComponentService(compositeService);
+ if (promotedService != null) {
+ Component promotedComponent = ServiceConfigurationUtil.getPromotedComponent(compositeService);
+
+ // Create a new component service to represent this composite
+ // service on the promoted component
+ ComponentService newComponentService = assemblyFactory.createComponentService();
+ newComponentService.setName("$promoted$" + compositeService.getName());
+ promotedComponent.getServices().add(newComponentService);
+ newComponentService.setService(promotedService.getService());
+ newComponentService.getBindings().addAll(compositeService.getBindings());
+ newComponentService.setInterfaceContract(compositeService.getInterfaceContract());
+ if (compositeService.getInterfaceContract() != null &&
+ compositeService.getInterfaceContract().getCallbackInterface() != null) {
+ newComponentService.setCallback(assemblyFactory.createCallback());
+ newComponentService.getCallback().getBindings()
+ .addAll(compositeService.getCallback().getBindings());
+ }
+
+ // Change the composite service to now promote the newly
+ // created component service directly
+ compositeService.setPromotedComponent(promotedComponent);
+ compositeService.setPromotedService(newComponentService);
+ }
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointBuilderImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointBuilderImpl.java
new file mode 100644
index 0000000000..1698b1a9c7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/EndpointBuilderImpl.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.builder.EndpointBuilder;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ * A factory for the Endpoint model.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class EndpointBuilderImpl implements EndpointBuilder {
+
+ private Monitor monitor;
+
+ public EndpointBuilderImpl (Monitor monitor){
+ this.monitor = monitor;
+ }
+
+ private void warning(String message, Object model, String... messageParameters) {
+ if (monitor != null){
+ Problem problem = new ProblemImpl(this.getClass().getName(), "assembly-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null){
+ Problem problem = null;
+ problem = new ProblemImpl(this.getClass().getName(), "assembly-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Resolve an endpoint against the provided target information and the
+ * set of candidate bindings.
+ */
+ public void build(Endpoint endpoint) {
+
+ // If this endpoint is not fully configured then don't try and resolve it
+ if (endpoint.getTargetComponentService() == null){
+ return;
+ }
+
+ // Does the reference expect callbacks
+ boolean bidirectional = false;
+
+ if (endpoint.getSourceComponentReference().getInterfaceContract() != null &&
+ endpoint.getSourceComponentReference().getInterfaceContract().getCallbackInterface() != null) {
+ bidirectional = true;
+ }
+
+ // if the target service is a promoted service then find the
+ // service it promotes
+ if (endpoint.getTargetComponentService().getService() instanceof CompositeService) {
+ CompositeService compositeService = (CompositeService) endpoint.getTargetComponentService().getService();
+ // Find the promoted component service
+ ComponentService promotedComponentService = ServiceConfigurationUtil.getPromotedComponentService(compositeService);
+ if (promotedComponentService != null && !promotedComponentService.isUnresolved()) {
+ endpoint.setTargetComponentService(promotedComponentService);
+ }
+ }
+
+ try {
+ PolicyConfigurationUtil.determineApplicableBindingPolicySets(endpoint.getSourceComponentReference(),
+ endpoint.getTargetComponentService());
+ } catch ( Exception e ) {
+ error("PolicyRelatedException", endpoint, e);
+ }
+
+
+ // Match the binding against the bindings of the target service
+ Binding resolvedBinding = BindingConfigurationUtil.matchBinding(endpoint.getTargetComponent(),
+ endpoint.getTargetComponentService(),
+ endpoint.getCandidateBindings(),
+ endpoint.getTargetComponentService().getBindings());
+ if (resolvedBinding == null) {
+ warning("NoMatchingBinding",
+ endpoint.getSourceComponentReference(),
+ endpoint.getSourceComponentReference().getName(),
+ endpoint.getTargetComponentService().getName());
+ } else {
+ endpoint.setSourceBinding(resolvedBinding);
+ }
+
+ if (bidirectional) {
+ Binding resolvedCallbackBinding = BindingConfigurationUtil.matchBinding(endpoint.getTargetComponent(),
+ endpoint.getTargetComponentService(),
+ endpoint.getSourceComponentReference().getCallback().getBindings(),
+ endpoint.getTargetComponentService().getCallback().getBindings());
+ if (resolvedBinding == null) {
+ warning("NoMatchingCallbackBinding",
+ endpoint.getSourceComponentReference(),
+ endpoint.getSourceComponentReference().getName(),
+ endpoint.getTargetComponentService().getName());
+ } else {
+ endpoint.setSourceCallbackBinding(resolvedCallbackBinding);
+ }
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyConfigurationException.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyConfigurationException.java
new file mode 100644
index 0000000000..944cf2cf36
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyConfigurationException.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+/**
+ * Exception to be throw for invalid policy intents / policysets
+ *
+ * @version $Rev$ $Date$
+ */
+public class PolicyConfigurationException extends Exception {
+ private static final long serialVersionUID = 506979037642587755L;
+
+ public PolicyConfigurationException(String message) {
+ super(message);
+ }
+
+ public PolicyConfigurationException(Throwable e) {
+ super(e);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyConfigurationUtil.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyConfigurationUtil.java
new file mode 100644
index 0000000000..c0bc18dfaf
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PolicyConfigurationUtil.java
@@ -0,0 +1,752 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.Base;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ConfiguredOperation;
+import org.apache.tuscany.sca.assembly.Contract;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.OperationsConfigurator;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPoint;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+import org.apache.tuscany.sca.policy.QualifiedIntent;
+import org.apache.tuscany.sca.policy.util.PolicyComputationUtils;
+import org.apache.tuscany.sca.policy.util.PolicyValidationException;
+import org.apache.tuscany.sca.policy.util.PolicyValidationUtils;
+
+/**
+ * This class contains policy computation methods common to computing implementation and binding policies
+ *
+ * @version $Rev$ $Date$
+ */
+abstract class PolicyConfigurationUtil {
+
+ private static List<Intent> computeInheritableIntents(IntentAttachPointType attachPointType,
+ List<Intent> inheritableIntents) throws PolicyValidationException {
+ List<Intent> validInheritableIntents = new ArrayList<Intent>();
+
+ //expand profile intents in inherited intents
+ PolicyComputationUtils.expandProfileIntents(inheritableIntents);
+
+ //validate if inherited intent applies to the attachpoint (binding / implementation) and
+ //only add such intents to the attachpoint (binding / implementation)
+ for (Intent intent : inheritableIntents) {
+ if ( !intent.isUnresolved() ) {
+ for (QName constrained : intent.getConstrains()) {
+ if ( PolicyValidationUtils.isConstrained(constrained, attachPointType)) {
+ validInheritableIntents.add(intent);
+ break;
+ }
+ }
+ } else {
+ throw new PolicyValidationException("Policy Intent '" + intent.getName() + "' is not defined in this domain");
+ }
+ }
+
+ return validInheritableIntents;
+ }
+
+ private static void normalizeIntents(IntentAttachPoint intentAttachPoint) {
+ //expand profile intents specified in the attachpoint (binding / implementation)
+ PolicyComputationUtils.expandProfileIntents(intentAttachPoint.getRequiredIntents());
+
+ //remove duplicates and ...
+ //where qualified form of intent exists retain it and remove the qualifiable intent
+ filterDuplicatesAndQualifiableIntents(intentAttachPoint);
+ }
+
+ private static void trimInherentlyProvidedIntents(IntentAttachPointType attachPointType, List<Intent>intents) {
+ //exclude intents that are inherently supported by the
+ //attachpoint-type (binding-type / implementation-type)
+ List<Intent> requiredIntents = new ArrayList<Intent>(intents);
+ for ( Intent intent : requiredIntents ) {
+ if ( isProvidedInherently(attachPointType, intent) ) {
+ intents.remove(intent);
+ }
+ }
+ }
+
+
+ static void computeIntentsForOperations(IntentAttachPoint intentAttachPoint) throws PolicyValidationException {
+ if ( intentAttachPoint instanceof OperationsConfigurator ) {
+ computeIntentsForOperations((OperationsConfigurator)intentAttachPoint,
+ intentAttachPoint,
+ intentAttachPoint.getRequiredIntents());
+ }
+ }
+
+ private static void computeIntentsForOperations(OperationsConfigurator opConfigurator,
+ IntentAttachPoint intentAttachPoint,
+ List<Intent> parentIntents) throws PolicyValidationException {
+ IntentAttachPointType attachPointType = intentAttachPoint.getType();
+
+ boolean found = false;
+ for ( ConfiguredOperation confOp : opConfigurator.getConfiguredOperations() ) {
+ //expand profile intents specified on operations
+ PolicyComputationUtils.expandProfileIntents(confOp.getRequiredIntents());
+
+ //validateIntents(confOp, attachPointType);
+
+ //add intents specified for parent intent attach point (binding / implementation)
+ //wherever its not overridden in the operation
+ Intent tempIntent = null;
+ List<Intent> attachPointOpIntents = new ArrayList<Intent>();
+ for (Intent anIntent : parentIntents) {
+ found = false;
+
+ tempIntent = anIntent;
+ while ( tempIntent instanceof QualifiedIntent ) {
+ tempIntent = ((QualifiedIntent)tempIntent).getQualifiableIntent();
+ }
+
+ for ( Intent opIntent : confOp.getRequiredIntents() ) {
+ if ( opIntent.getName().getLocalPart().startsWith(tempIntent.getName().getLocalPart())) {
+ found = true;
+ break;
+ }
+ }
+
+ if ( !found ) {
+ boolean conflict = false;
+ for (Intent excluded : anIntent.getExcludedIntents()) {
+ if (confOp.getRequiredIntents().contains(excluded)) {
+ conflict = true;
+ break;
+ }
+ }
+ if (!conflict) {
+ attachPointOpIntents.add(anIntent);
+ }
+ }
+ }
+
+ confOp.getRequiredIntents().addAll(attachPointOpIntents);
+
+ //remove duplicates and ...
+ //where qualified form of intent exists retain it and remove the qualifiable intent
+ filterDuplicatesAndQualifiableIntents(confOp);
+
+ //exclude intents that are inherently supported by the parent
+ //attachpoint-type (binding-type / implementation-type)
+ if ( attachPointType != null ) {
+ List<Intent> requiredIntents = new ArrayList<Intent>(confOp.getRequiredIntents());
+ for ( Intent intent : requiredIntents ) {
+ if ( isProvidedInherently(attachPointType, intent) ) {
+ confOp.getRequiredIntents().remove(intent);
+ }
+ }
+ }
+ }
+ }
+
+ private static List<PolicySet> computeInheritablePolicySets(List<PolicySet> inheritablePolicySets,
+ List<PolicySet> applicablePolicySets)
+ throws PolicyValidationException {
+ List<PolicySet> validInheritablePolicySets = new ArrayList<PolicySet>();
+ for (PolicySet policySet : inheritablePolicySets) {
+ if ( !policySet.isUnresolved() ) {
+ if ( applicablePolicySets.contains(policySet) ) {
+ validInheritablePolicySets.add(policySet);
+ }
+ } else {
+ throw new PolicyValidationException("Policy Set '" + policySet.getName()
+ + "' is not defined in this domain ");
+ }
+ }
+
+ return validInheritablePolicySets;
+ }
+
+ private static void normalizePolicySets(PolicySetAttachPoint policySetAttachPoint ) {
+ //get rid of duplicate entries
+ HashMap<QName, PolicySet> policySetTable = new HashMap<QName, PolicySet>();
+ for ( PolicySet policySet : policySetAttachPoint.getPolicySets() ) {
+ policySetTable.put(policySet.getName(), policySet);
+ }
+
+ policySetAttachPoint.getPolicySets().clear();
+ policySetAttachPoint.getPolicySets().addAll(policySetTable.values());
+
+ //expand profile intents
+ for ( PolicySet policySet : policySetAttachPoint.getPolicySets() ) {
+ PolicyComputationUtils.expandProfileIntents(policySet.getProvidedIntents());
+ }
+ }
+
+ private static void computePolicySetsForOperations(List<PolicySet> applicablePolicySets,
+ PolicySetAttachPoint policySetAttachPoint)
+ throws PolicyValidationException {
+ if ( policySetAttachPoint instanceof OperationsConfigurator ) {
+ computePolicySetsForOperations(applicablePolicySets,
+ (OperationsConfigurator)policySetAttachPoint,
+ policySetAttachPoint);
+ }
+
+ }
+
+ private static void computePolicySetsForOperations(List<PolicySet> applicablePolicySets,
+ OperationsConfigurator opConfigurator,
+ PolicySetAttachPoint policySetAttachPoint)
+ throws PolicyValidationException {
+ //String appliesTo = null;
+ //String scdlFragment = "";
+ HashMap<QName, PolicySet> policySetTable = new HashMap<QName, PolicySet>();
+ IntentAttachPointType attachPointType = policySetAttachPoint.getType();
+
+ for ( ConfiguredOperation confOp : opConfigurator.getConfiguredOperations() ) {
+ //validate policysets specified for the attachPoint
+ for (PolicySet policySet : confOp.getPolicySets()) {
+ if ( !policySet.isUnresolved() ) {
+ //appliesTo = policySet.getAppliesTo();
+
+ //if (!PolicyValidationUtils.isPolicySetApplicable(scdlFragment, appliesTo, attachPointType)) {
+ if (!applicablePolicySets.contains(policySet)) {
+ throw new PolicyValidationException("Policy Set '" + policySet.getName()
+ + " specified for operation " + confOp.getName()
+ + "' does not constrain extension type "
+ + attachPointType.getName());
+
+ }
+ } else {
+ throw new PolicyValidationException("Policy Set '" + policySet.getName()
+ + " specified for operation " + confOp.getName()
+ + "' is not defined in this domain ");
+ }
+ }
+
+ //get rid of duplicate entries
+ for ( PolicySet policySet : confOp.getPolicySets() ) {
+ policySetTable.put(policySet.getName(), policySet);
+ }
+
+ confOp.getPolicySets().clear();
+ confOp.getPolicySets().addAll(policySetTable.values());
+ policySetTable.clear();
+
+ //expand profile intents
+ for ( PolicySet policySet : confOp.getPolicySets() ) {
+ PolicyComputationUtils.expandProfileIntents(policySet.getProvidedIntents());
+ }
+ }
+ }
+
+
+ private static void trimProvidedIntents(List<Intent> requiredIntents, List<PolicySet> policySets) {
+ for ( PolicySet policySet : policySets ) {
+ trimProvidedIntents(requiredIntents, policySet);
+ }
+ }
+
+ private static void determineApplicableDomainPolicySets(List<PolicySet> applicablePolicySets,
+ PolicySetAttachPoint policySetAttachPoint,
+ IntentAttachPointType intentAttachPointType) {
+
+ if (policySetAttachPoint.getRequiredIntents().size() > 0) {
+
+ // form a list of all intents required by the attach point
+ List<Intent> combinedTargetIntents = new ArrayList<Intent>();
+ combinedTargetIntents.addAll(policySetAttachPoint.getRequiredIntents());
+ for (PolicySet targetPolicySet : policySetAttachPoint.getPolicySets()) {
+ combinedTargetIntents.addAll(PolicyComputationUtils.findAndExpandProfileIntents(targetPolicySet.getProvidedIntents()));
+ }
+
+ //since the set of applicable policysets for this attachpoint is known
+ //we only need to check in that list if there is a policyset that matches
+ for (PolicySet policySet : applicablePolicySets) {
+ // do not use the policy set if it provides intents that conflict with required intents
+ boolean conflict = false;
+ List<Intent> providedIntents = PolicyComputationUtils.findAndExpandProfileIntents(policySet.getProvidedIntents());
+ checkConflict: for (Intent intent : providedIntents) {
+ for (Intent excluded : intent.getExcludedIntents()) {
+ if (combinedTargetIntents.contains(excluded)) {
+ conflict = true;
+ break checkConflict;
+ }
+ }
+ }
+ if (conflict)
+ continue;
+ int prevSize = policySetAttachPoint.getRequiredIntents().size();
+ trimProvidedIntents(policySetAttachPoint.getRequiredIntents(), policySet);
+ // if any intent was trimmed off, then this policyset must
+ // be attached to the intent attachpoint's policyset
+ if (prevSize != policySetAttachPoint.getRequiredIntents().size()) {
+ policySetAttachPoint.getPolicySets().add(policySet);
+ }
+ }
+ }
+ }
+
+ private static boolean isProvidedInherently(IntentAttachPointType attachPointType, Intent intent) {
+ return ( attachPointType != null &&
+ (( attachPointType.getAlwaysProvidedIntents() != null &&
+ attachPointType.getAlwaysProvidedIntents().contains(intent) ) ||
+ ( attachPointType.getMayProvideIntents() != null &&
+ attachPointType.getMayProvideIntents().contains(intent) )
+ ) );
+ }
+
+ private static void trimProvidedIntents(List<Intent> requiredIntents, PolicySet policySet) {
+ for ( Intent providedIntent : policySet.getProvidedIntents() ) {
+ if ( requiredIntents.contains(providedIntent) ) {
+ requiredIntents.remove(providedIntent);
+ }
+ }
+
+ for ( Intent mappedIntent : policySet.getMappedPolicies().keySet() ) {
+ if ( requiredIntents.contains(mappedIntent) ) {
+ requiredIntents.remove(mappedIntent);
+ }
+ }
+ }
+
+ private static void filterDuplicatesAndQualifiableIntents(IntentAttachPoint intentAttachPoint) {
+ //remove duplicates
+ Map<QName, Intent> intentsTable = new HashMap<QName, Intent>();
+ for ( Intent intent : intentAttachPoint.getRequiredIntents() ) {
+ intentsTable.put(intent.getName(), intent);
+ }
+
+ //where qualified form of intent exists retain it and remove the qualifiable intent
+ Map<QName, Intent> intentsTableCopy = new HashMap<QName, Intent>(intentsTable);
+ //if qualified form of intent exists remove the unqualified form
+ for ( Intent intent : intentsTableCopy.values() ) {
+ if ( intent instanceof QualifiedIntent ) {
+ QualifiedIntent qualifiedIntent = (QualifiedIntent)intent;
+ if ( intentsTable.get(qualifiedIntent.getQualifiableIntent().getName()) != null ) {
+ intentsTable.remove(qualifiedIntent.getQualifiableIntent().getName());
+ }
+ }
+ }
+ intentAttachPoint.getRequiredIntents().clear();
+ intentAttachPoint.getRequiredIntents().addAll(intentsTable.values());
+ }
+
+ private static void validateIntents(ConfiguredOperation confOp, IntentAttachPointType attachPointType) throws PolicyValidationException {
+ boolean found = false;
+ if ( attachPointType != null ) {
+ //validate intents specified against the parent (binding / implementation)
+ found = false;
+ for (Intent intent : confOp.getRequiredIntents()) {
+ if ( !intent.isUnresolved() ) {
+ for (QName constrained : intent.getConstrains()) {
+ if (PolicyValidationUtils.isConstrained(constrained, attachPointType)) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ throw new PolicyValidationException("Policy Intent '" + intent.getName()
+ + " specified for operation " + confOp.getName()
+ + "' does not constrain extension type "
+ + attachPointType.getName());
+ }
+ } else {
+ throw new PolicyValidationException("Policy Intent '" + intent.getName()
+ + " specified for operation " + confOp.getName()
+ + "' is not defined in this domain ");
+ }
+ }
+ }
+ }
+
+ static void computeBindingIntentsAndPolicySets(Contract contract) throws PolicyValidationException {
+ for (Binding binding : contract.getBindings()) {
+ if (binding instanceof PolicySetAttachPoint) {
+ PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)binding;
+ computeIntents((IntentAttachPoint)binding, contract.getRequiredIntents());
+
+ aggregateAndPruneApplicablePolicySets(contract.getApplicablePolicySets(),
+ policiedBinding.getApplicablePolicySets());
+
+ computePolicySets(policiedBinding, contract.getPolicySets());
+
+ PolicyComputationUtils.checkForMutuallyExclusiveIntents(
+ policiedBinding.getRequiredIntents(),
+ policiedBinding.getPolicySets(),
+ policiedBinding.getType(),
+ contract.getName());
+
+ if ( binding instanceof OperationsConfigurator &&
+ contract instanceof OperationsConfigurator ) {
+ //add or merge service operations to the binding
+ addInheritedOpConfOnBindings((OperationsConfigurator)contract,
+ (OperationsConfigurator)binding,
+ (PolicySetAttachPoint)binding);
+
+ computeIntentsForOperations((IntentAttachPoint)binding);
+ computePolicySetsForOperations(contract.getApplicablePolicySets(),
+ policiedBinding);
+
+ for ( ConfiguredOperation confOp : ((OperationsConfigurator)binding).getConfiguredOperations() ) {
+ PolicyComputationUtils.checkForMutuallyExclusiveIntents(
+ confOp.getRequiredIntents(),
+ confOp.getPolicySets(),
+ policiedBinding.getType(),
+ contract.getName() + "." + confOp.getName());
+ }
+
+ }
+ }
+ }
+
+ if ( contract.getCallback() != null ) {
+ for (Binding binding : contract.getCallback().getBindings()) {
+ if (binding instanceof PolicySetAttachPoint) {
+ PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)binding;
+ computeIntents((IntentAttachPoint)binding, contract.getCallback().getRequiredIntents());
+
+ aggregateAndPruneApplicablePolicySets(contract.getApplicablePolicySets(),
+ policiedBinding.getApplicablePolicySets());
+
+ computePolicySets(policiedBinding, contract.getCallback().getPolicySets());
+
+ PolicyComputationUtils.checkForMutuallyExclusiveIntents(
+ policiedBinding.getRequiredIntents(),
+ policiedBinding.getPolicySets(),
+ policiedBinding.getType(),
+ contract.getName() + " callback");
+
+ }
+ }
+ }
+ }
+
+ private static void computeIntents(IntentAttachPoint policiedBinding, List<Intent> inheritedIntents)
+ throws PolicyValidationException {
+ //since the parent component could also contain intents that apply to implementation
+ //and binding elements within, we filter out only those that apply to this binding type
+ List<Intent> prunedIntents = computeInheritableIntents(policiedBinding.getType(),
+ inheritedIntents);
+ policiedBinding.getRequiredIntents().addAll(prunedIntents);
+
+ normalizeIntents(policiedBinding);
+ }
+
+ private static void computePolicySets(PolicySetAttachPoint policiedBinding,
+ List<PolicySet> inheritedPolicySets) throws PolicyValidationException {
+
+ List<PolicySet> prunedPolicySets = computeInheritablePolicySets(inheritedPolicySets,
+ policiedBinding.getApplicablePolicySets());
+ policiedBinding.getPolicySets().addAll(prunedPolicySets);
+ normalizePolicySets(policiedBinding);
+ }
+
+ static void determineApplicableBindingPolicySets(Contract source, Contract target) throws PolicyConfigurationException {
+ List<Intent> intentsCopy = null;
+ for (Binding aBinding : source.getBindings()) {
+ if (aBinding instanceof PolicySetAttachPoint) {
+ PolicySetAttachPoint policiedBinding = (PolicySetAttachPoint)aBinding;
+ IntentAttachPointType bindingType = policiedBinding.getType();
+
+
+ intentsCopy = new ArrayList<Intent>(policiedBinding.getRequiredIntents());
+ // add the target component's intents to the reference binding
+ if (target != null) {
+ for (Intent intent : target.getRequiredIntents()) {
+ if (!policiedBinding.getRequiredIntents().contains(intent)) {
+ for (QName constrained : intent.getConstrains()) {
+ if (bindingType != null && bindingType.getName().getNamespaceURI()
+ .equals(constrained.getNamespaceURI())
+ && bindingType.getName().getLocalPart().startsWith(constrained
+ .getLocalPart())) {
+ policiedBinding.getRequiredIntents().add(intent);
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ //trim intents specified in operations. First check for policysets specified on the operation
+ //and then in the parent implementation
+ if ( aBinding instanceof OperationsConfigurator ) {
+ OperationsConfigurator opConfigurator = (OperationsConfigurator)aBinding;
+
+ for ( ConfiguredOperation confOp : opConfigurator.getConfiguredOperations() ) {
+ List<Intent> opsIntentsCopy = new ArrayList<Intent>(confOp.getRequiredIntents());
+
+ trimInherentlyProvidedIntents(policiedBinding.getType(),
+ confOp.getRequiredIntents());
+ trimProvidedIntents(confOp.getRequiredIntents(), confOp.getPolicySets());
+ trimProvidedIntents(confOp.getRequiredIntents(), policiedBinding.getPolicySets());
+
+ determineApplicableDomainPolicySets(policiedBinding.getApplicablePolicySets(),
+ confOp,
+ policiedBinding.getType());
+
+ if (confOp.getRequiredIntents().size() > 0) {
+ throw new PolicyConfigurationException("The following are unfulfilled intents for operations configured in "
+ + "binding - " + aBinding.getName() + "\nUnfulfilled Intents = " +
+ confOp.getRequiredIntents());
+ }
+
+ //the intents list could have been trimmed when matching for policysets
+ //since the bindings may need the original set of intents we copy that back
+ confOp.getRequiredIntents().clear();
+ confOp.getRequiredIntents().addAll(opsIntentsCopy);
+
+ }
+ }
+
+ trimInherentlyProvidedIntents(policiedBinding.getType(),
+ policiedBinding.getRequiredIntents());
+ trimProvidedIntents(policiedBinding.getRequiredIntents(), policiedBinding
+ .getPolicySets());
+
+ // determine additional policysets that match remaining intents
+ // TODO: resolved to domain policy registry and attach suitable
+ // policy sets to the binding
+ // for now using the SCA Definitions instead of registry
+ // if there are intents that are not provided by any policy set
+ // throw a warning
+ determineApplicableDomainPolicySets(source, policiedBinding);
+
+ //the intents list could have been trimmed when matching for policysets
+ //since the bindings may need the original set of intents we copy that back
+ policiedBinding.getRequiredIntents().clear();
+ policiedBinding.getRequiredIntents().addAll(intentsCopy);
+
+ }
+ }
+ }
+
+ private static void determineApplicableDomainPolicySets(Contract contract,
+ PolicySetAttachPoint policiedBinding)
+ throws PolicyConfigurationException {
+ //if ( domainPolicySets != null) {
+ determineApplicableDomainPolicySets(policiedBinding.getApplicablePolicySets(),
+ policiedBinding,
+ policiedBinding.getType());
+
+ if ( policiedBinding.getRequiredIntents().size() > 0 ) {
+ if ( contract instanceof Service ) {
+ throw new PolicyConfigurationException("The following are unfulfilled intents for " +
+ "binding in service - " + contract.getName() + "\nUnfulfilled Intents = " +
+ policiedBinding.getRequiredIntents());
+ } else {
+ throw new PolicyConfigurationException("The are unfulfilled intents for " +
+ "binding in reference - " + contract.getName() + "\nUnfulfilled Intents = " +
+ policiedBinding.getRequiredIntents());
+ }
+ }
+ //}
+ }
+
+ private static void addInheritedOpConfOnBindings(OperationsConfigurator source,
+ OperationsConfigurator target,
+ PolicySetAttachPoint attachPoint) throws PolicyValidationException {
+ boolean found = false;
+
+ List<ConfiguredOperation> additionalOperations = new ArrayList<ConfiguredOperation>();
+ for ( ConfiguredOperation sourceConfOp : source.getConfiguredOperations() ) {
+ for ( ConfiguredOperation targetConfOp : target.getConfiguredOperations() ) {
+ if ( sourceConfOp.getName().equals(targetConfOp.getName())) {
+ List<Intent> prunedIntents = computeInheritableIntents(attachPoint.getType(),
+ sourceConfOp.getRequiredIntents());
+ PolicyComputationUtils.addInheritedIntents(prunedIntents,
+ targetConfOp.getRequiredIntents());
+
+ List<PolicySet> prunedPolicySets = computeInheritablePolicySets(sourceConfOp.getPolicySets(),
+ attachPoint.getApplicablePolicySets());
+ PolicyComputationUtils.addInheritedPolicySets(prunedPolicySets, targetConfOp.getPolicySets(), true);
+ found = true;
+ break;
+ }
+ }
+
+ if ( !found ) {
+ additionalOperations.add(sourceConfOp);
+ }
+ }
+
+ if ( !additionalOperations.isEmpty() ) {
+ target.getConfiguredOperations().addAll(additionalOperations);
+ }
+ }
+
+ private static void aggregateAndPruneApplicablePolicySets(List<PolicySet> source, List<PolicySet> target) {
+ target.addAll(source);
+ //strip duplicates
+ Hashtable<QName, PolicySet> policySetTable = new Hashtable<QName, PolicySet>();
+ for ( PolicySet policySet : target ) {
+ policySetTable.put(policySet.getName(), policySet);
+ }
+
+ target.clear();
+ target.addAll(policySetTable.values());
+ }
+
+ static <C extends Contract> void inheritDefaultPolicies(Base parent, List<C> contracts) {
+
+ for (Contract contract : contracts) {
+
+ // The contract inherits default policies from the parent composite/component.
+ if ( parent instanceof PolicySetAttachPoint ) {
+ PolicyComputationUtils.addDefaultPolicies(
+ ((PolicySetAttachPoint)parent).getRequiredIntents(),
+ ((PolicySetAttachPoint)parent).getPolicySets(),
+ contract.getRequiredIntents(),
+ contract.getPolicySets());
+ }
+
+ // The contract's configured operations inherit default policies from the contract.
+ for ( ConfiguredOperation confOp : contract.getConfiguredOperations() ) {
+ PolicyComputationUtils.addDefaultPolicies(
+ contract.getRequiredIntents(),
+ contract.getPolicySets(),
+ confOp.getRequiredIntents(),
+ confOp.getPolicySets());
+ }
+
+ // The contract's callback inherits default policies from the contract.
+ if (contract.getCallback() != null) {
+ PolicyComputationUtils.addDefaultPolicies(
+ contract.getRequiredIntents(),
+ contract.getPolicySets(),
+ contract.getCallback().getRequiredIntents(),
+ contract.getCallback().getPolicySets());
+ }
+
+ }
+ }
+
+ static void computeImplementationIntentsAndPolicySets(Implementation implementation, Component parent)
+ throws PolicyValidationException, PolicyConfigurationException {
+ if ( implementation instanceof PolicySetAttachPoint ) {
+ PolicySetAttachPoint policiedImplementation = (PolicySetAttachPoint)implementation;
+ //since for an implementation the component has its policy intents and policysets its possible
+ //that there are some intents there that does not constrain the implementation.. so prune
+ List<Intent> prunedIntents = computeInheritableIntents(policiedImplementation.getType(),
+ parent.getRequiredIntents());
+ parent.getRequiredIntents().clear();
+ parent.getRequiredIntents().addAll(prunedIntents);
+ normalizeIntents(parent);
+
+ computeIntentsForOperations((OperationsConfigurator)parent,
+ (IntentAttachPoint)implementation,
+ parent.getRequiredIntents());
+
+
+ List<PolicySet> prunedPolicySets = computeInheritablePolicySets(parent.getPolicySets(),
+ parent.getApplicablePolicySets());
+ parent.getPolicySets().clear();
+ parent.getPolicySets().addAll(prunedPolicySets);
+ normalizePolicySets(parent);
+
+ PolicyComputationUtils.checkForMutuallyExclusiveIntents(
+ parent.getRequiredIntents(),
+ parent.getPolicySets(),
+ policiedImplementation.getType(),
+ parent.getName());
+
+ computePolicySetsForOperations(parent.getApplicablePolicySets(),
+ (OperationsConfigurator)parent,
+ (PolicySetAttachPoint)implementation);
+
+ for ( ConfiguredOperation confOp : ((OperationsConfigurator)parent).getConfiguredOperations() ) {
+ PolicyComputationUtils.checkForMutuallyExclusiveIntents(
+ confOp.getRequiredIntents(),
+ confOp.getPolicySets(),
+ policiedImplementation.getType(),
+ parent.getName() + "." + confOp.getName());
+ }
+
+ determineApplicableImplementationPolicySets(parent);
+
+ }
+ }
+
+ private static void determineApplicableImplementationPolicySets(Component component) throws PolicyConfigurationException {
+ List<Intent> intentsCopy = null;
+ if ( component.getImplementation() instanceof PolicySetAttachPoint ) {
+ PolicySetAttachPoint policiedImplementation = (PolicySetAttachPoint)component.getImplementation();
+
+ //trim intents specified in operations. First check for policysets specified on the operation
+ //and then in the parent implementation
+ if ( component instanceof OperationsConfigurator ) {
+ OperationsConfigurator opConfigurator = (OperationsConfigurator)component;
+
+ for ( ConfiguredOperation confOp : opConfigurator.getConfiguredOperations() ) {
+ intentsCopy = new ArrayList<Intent>(confOp.getRequiredIntents());
+ trimInherentlyProvidedIntents(policiedImplementation.getType(),
+ confOp.getRequiredIntents());
+ trimProvidedIntents(confOp.getRequiredIntents(), confOp.getPolicySets());
+ trimProvidedIntents(confOp.getRequiredIntents(), component.getPolicySets());
+
+ determineApplicableDomainPolicySets(component.getApplicablePolicySets(),
+ confOp,
+ policiedImplementation.getType());
+
+ if (confOp.getRequiredIntents().size() > 0) {
+ throw new PolicyConfigurationException("The following are unfulfilled intents for operations configured in "
+ + "component implementation - " + component.getName() + "\nUnfulfilled Intents = " +
+ confOp.getRequiredIntents());
+ }
+
+ //the intents list could have been trimmed when matching for policysets
+ //since the implementation may need the original set of intents we copy that back
+ confOp.getRequiredIntents().clear();
+ confOp.getRequiredIntents().addAll(intentsCopy);
+ }
+ }
+
+ intentsCopy = new ArrayList<Intent>(component.getRequiredIntents());
+ trimInherentlyProvidedIntents(policiedImplementation.getType(),
+ component.getRequiredIntents());
+ trimProvidedIntents(component.getRequiredIntents(), component.getPolicySets());
+
+ //determine additional policysets that match remaining intents
+ //if there are intents that are not provided by any policy set throw a warning
+ //TODO: resolved to domain policy registry and attach suitable policy sets to the implementation
+ //...for now using the SCA Definitions instead of registry
+ //if ( domainPolicySets != null) {
+ determineApplicableDomainPolicySets(component.getApplicablePolicySets(),
+ component,
+ policiedImplementation.getType());
+
+ if (component.getRequiredIntents().size() > 0) {
+ throw new PolicyConfigurationException("The following are unfulfilled intents for component implementation - " + component
+ .getName() + "\nUnfulfilled Intents = " + component.getRequiredIntents());
+ }
+ //}
+
+ //the intents list could have been trimmed when matching for policysets
+ //since the bindings may need the original set of intents we copy that back
+ component.getRequiredIntents().clear();
+ component.getRequiredIntents().addAll(intentsCopy);
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtil.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtil.java
new file mode 100644
index 0000000000..e85aec8cea
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtil.java
@@ -0,0 +1,273 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.w3c.dom.Node;
+
+/**
+ * A simple print utility class to help print model instances.
+ *
+ * @version $Rev$ $Date$
+ */
+class PrintUtil {
+ private boolean useGetters = false;
+ private PrintWriter out;
+ private int indent;
+
+ public PrintUtil(PrintWriter out, boolean useGetters) {
+ this.out = out;
+ this.useGetters = useGetters;
+ }
+
+ public PrintUtil(OutputStream out) {
+ this.out = new PrintWriter(new OutputStreamWriter(out), true);
+ }
+
+ void indent() {
+ for (int i = 0; i < indent; i++) {
+ out.print(" ");
+ }
+ }
+
+ /**
+ * Print an object.
+ *
+ * @param object
+ */
+ public void print(Object object) {
+ Set<Integer> objects = new HashSet<Integer>();
+ print(object, objects);
+ }
+
+ /**
+ * Print an object.
+ *
+ * @param object
+ */
+ private void print(Object object, Set<Integer> printed) {
+ if (object == null) {
+ return;
+ }
+ int id = System.identityHashCode(object);
+ if (printed.contains(id)) {
+
+ // If we've already printed an object, print just it's HashCode
+ indent();
+ out.println(object.getClass().getName() + "@" + id);
+ } else {
+ printed.add(id);
+ try {
+
+ // Print the object class name
+ indent();
+ out.println(object.getClass().getSimpleName() + " {");
+
+ // Get the object's properties
+ ValueAccessor accessor = useGetters ? new PropertyAccessor(object) : new FieldAccessor(object);
+ for (int i = 0; i < accessor.size(); i++) {
+ try {
+
+ // Get the value of each property
+ Object value = accessor.getValue(i);
+ if (value != null) {
+
+ // Convert array value into a list
+ if (value.getClass().isArray()) {
+ value = Arrays.asList((Object[])value);
+ }
+
+ // Print elements in a list
+ if (value instanceof List) {
+ if (!((List)value).isEmpty()) {
+ indent++;
+ indent();
+ out.println(accessor.getName(i) + "= [");
+
+ // Print each element, recursively
+ for (Object element : (List)value) {
+ indent++;
+ print(element, printed);
+ indent--;
+ }
+ indent();
+ out.println(" ]");
+ indent--;
+ }
+ } else {
+ Class<?> valueClass = value.getClass();
+
+ // Print a primitive, java built in type or
+ // enum, using toString()
+ if (valueClass.isPrimitive() || valueClass.getName().startsWith("java.")
+ || valueClass.getName().startsWith("javax.")
+ || valueClass.isEnum()) {
+ if (!accessor.getName(i).equals("class")) {
+ if (!(Boolean.FALSE.equals(value))) {
+ indent++;
+ indent();
+ out.println(accessor.getName(i) + "=" + value.toString());
+ indent--;
+ }
+ }
+ } else if (value instanceof Node) {
+ indent++;
+ indent();
+ out.println(accessor.getName(i) + "=" + value.toString());
+ indent--;
+ } else {
+
+ // Print an object, recursively
+ indent++;
+ indent();
+ out.println(accessor.getName(i) + "= {");
+ indent++;
+ print(value, printed);
+ indent--;
+ indent();
+ out.println("}");
+ indent--;
+ }
+ }
+ }
+ } catch (Exception e) {
+ }
+ }
+ indent();
+ out.println("}");
+ } catch (Exception e) {
+ indent();
+ out.println(e);
+ }
+ }
+ }
+
+ public static interface ValueAccessor {
+ int size();
+
+ String getName(int i);
+
+ Object getValue(int i) throws Exception;
+ }
+
+ /**
+ * Java field reflection based value accessor
+ */
+ private static class FieldAccessor implements ValueAccessor {
+
+ private Object object;
+ private List<Field> fields;
+
+ public FieldAccessor(Object object) {
+ this.fields = getAllFields(object.getClass());
+ this.object = object;
+ }
+
+ public String getName(int i) {
+ return fields.get(i).getName();
+ }
+
+ public Object getValue(int i) throws Exception {
+ return fields.get(i).get(object);
+ }
+
+ public int size() {
+ return fields.size();
+ }
+
+ }
+
+ /**
+ * JavaBean-based value accessor
+ */
+ private static class PropertyAccessor implements ValueAccessor {
+
+ private Object object;
+ private PropertyDescriptor[] fields;
+
+ public PropertyAccessor(Object object) throws IntrospectionException {
+ BeanInfo beanInfo = Introspector.getBeanInfo(object.getClass());
+ this.fields = beanInfo.getPropertyDescriptors();
+ this.object = object;
+ }
+
+ public String getName(int i) {
+ return fields[i].getName();
+ }
+
+ public Object getValue(int i) throws Exception {
+ Method getter = fields[i].getReadMethod();
+ if (getter != null) {
+ return getter.invoke(object);
+ }
+ return null;
+ }
+
+ public int size() {
+ return fields.length;
+ }
+
+ }
+
+ /**
+ * Returns a collection of fields declared by a class
+ * or one of its supertypes
+ */
+ private static List<Field> getAllFields(Class<?> clazz) {
+ return getAllFields(clazz, new ArrayList<Field>());
+ }
+
+ /**
+ * Recursively evaluates the type hierarchy to return all fields
+ */
+ private static List<Field> getAllFields(Class<?> clazz, List<Field> fields) {
+ if (clazz == null || clazz.isArray() || Object.class.equals(clazz)) {
+ return fields;
+ }
+ fields = getAllFields(clazz.getSuperclass(), fields);
+ Field[] declaredFields = clazz.getDeclaredFields();
+ for (final Field field : declaredFields) {
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ field.setAccessible(true); // ignore Java accessibility
+ return null;
+ }
+ });
+ fields.add(field);
+ }
+ return fields;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ProblemImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ProblemImpl.java
new file mode 100644
index 0000000000..03f24dfae8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ProblemImpl.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import java.util.logging.Formatter;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+import java.util.logging.SimpleFormatter;
+
+import org.apache.tuscany.sca.monitor.Problem;
+
+/**
+ * Reports a composite assembly problem.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ProblemImpl implements Problem {
+
+ private String sourceClassName;
+ private String bundleName;
+ private Severity severity;
+ private Object problemObject;
+ private String messageId;
+ private Object[] messageParams;
+ private Exception cause;
+
+ /**
+ * Construct a new problem
+ *
+ * @param sourceClassName the class name reporting the problem
+ * @param bundleName the name of the message bundle to use
+ * @param severity the severity of the problem
+ * @param problemObject the model object for which the problem is being reported
+ * @param messageId the id of the problem message
+ * @param messageParams the parameters of the problem message
+ */
+ public ProblemImpl(String sourceClassName, String bundleName, Severity severity, Object problemObject, String messageId, Object... messageParams ) {
+ this.sourceClassName = sourceClassName;
+ this.bundleName = bundleName;
+ this.severity = severity;
+ this.problemObject = problemObject;
+ this.messageId = messageId;
+ this.messageParams = messageParams;
+ }
+
+ /**
+ * Construct a new problem
+ *
+ * @param sourceClassName the class name reporting the problem
+ * @param bundleName the name of the message bundle to use
+ * @param severity the severity of the problem
+ * @param problemObject the model object for which the problem is being reported
+ * @param messageId the id of the problem message
+ * @param cause the exception which caused the problem
+ */
+ public ProblemImpl(String sourceClassName, String bundleName, Severity severity, Object problemObject, String messageId, Exception cause) {
+ this.sourceClassName = sourceClassName;
+ this.bundleName = bundleName;
+ this.severity = severity;
+ this.problemObject = problemObject;
+ this.messageId = messageId;
+ this.cause = cause;
+ }
+
+ public String getSourceClassName() {
+ return sourceClassName;
+ }
+
+ public String getBundleName() {
+ return bundleName;
+ }
+
+ public Severity getSeverity() {
+ return severity;
+ }
+
+ public Object getProblemObject() {
+ return problemObject;
+ }
+
+ public String getMessageId() {
+ return messageId;
+ }
+
+ public Object[] getMessageParams() {
+ return messageParams;
+ }
+
+ public Exception getCause() {
+ return cause;
+ }
+
+ @Override
+ public String toString() {
+ Logger logger = Logger.getLogger(sourceClassName, bundleName);
+
+ LogRecord record = new LogRecord(Level.INFO, messageId);
+
+ if (cause == null){
+ record.setParameters(messageParams);
+
+ } else {
+ Object[] params = new String[1];
+ params[0] = cause.toString();
+ record.setParameters(params);
+ }
+ record.setResourceBundle(logger.getResourceBundle());
+ record.setSourceClassName(sourceClassName);
+
+ Formatter formatter = new SimpleFormatter();
+
+ return formatter.formatMessage(record);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java
new file mode 100644
index 0000000000..0105d4af50
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/PropertyConfigurationUtil.java
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathExpressionException;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentProperty;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+
+/**
+ * Utility class to deal with processing of component properties that are taking values from the parent
+ * composite's properties or an external file.
+ *
+ * @version $Rev$ $Date$
+ */
+abstract class PropertyConfigurationUtil {
+
+ private static Document evaluate(Document node, XPathExpression expression, DocumentBuilderFactory documentBuilderFactory)
+ throws XPathExpressionException, ParserConfigurationException {
+
+ Node value = node.getDocumentElement();
+ Node result = (Node)expression.evaluate(value, XPathConstants.NODE);
+ if (result == null) {
+ return null;
+ }
+
+ // TODO: How to wrap the result into a Document?
+ Document document = documentBuilderFactory.newDocumentBuilder().newDocument();
+ if (result instanceof Document) {
+ return (Document)result;
+ } else {
+ //Element root = document.createElementNS(null, "value");
+ //document.appendChild(root);
+ document.appendChild(document.importNode(result, true));
+ return document;
+ }
+ }
+
+ private static Document loadFromFile(String file, TransformerFactory transformerFactory) throws MalformedURLException, IOException,
+ TransformerException, ParserConfigurationException {
+ URI uri = URI.create(file);
+ // URI resolution for relative URIs is done when the composite is resolved.
+ URL url = uri.toURL();
+ URLConnection connection = url.openConnection();
+ connection.setUseCaches(false);
+ InputStream is = null;
+ try {
+ is = connection.getInputStream();
+
+ Source streamSource = new SAXSource(new InputSource(is));
+ DOMResult result = new DOMResult();
+ javax.xml.transform.Transformer transformer = transformerFactory.newTransformer();
+ transformer.transform(streamSource, result);
+
+ Document document = (Document)result.getNode();
+
+ // TUSCANY-2377, Add a fake value element so it's consistent with
+ // the DOM tree loaded from inside SCDL
+ Element root = document.createElementNS(null, "value");
+ root.appendChild(document.getDocumentElement());
+ document.appendChild(root);
+ return document;
+ } finally {
+ if (is != null) {
+ is.close();
+ }
+ }
+ }
+
+ static void sourceComponentProperties(Map<String, Property> compositeProperties,
+ Component componentDefinition,
+ DocumentBuilderFactory documentBuilderFactory,
+ TransformerFactory transformerFactory) throws CompositeBuilderException,
+ ParserConfigurationException,
+ XPathExpressionException,
+ TransformerException,
+ IOException {
+
+ List<ComponentProperty> componentProperties = componentDefinition.getProperties();
+ for (ComponentProperty aProperty : componentProperties) {
+ String source = aProperty.getSource();
+ String file = aProperty.getFile();
+ if (source != null) {
+ // $<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 = compositeProperties.get(name);
+ if (compositeProp == null) {
+ throw new CompositeBuilderException("The 'source' cannot be resolved to a composite property: " + source);
+ }
+
+ Document compositePropDefValues = (Document)compositeProp.getValue();
+
+ // FIXME: How to deal with namespaces?
+ Document node = evaluate(compositePropDefValues, aProperty.getSourceXPathExpression(), documentBuilderFactory);
+
+ if (node != null) {
+ aProperty.setValue(node);
+ }
+ } else {
+ throw new CompositeBuilderException("The 'source' has an invalid value: " + source);
+ }
+ } else if (file != null) {
+ aProperty.setValue(loadFromFile(aProperty.getFile(), transformerFactory));
+
+ }
+ }
+ }
+
+ private static class DOMNamespaceContext implements NamespaceContext {
+ private Node node;
+
+ /**
+ * @param node
+ */
+ public DOMNamespaceContext(Node node) {
+ super();
+ this.node = node;
+ }
+
+ public String getNamespaceURI(String prefix) {
+ if (prefix == null) {
+ throw new IllegalArgumentException("Prefix is null");
+ } else if (XMLConstants.XML_NS_PREFIX.equals(prefix)) {
+ return XMLConstants.XML_NS_URI;
+ } else if (XMLConstants.XMLNS_ATTRIBUTE.equals(prefix)) {
+ return XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
+ }
+ String ns = node.lookupNamespaceURI(prefix);
+ return ns == null ? XMLConstants.NULL_NS_URI : ns;
+ }
+
+ public String getPrefix(String namespaceURI) {
+ if (namespaceURI == null) {
+ throw new IllegalArgumentException("Namespace URI is null");
+ } else if (XMLConstants.XML_NS_URI.equals(namespaceURI)) {
+ return XMLConstants.XML_NS_PREFIX;
+ } else if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceURI)) {
+ return XMLConstants.XMLNS_ATTRIBUTE;
+ }
+ return node.lookupPrefix(namespaceURI);
+ }
+
+ public Iterator<?> getPrefixes(String namespaceURI) {
+ // Not implemented
+ if (namespaceURI == null) {
+ throw new IllegalArgumentException("Namespace URI is null");
+ } else if (XMLConstants.XML_NS_URI.equals(namespaceURI)) {
+ return Arrays.asList(XMLConstants.XML_NS_PREFIX).iterator();
+ } else if (XMLConstants.XMLNS_ATTRIBUTE_NS_URI.equals(namespaceURI)) {
+ return Arrays.asList(XMLConstants.XMLNS_ATTRIBUTE).iterator();
+ }
+ String prefix = getPrefix(namespaceURI);
+ if (prefix == null) {
+ return Collections.emptyList().iterator();
+ }
+ return Arrays.asList(prefix).iterator();
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceConfigurationUtil.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceConfigurationUtil.java
new file mode 100644
index 0000000000..23d547efaf
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ReferenceConfigurationUtil.java
@@ -0,0 +1,264 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.CompositeReference;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointFactory;
+import org.apache.tuscany.sca.assembly.Multiplicity;
+import org.apache.tuscany.sca.assembly.OptimizableBinding;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ * This class encapsulates utility methods to deal with reference definitions
+ *
+ * @version $Rev$ $Date$
+ */
+abstract class ReferenceConfigurationUtil {
+
+ /**
+ * Report a warning.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private static void warning(Monitor monitor, String message, Object model, String... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(ReferenceConfigurationUtil.class.getName(), "assembly-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ static boolean isValidMultiplicityOverride(Multiplicity definedMul, Multiplicity overridenMul) {
+ if (definedMul != overridenMul) {
+ switch (definedMul) {
+ case ZERO_N:
+ return overridenMul == Multiplicity.ZERO_ONE;
+ case ONE_N:
+ return overridenMul == Multiplicity.ONE_ONE;
+ default:
+ return false;
+ }
+ } else {
+ return true;
+ }
+ }
+
+ static boolean validateMultiplicityAndTargets(Multiplicity multiplicity,
+ List<?> targets, List<Binding> bindings) {
+
+ // Count targets
+ int count = targets.size();
+
+ //FIXME workaround, this validation is sometimes invoked too early
+ // before we get a chance to init the multiplicity attribute
+ if (multiplicity == null) {
+ return true;
+ }
+
+ switch (multiplicity) {
+ case ZERO_N:
+ break;
+ case ZERO_ONE:
+ if (count > 1) {
+ return false;
+ }
+ break;
+ case ONE_ONE:
+ if (count != 1) {
+ if (count == 0) {
+ for (Binding binding: bindings) {
+ if (!(binding instanceof OptimizableBinding) || binding.getURI()!=null) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ break;
+ case ONE_N:
+ if (count < 1) {
+ if (count == 0) {
+ for (Binding binding: bindings) {
+ if (!(binding instanceof OptimizableBinding) || binding.getURI()!=null) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+ break;
+ }
+ return true;
+ }
+
+ /**
+ * Follow a reference promotion chain down to the innermost (non composite)
+ * component references.
+ *
+ * @param compositeReference
+ * @return
+ */
+ static List<ComponentReference> getPromotedComponentReferences(CompositeReference compositeReference) {
+ List<ComponentReference> componentReferences = new ArrayList<ComponentReference>();
+ collectPromotedComponentReferences(compositeReference, componentReferences);
+ return componentReferences;
+ }
+
+ /**
+ * Follow a reference promotion chain down to the innermost (non composite)
+ * component references.
+ *
+ * @param compositeReference
+ * @param componentReferences
+ * @return
+ */
+ private static void collectPromotedComponentReferences(CompositeReference compositeReference,
+ List<ComponentReference> componentReferences) {
+ for (ComponentReference componentReference : compositeReference.getPromotedReferences()) {
+ Reference reference = componentReference.getReference();
+ if (reference instanceof CompositeReference) {
+
+ // Continue to follow the reference promotion chain
+ collectPromotedComponentReferences((CompositeReference)reference, componentReferences);
+
+ } else if (reference != null) {
+
+ // Found a non-composite reference
+ componentReferences.add(componentReference);
+ }
+ }
+ }
+
+ /**
+ * Override the bindings for a promoted reference from an outer component
+ * reference
+ *
+ * @param reference
+ * @param promotedReference
+ */
+ static void reconcileReferenceBindings(Reference reference,
+ ComponentReference promotedReference,
+ AssemblyFactory assemblyFactory,
+ EndpointFactory endpointFactory,
+ Monitor monitor) {
+
+ if (promotedReference.getMultiplicity() == Multiplicity.ONE_ONE ||
+ promotedReference.getMultiplicity() == Multiplicity.ZERO_ONE) {
+
+ // if necessary override the promoted endpoints (and bindings) with the top level bindings
+ if (reference.getBindings().size() > 0 ){
+
+ List<Binding> bindingsToCopyDown = new ArrayList<Binding>();
+ List<Endpoint> endpointsToCopyDown = new ArrayList<Endpoint>();
+
+ for (Binding binding : reference.getBindings()) {
+ if ((!(binding instanceof OptimizableBinding)) || binding.getURI() != null) {
+ bindingsToCopyDown.add(binding);
+
+ if (reference instanceof ComponentReference){
+ for (Endpoint endpoint : ((ComponentReference)reference).getEndpoints()){
+ if ( endpoint.getSourceBinding() == binding){
+ endpointsToCopyDown.add(endpoint);
+ break;
+ }
+ }
+ } else {
+ // create a new endpoint to represent this promoted binding
+ Endpoint endpoint = endpointFactory.createEndpoint();
+ endpoint.setTargetName(binding.getURI());
+ endpoint.setSourceComponent(null); // TODO - fixed up at start
+ endpoint.setSourceComponentReference(promotedReference);
+ endpoint.setInterfaceContract(reference.getInterfaceContract());
+ endpoint.setSourceBinding(binding);
+ endpointsToCopyDown.add(endpoint);
+ }
+ }
+ }
+
+ if (bindingsToCopyDown.size() > 0) {
+ promotedReference.getBindings().clear();
+ promotedReference.getBindings().addAll(bindingsToCopyDown);
+
+ promotedReference.getEndpoints().clear();
+ promotedReference.getEndpoints().addAll(endpointsToCopyDown);
+ }
+ }
+
+ if (promotedReference.getBindings().size() > 1) {
+ warning(monitor, "ComponentReferenceMoreWire", promotedReference, promotedReference.getName());
+ }
+ } else {
+ // if necessary merge the promoted endpoints (and bindings) with the top level bindings
+ if (reference.getBindings().size() > 0 ){
+
+ for (Binding binding : reference.getBindings()) {
+ if ((!(binding instanceof OptimizableBinding)) || binding.getURI() != null) {
+ promotedReference.getBindings().add(binding);
+
+ if (reference instanceof ComponentReference){
+ for (Endpoint endpoint : ((ComponentReference)reference).getEndpoints()){
+ if ( endpoint.getSourceBinding() == binding){
+ promotedReference.getEndpoints().add(endpoint);
+ break;
+ }
+ }
+ } else {
+ // create a new endpoint to represent this promoted binding
+ Endpoint endpoint = endpointFactory.createEndpoint();
+ endpoint.setTargetName(binding.getURI());
+ endpoint.setSourceComponent(null); // TODO - fixed up at start
+ endpoint.setSourceComponentReference(promotedReference);
+ endpoint.setInterfaceContract(reference.getInterfaceContract());
+ endpoint.setSourceBinding(binding);
+ promotedReference.getEndpoints().add(endpoint);
+ }
+ }
+ }
+ }
+ }
+
+ Set<Binding> callbackBindings = new HashSet<Binding>();
+ if (promotedReference.getCallback() != null) {
+ callbackBindings.addAll(promotedReference.getCallback().getBindings());
+ }
+ if (reference.getCallback() != null) {
+ callbackBindings.addAll(reference.getCallback().getBindings());
+ }
+ promotedReference.setCallback(assemblyFactory.createCallback());
+ for (Binding binding : callbackBindings) {
+ if ((!(binding instanceof OptimizableBinding)) || binding.getURI() != null) {
+ promotedReference.getCallback().getBindings().add(binding);
+ }
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ServiceConfigurationUtil.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ServiceConfigurationUtil.java
new file mode 100644
index 0000000000..41a8b3f8ba
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/builder/impl/ServiceConfigurationUtil.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.Service;
+
+/**
+ * This class encapsulates utility methods to deal with service definitions.
+ *
+ * @version $Rev$ $Date$
+ */
+abstract class ServiceConfigurationUtil {
+
+ /**
+ * Follow a service promotion chain down to the inner most (non composite)
+ * component service.
+ *
+ * @param topCompositeService
+ * @return
+ */
+ static ComponentService getPromotedComponentService(CompositeService compositeService) {
+ ComponentService componentService = compositeService.getPromotedService();
+ if (componentService != null) {
+ Service service = componentService.getService();
+ if (componentService.getName() != null && service instanceof CompositeService) {
+
+ // Continue to follow the service promotion chain
+ return getPromotedComponentService((CompositeService)service);
+
+ } else {
+
+ // Found a non-composite service
+ return componentService;
+ }
+ } else {
+
+ // No promoted service
+ return null;
+ }
+ }
+
+ /**
+ * Follow a service promotion chain down to the innermost (non-composite) component.
+ *
+ * @param compositeService
+ * @return
+ */
+ static Component getPromotedComponent(CompositeService compositeService) {
+ ComponentService componentService = compositeService.getPromotedService();
+ if (componentService != null) {
+ Service service = componentService.getService();
+ if (componentService.getName() != null && service instanceof CompositeService) {
+
+ // Continue to follow the service promotion chain
+ return getPromotedComponent((CompositeService)service);
+
+ } else {
+
+ // Found a non-composite service
+ return compositeService.getPromotedComponent();
+ }
+ } else {
+
+ // No promoted service
+ return null;
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractPropertyImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractPropertyImpl.java
new file mode 100644
index 0000000000..b7c63dc2b4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractPropertyImpl.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.AbstractProperty;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+
+/**
+ * Represents an abstract property.
+ *
+ * @version $Rev$ $Date$
+ */
+public class AbstractPropertyImpl extends ExtensibleImpl implements AbstractProperty {
+ private Object value;
+ private String name;
+ private QName xsdType;
+ private QName xsdElement;
+ private boolean many;
+ private boolean mustSupply;
+ private List<Intent> requiredIntents = new ArrayList<Intent>();
+
+
+ public List<Intent> getRequiredIntents() {
+ return requiredIntents;
+ }
+
+ /**
+ * Constructs a new abstract property.
+ */
+ protected AbstractPropertyImpl() {
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public QName getXSDElement() {
+ return xsdElement;
+ }
+
+ public QName getXSDType() {
+ return xsdType;
+ }
+
+ public boolean isMany() {
+ return many;
+ }
+
+ public boolean isMustSupply() {
+ return mustSupply;
+ }
+
+ public void setValue(Object defaultValue) {
+ this.value = defaultValue;
+ }
+
+ public void setMany(boolean many) {
+ this.many = many;
+ }
+
+ public void setMustSupply(boolean mustSupply) {
+ this.mustSupply = mustSupply;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public void setXSDElement(QName element) {
+ this.xsdElement = element;
+ }
+
+ public void setXSDType(QName type) {
+ this.xsdType = type;
+ }
+
+ public IntentAttachPointType getType() {
+ return null;
+ }
+
+ public void setType(IntentAttachPointType type) {
+ }
+
+ public void setRequiredIntents(List<Intent> intents) {
+ this.requiredIntents = intents;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractReferenceImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractReferenceImpl.java
new file mode 100644
index 0000000000..d0ee3832c5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractReferenceImpl.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly.impl;
+
+import org.apache.tuscany.sca.assembly.AbstractReference;
+import org.apache.tuscany.sca.assembly.Multiplicity;
+
+/**
+ * Represents an abstract reference
+ *
+ * @version $Rev$ $Date$
+ */
+public class AbstractReferenceImpl extends ContractImpl implements AbstractReference {
+ private Multiplicity multiplicity = Multiplicity.ONE_ONE;
+
+ /**
+ * Constructs a new abstract reference.
+ */
+ protected AbstractReferenceImpl() {
+ }
+
+ public Multiplicity getMultiplicity() {
+ return multiplicity;
+ }
+
+ public void setMultiplicity(Multiplicity multiplicity) {
+ this.multiplicity = multiplicity;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractServiceImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractServiceImpl.java
new file mode 100644
index 0000000000..346764b1b4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AbstractServiceImpl.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly.impl;
+
+import org.apache.tuscany.sca.assembly.AbstractService;
+
+/**
+ * Represents an abstract service
+ *
+ * @version $Rev$ $Date$
+ */
+public class AbstractServiceImpl extends ContractImpl implements AbstractService {
+
+ /**
+ * Constructs a new abstract service.
+ */
+ protected AbstractServiceImpl() {
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AssemblyFactoryImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AssemblyFactoryImpl.java
new file mode 100644
index 0000000000..016a9a5b05
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/AssemblyFactoryImpl.java
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.impl;
+
+import org.apache.tuscany.sca.assembly.AbstractProperty;
+import org.apache.tuscany.sca.assembly.AbstractReference;
+import org.apache.tuscany.sca.assembly.AbstractService;
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Callback;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentProperty;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeReference;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.ConfiguredOperation;
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.Wire;
+
+/**
+ * A factory for the assembly model.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class AssemblyFactoryImpl implements AssemblyFactory {
+
+ public AbstractProperty createAbstractProperty() {
+ return new AbstractPropertyImpl();
+ }
+
+ public AbstractReference createAbstractReference() {
+ return new AbstractReferenceImpl();
+ }
+
+ public AbstractService createAbstractService() {
+ return new AbstractServiceImpl();
+ }
+
+ public Callback createCallback() {
+ return new CallbackImpl();
+ }
+
+ public Component createComponent() {
+ return new ComponentImpl();
+ }
+
+ public ComponentProperty createComponentProperty() {
+ return new ComponentPropertyImpl();
+ }
+
+ public ComponentReference createComponentReference() {
+ return new ComponentReferenceImpl();
+ }
+
+ public ComponentService createComponentService() {
+ return new ComponentServiceImpl();
+ }
+
+ public ComponentType createComponentType() {
+ return new ComponentTypeImpl();
+ }
+
+ public Composite createComposite() {
+ return new CompositeImpl();
+ }
+
+ public CompositeReference createCompositeReference() {
+ return new CompositeReferenceImpl();
+ }
+
+ public CompositeService createCompositeService() {
+ return new CompositeServiceImpl();
+ }
+
+ public ConstrainingType createConstrainingType() {
+ return new ConstrainingTypeImpl();
+ }
+
+ public Property createProperty() {
+ return new PropertyImpl();
+ }
+
+ public Reference createReference() {
+ return new ReferenceImpl();
+ }
+
+ public Service createService() {
+ return new ServiceImpl();
+ }
+
+ public Wire createWire() {
+ return new WireImpl();
+ }
+
+ public ConfiguredOperation createConfiguredOperation() {
+ return new ConfiguredOperationImpl();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/BaseImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/BaseImpl.java
new file mode 100644
index 0000000000..553e600bc9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/BaseImpl.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly.impl;
+
+import org.apache.tuscany.sca.assembly.Base;
+
+/**
+ * Convenience base class for assembly model objects.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class BaseImpl implements Base {
+ private boolean unresolved;
+
+ /**
+ * Constructs a new base model object.
+ */
+ protected BaseImpl() {
+ }
+
+ public boolean isUnresolved() {
+ return unresolved;
+ }
+
+ public void setUnresolved(boolean undefined) {
+ this.unresolved = undefined;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CallbackImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CallbackImpl.java
new file mode 100644
index 0000000000..4082d81fdb
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CallbackImpl.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Callback;
+import org.apache.tuscany.sca.assembly.ConfiguredOperation;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicySet;
+
+/**
+ * Represents a reference.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CallbackImpl extends ExtensibleImpl implements Callback {
+ private List<Binding> bindings = new ArrayList<Binding>();
+ private List<Intent> requiredIntents = new ArrayList<Intent>();
+ private List<PolicySet> policySets = new ArrayList<PolicySet>();
+ private List<ConfiguredOperation> configuredOperations = new ArrayList<ConfiguredOperation>();
+ private List<PolicySet> applicablePolicySets = new ArrayList<PolicySet>();
+
+ public List<PolicySet> getPolicySets() {
+ return policySets;
+ }
+
+ public List<Intent> getRequiredIntents() {
+ return requiredIntents;
+ }
+
+ protected CallbackImpl() {
+ }
+
+ public List<Binding> getBindings() {
+ return bindings;
+ }
+
+ public IntentAttachPointType getType() {
+ return null;
+ }
+
+ public void setType(IntentAttachPointType type) {
+ }
+
+ public void setPolicySets(List<PolicySet> policySets) {
+ this.policySets = policySets;
+ }
+
+ public void setRequiredIntents(List<Intent> intents) {
+ this.requiredIntents = intents;
+ }
+
+ public List<ConfiguredOperation> getConfiguredOperations() {
+ return configuredOperations;
+ }
+
+ public List<PolicySet> getApplicablePolicySets() {
+ return applicablePolicySets;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java
new file mode 100644
index 0000000000..34429a6703
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentImpl.java
@@ -0,0 +1,174 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentProperty;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.ConfiguredOperation;
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.OperationsConfigurator;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicySet;
+
+/**
+ * Represents a component.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentImpl extends ExtensibleImpl implements Component, Cloneable, OperationsConfigurator {
+ private ConstrainingType constrainingType;
+ private Implementation implementation;
+ private String name;
+ private String uri;
+ private List<ComponentProperty> properties = new ArrayList<ComponentProperty>();
+ private List<ComponentReference> references = new ArrayList<ComponentReference>();
+ private List<ComponentService> services = new ArrayList<ComponentService>();
+ private List<Intent> requiredIntents = new ArrayList<Intent>();
+ private List<PolicySet> policySets = new ArrayList<PolicySet>();
+ private Boolean autowire;
+ private IntentAttachPointType type;
+ private List<ConfiguredOperation> configuredImplOperations = new ArrayList<ConfiguredOperation>();
+ private List<PolicySet> applicablePolicySets = new ArrayList<PolicySet>();
+ /**
+ * Constructs a new component.
+ */
+ protected ComponentImpl() {
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ ComponentImpl clone = (ComponentImpl)super.clone();
+
+ clone.properties = new ArrayList<ComponentProperty>();
+ for (ComponentProperty property : getProperties()) {
+ clone.properties.add((ComponentProperty)property.clone());
+ }
+ clone.references = new ArrayList<ComponentReference>();
+ for (ComponentReference reference : getReferences()) {
+ clone.references.add((ComponentReference)reference.clone());
+ }
+ clone.services = new ArrayList<ComponentService>();
+ for (ComponentService service : getServices()) {
+ clone.services.add((ComponentService)service.clone());
+ }
+ return clone;
+ }
+
+ public String getURI() {
+ return uri;
+ }
+
+ public void setURI(String uri) {
+ this.uri = uri;
+ }
+
+ public ConstrainingType getConstrainingType() {
+ return constrainingType;
+ }
+
+ public Implementation getImplementation() {
+ return implementation;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public List<ComponentProperty> getProperties() {
+ return properties;
+ }
+
+ public List<ComponentReference> getReferences() {
+ return references;
+ }
+
+ public List<ComponentService> getServices() {
+ return services;
+ }
+
+ public void setConstrainingType(ConstrainingType constrainingType) {
+ this.constrainingType = constrainingType;
+ }
+
+ public void setImplementation(Implementation implementation) {
+ this.implementation = implementation;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public List<Intent> getRequiredIntents() {
+ return requiredIntents;
+ }
+
+ public List<PolicySet> getPolicySets() {
+ return policySets;
+ }
+
+ public boolean isAutowire() {
+ return (autowire == null) ? false : autowire.booleanValue();
+ }
+
+ public void setAutowire(Boolean autowire) {
+ this.autowire = autowire;
+ }
+
+ public Boolean getAutowire() {
+ return autowire;
+ }
+
+ public IntentAttachPointType getType() {
+ return type;
+ }
+
+ public void setType(IntentAttachPointType type) {
+ this.type = type;
+ }
+
+ public void setPolicySets(List<PolicySet> policySets) {
+ this.policySets = policySets;
+
+ }
+
+ public void setRequiredIntents(List<Intent> intents) {
+ this.requiredIntents = intents;
+
+ }
+
+ public List<ConfiguredOperation> getConfiguredOperations() {
+ return configuredImplOperations;
+ }
+
+ public void setConfiguredOperations(List<ConfiguredOperation> configuredOperations) {
+ this.configuredImplOperations = configuredOperations;
+ }
+
+ public List<PolicySet> getApplicablePolicySets() {
+ return applicablePolicySets;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java
new file mode 100644
index 0000000000..e2e7b59896
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentPropertyImpl.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.impl;
+
+import javax.xml.xpath.XPathExpression;
+
+import org.apache.tuscany.sca.assembly.ComponentProperty;
+import org.apache.tuscany.sca.assembly.Property;
+
+/**
+ * Represents a component property.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentPropertyImpl extends PropertyImpl implements ComponentProperty, Cloneable {
+ private String file;
+ private Property property;
+ private String source;
+ private XPathExpression sourceXPathExpression;
+
+ /**
+ * Constructs a new component property.
+ */
+ protected ComponentPropertyImpl() {
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+ // FIXME getValue should not delegate to property.getValue()
+ // Doing this violates the setValue/getValue semantics, as you
+ // can call setValue() then get a different value from getValue()
+ @Override
+ public Object getValue() {
+ if (super.getValue() == null && property != null) {
+ return property.getValue();
+ } else {
+ return super.getValue();
+ }
+ }
+
+ public String getFile() {
+ return file;
+ }
+
+ public Property getProperty() {
+ return property;
+ }
+
+ public String getSource() {
+ return source;
+ }
+
+ public void setFile(String file) {
+ this.file = file;
+ }
+
+ public void setProperty(Property property) {
+ this.property = property;
+ }
+
+ public void setSource(String source) {
+ this.source = source;
+ }
+
+ public XPathExpression getSourceXPathExpression() {
+ return sourceXPathExpression;
+ }
+
+ public void setSourceXPathExpression(XPathExpression sourceXPathExpression) {
+ this.sourceXPathExpression = sourceXPathExpression;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.java
new file mode 100644
index 0000000000..488023090c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentReferenceImpl.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.CompositeReference;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+
+/**
+ * Represents a component reference
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentReferenceImpl extends ReferenceImpl implements ComponentReference, Cloneable {
+ private Reference reference;
+ private Boolean autowire;
+ private List<CompositeReference> promotedAs = new ArrayList<CompositeReference>();
+ private ComponentService callbackService;
+ private List<Endpoint> endpoints = new ArrayList<Endpoint>();
+
+ /**
+ * Constructs a new component reference.
+ */
+ protected ComponentReferenceImpl() {
+ // Set multiplicity to null so that by default it'll inherit from the Reference
+ setMultiplicity(null);
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+ public Reference getReference() {
+ return reference;
+ }
+
+ public void setReference(Reference reference) {
+ this.reference = reference;
+ }
+
+ public boolean isAutowire() {
+ return (autowire == null) ? false : autowire.booleanValue();
+ }
+
+ public void setAutowire(Boolean autowire) {
+ this.autowire = autowire;
+ }
+
+ public Boolean getAutowire() {
+ return autowire;
+ }
+
+ public List<CompositeReference> promotedAs() {
+ return promotedAs;
+ }
+
+ public ComponentService getCallbackService() {
+ return callbackService;
+ }
+
+ public void setCallbackService(ComponentService callbackService) {
+ this.callbackService = callbackService;
+ }
+
+ public List<Endpoint> getEndpoints(){
+ return endpoints;
+ }
+
+ /**
+ * Use endpoint information to work out what the interface contract for the
+ * binding is.
+ */
+ @Override
+ public InterfaceContract getInterfaceContract(Binding binding){
+ InterfaceContract interfaceContract = null;
+
+ for (Endpoint theEndpoint : endpoints){
+ if (theEndpoint.getSourceBinding() == binding){
+ interfaceContract = theEndpoint.getInterfaceContract();
+ }
+ }
+
+ if (interfaceContract == null){
+ interfaceContract = getInterfaceContract();
+ }
+ return interfaceContract;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentServiceImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentServiceImpl.java
new file mode 100644
index 0000000000..0c78a2505f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentServiceImpl.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.Service;
+
+/**
+ * Represents a component service
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentServiceImpl extends ServiceImpl implements ComponentService, Cloneable {
+ private Service service;
+ private List<CompositeService> promotedAs = new ArrayList<CompositeService>();
+ private ComponentReference callbackReference;
+
+ /**
+ * Constructs a new component service.
+ */
+ protected ComponentServiceImpl() {
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+ public Service getService() {
+ return service;
+ }
+
+ public void setService(Service service) {
+ this.service = service;
+ }
+
+ public List<CompositeService> promotedAs() {
+ return promotedAs;
+ }
+
+ public ComponentReference getCallbackReference() {
+ return callbackReference;
+ }
+
+ public void setCallbackReference(ComponentReference callbackReference) {
+ this.callbackReference = callbackReference;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentTypeImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentTypeImpl.java
new file mode 100644
index 0000000000..bbe665d52f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ComponentTypeImpl.java
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+
+/**
+ * Represents a component type.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentTypeImpl extends ExtensibleImpl implements ComponentType, Cloneable {
+ private String uri;
+ private ConstrainingType constrainingType;
+ private List<Property> properties = new ArrayList<Property>();
+ private List<Reference> references = new ArrayList<Reference>();
+ private List<Service> services = new ArrayList<Service>();
+ /**
+ * Constructs a new component type.
+ */
+ protected ComponentTypeImpl() {
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ ComponentTypeImpl clone = (ComponentTypeImpl)super.clone();
+
+ clone.services = new ArrayList<Service>();
+ for (Service service : getServices()) {
+ clone.services.add((Service)service.clone());
+ }
+ clone.references = new ArrayList<Reference>();
+ for (Reference reference : getReferences()) {
+ clone.references.add((Reference)reference.clone());
+ }
+ clone.properties = new ArrayList<Property>();
+ for (Property property : getProperties()) {
+ clone.properties.add((Property)property.clone());
+ }
+ return clone;
+ }
+
+ public String getURI() {
+ return uri;
+ }
+
+ public void setURI(String uri) {
+ this.uri = uri;
+ }
+
+ public ConstrainingType getConstrainingType() {
+ return constrainingType;
+ }
+
+ public List<Property> getProperties() {
+ return properties;
+ }
+
+ public List<Reference> getReferences() {
+ return references;
+ }
+
+ public List<Service> getServices() {
+ return services;
+ }
+
+ public void setConstrainingType(ConstrainingType constrainingType) {
+ this.constrainingType = constrainingType;
+ }
+
+ @Override
+ public int hashCode() {
+ return String.valueOf(getURI()).hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ } else {
+ if (obj instanceof ComponentType) {
+ if (getURI() != null) {
+ return getURI().equals(((ComponentType)obj).getURI());
+ } else {
+ return ((ComponentType)obj).getURI() == null;
+ }
+ } else {
+ return false;
+ }
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeImpl.java
new file mode 100644
index 0000000000..a0ec95023a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeImpl.java
@@ -0,0 +1,153 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeReference;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.Wire;
+
+/**
+ * Implementation of a Composite.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeImpl extends ImplementationImpl implements Composite, Cloneable {
+ private List<Component> components = new ArrayList<Component>();
+ private List<Composite> includes = new ArrayList<Composite>();
+ private QName name;
+ private List<Wire> wires = new ArrayList<Wire>();
+ private Boolean autowire;
+ private boolean local = true;
+
+ /**
+ * Constructs a new composite.
+ */
+ protected CompositeImpl() {
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ CompositeImpl clone = (CompositeImpl)super.clone();
+
+ clone.components = new ArrayList<Component>();
+ for (Component component : getComponents()) {
+ Component clonedComponent = (Component)component.clone();
+ for (Service service : clone.getServices()) {
+ CompositeService compositeService = (CompositeService)service;
+ // Force the promoted component/service to be rebuilt against the clone
+ if (compositeService.getPromotedComponent() != null) {
+ compositeService.getPromotedComponent().setUnresolved(true);
+ }
+ if (compositeService.getPromotedService() != null) {
+ compositeService.getPromotedService().setUnresolved(true);
+ }
+ }
+ for (Reference reference : clone.getReferences()) {
+ CompositeReference compositeReference = (CompositeReference)reference;
+ for (ComponentReference ref : compositeReference.getPromotedReferences()) {
+ // Force the promoted reference to be rebuilt against the clone
+ ref.setUnresolved(true);
+ }
+ }
+
+ clone.components.add(clonedComponent);
+ }
+ clone.wires = new ArrayList<Wire>();
+ for (Wire wire : getWires()) {
+ clone.wires.add((Wire)wire.clone());
+ }
+ return clone;
+ }
+
+ public List<Component> getComponents() {
+ return components;
+ }
+
+ public List<Composite> getIncludes() {
+ return includes;
+ }
+
+ public QName getName() {
+ return name;
+ }
+
+ public List<Wire> getWires() {
+ return wires;
+ }
+
+ public boolean isLocal() {
+ return local;
+ }
+
+ public void setLocal(boolean local) {
+ this.local = local;
+ }
+
+ public boolean isAutowire() {
+ return (autowire == null) ? false : autowire.booleanValue();
+ }
+
+ public void setAutowire(Boolean autowire) {
+ this.autowire = autowire;
+ }
+
+ public Boolean getAutowire() {
+ return autowire;
+ }
+
+ public void setName(QName name) {
+ this.name = name;
+ }
+
+ @Override
+ public int hashCode() {
+ return String.valueOf(getName()).hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ } else if (obj instanceof Composite) {
+ if (getName() != null) {
+ return getName().equals(((Composite)obj).getName());
+ } else {
+ return ((Composite)obj).getName() == null;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public String toString(){
+ return getName().toString();
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeReferenceImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeReferenceImpl.java
new file mode 100644
index 0000000000..4348e08fcb
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeReferenceImpl.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.CompositeReference;
+
+/**
+ * Represents a composite reference.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeReferenceImpl extends ReferenceImpl implements CompositeReference, Cloneable {
+ private List<ComponentReference> promotedReferences = new ArrayList<ComponentReference>();
+
+ /**
+ * Constructs a new composite reference.
+ */
+ protected CompositeReferenceImpl() {
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+ public List<ComponentReference> getPromotedReferences() {
+ return promotedReferences;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeServiceImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeServiceImpl.java
new file mode 100644
index 0000000000..6777a96982
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/CompositeServiceImpl.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.impl;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.CompositeService;
+
+/**
+ * Represents a composite service
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeServiceImpl extends ServiceImpl implements CompositeService, Cloneable {
+ private ComponentService promotedService;
+ private Component promotedComponent;
+
+ /**
+ * Constructs a new composite service.
+ */
+ protected CompositeServiceImpl() {
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+ public ComponentService getPromotedService() {
+ return promotedService;
+ }
+
+ public void setPromotedService(ComponentService promotedService) {
+ this.promotedService = promotedService;
+ }
+
+ public Component getPromotedComponent() {
+ return promotedComponent;
+ }
+
+ public void setPromotedComponent(Component promotedComponent) {
+ this.promotedComponent = promotedComponent;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConfiguredOperationImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConfiguredOperationImpl.java
new file mode 100644
index 0000000000..1373ce511b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConfiguredOperationImpl.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.ConfiguredOperation;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicySet;
+
+/**
+ * Represents an Operation.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConfiguredOperationImpl extends BaseImpl implements ConfiguredOperation {
+ private List<PolicySet> policySets = new ArrayList<PolicySet>();
+ private List<Intent> requiredIntents = new ArrayList<Intent>();
+ private List<PolicySet> applicablePolicySets = new ArrayList<PolicySet>();
+
+ private String name;
+ private String contractName;
+
+ /**
+ * Constructs a new Operation.
+ */
+ protected ConfiguredOperationImpl() {
+ }
+
+ public List<PolicySet> getPolicySets() {
+ return policySets;
+ }
+
+ public void setPolicySets(List<PolicySet> policySets) {
+ this.policySets = policySets;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public List<Intent> getRequiredIntents() {
+ return requiredIntents;
+ }
+
+ public void setRequiredIntents(List<Intent> intents) {
+ this.requiredIntents = intents;
+ }
+
+ public String getContractName() {
+ return contractName;
+ }
+
+ public void setContractName(String contractName) {
+ this.contractName = contractName;
+ }
+
+ public IntentAttachPointType getType() {
+ return null;
+ }
+
+ public void setType(IntentAttachPointType type) {
+ }
+
+ public List<PolicySet> getApplicablePolicySets() {
+ return applicablePolicySets;
+ }
+
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConstrainingTypeImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConstrainingTypeImpl.java
new file mode 100644
index 0000000000..d5701df74e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ConstrainingTypeImpl.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.AbstractProperty;
+import org.apache.tuscany.sca.assembly.AbstractReference;
+import org.apache.tuscany.sca.assembly.AbstractService;
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+
+/**
+ * Represents a constraining type.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConstrainingTypeImpl extends ExtensibleImpl implements ConstrainingType {
+ private QName name;
+ private List<AbstractProperty> properties = new ArrayList<AbstractProperty>();
+ private List<AbstractReference> references = new ArrayList<AbstractReference>();
+ private List<AbstractService> services = new ArrayList<AbstractService>();
+ private List<Intent> requiredIntents = new ArrayList<Intent>();
+
+ /**
+ * Constructs a new ConstrainingType
+ */
+ protected ConstrainingTypeImpl() {
+ }
+
+ public QName getName() {
+ return name;
+ }
+
+ public void setName(QName name) {
+ this.name = name;
+ }
+
+ public List<AbstractProperty> getProperties() {
+ return properties;
+ }
+
+ public List<AbstractReference> getReferences() {
+ return references;
+ }
+
+ public List<AbstractService> getServices() {
+ return services;
+ }
+
+ public List<Intent> getRequiredIntents() {
+ return requiredIntents;
+ }
+
+ @Override
+ public int hashCode() {
+ return String.valueOf(getName()).hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ } else if (obj instanceof ConstrainingType) {
+ if (getName() != null) {
+ return getName().equals(((ConstrainingType)obj).getName());
+ } else {
+ return ((ConstrainingType)obj).getName() == null;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ public IntentAttachPointType getType() {
+ return null;
+ }
+
+ public void setType(IntentAttachPointType type) {
+ }
+
+ public void setRequiredIntents(List<Intent> intents) {
+ this.requiredIntents = intents;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ContractImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ContractImpl.java
new file mode 100644
index 0000000000..491c835246
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ContractImpl.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.AbstractContract;
+import org.apache.tuscany.sca.assembly.ConfiguredOperation;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+
+/**
+ * Implementation of a Contract.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ContractImpl extends ExtensibleImpl implements AbstractContract {
+ private InterfaceContract interfaceContract;
+ private String name;
+ private List<Intent> requiredIntents = new ArrayList<Intent>();
+ private List<ConfiguredOperation> configuredOperations = new ArrayList<ConfiguredOperation>();
+
+ private boolean isCallback = false;
+
+ /**
+ * Constructs a new contract.
+ */
+ protected ContractImpl() {
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public InterfaceContract getInterfaceContract() {
+ return interfaceContract;
+ }
+
+ public void setInterfaceContract(InterfaceContract interfaceContract) {
+ this.interfaceContract = interfaceContract;
+ }
+
+ public List<Intent> getRequiredIntents() {
+ return requiredIntents;
+ }
+
+ public boolean isCallback() {
+ return isCallback;
+ }
+
+ public void setIsCallback(boolean isCallback) {
+ this.isCallback = isCallback;
+ }
+
+ public IntentAttachPointType getType() {
+ return null;
+ }
+
+ public void setType(IntentAttachPointType type) {
+ }
+
+ public void setRequiredIntents(List<Intent> intents) {
+ this.requiredIntents = intents;
+ }
+
+ public List<ConfiguredOperation> getConfiguredOperations() {
+ return configuredOperations;
+ }
+
+ public void setConfiguredOperations(List<ConfiguredOperation> configuredOperations) {
+ this.configuredOperations = configuredOperations;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointFactoryImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointFactoryImpl.java
new file mode 100644
index 0000000000..ece51cbe9b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointFactoryImpl.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.impl;
+
+
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.EndpointFactory;
+
+/**
+ * A factory for the Endpoint model.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class EndpointFactoryImpl implements EndpointFactory {
+
+ public EndpointFactoryImpl (){
+
+ }
+
+ public Endpoint createEndpoint() {
+ return new EndpointImpl();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointImpl.java
new file mode 100644
index 0000000000..5748abb07d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/EndpointImpl.java
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+
+/**
+ * The assembly model object for an endpoint.
+ *
+ * @version $Rev$ $Date$
+ */
+public class EndpointImpl implements Endpoint {
+
+ private String targetName;
+
+ private Component sourceComponent;
+ private ComponentReference sourceComponentReference;
+ private Binding resolvedBinding;
+ private Binding resolvedCallbackBinding;
+
+ private List<Binding> candidateBindings = new ArrayList<Binding>();
+
+ private Component targetComponent;
+ private ComponentService targetComponentService;
+ private Binding targetBinding;
+ private Binding targetCallbackBinding;
+
+ private InterfaceContract interfaceContract;
+
+ protected EndpointImpl() {
+ }
+
+ public boolean isUnresolved() {
+ return resolvedBinding == null;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ // do nothing as the status is determined by having
+ // a resolved source binding
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+ public String getTargetName(){
+ return targetName;
+ }
+
+ public void setTargetName(String targetName){
+ this.targetName = targetName;
+ }
+
+ public Component getSourceComponent() {
+ return sourceComponent;
+ }
+
+ public void setSourceComponent(Component sourceComponent) {
+ this.sourceComponent = sourceComponent;
+ }
+
+ public ComponentReference getSourceComponentReference() {
+ return sourceComponentReference;
+ }
+
+ public void setSourceComponentReference(ComponentReference sourceComponentReference) {
+ this.sourceComponentReference = sourceComponentReference;
+ }
+
+ public Binding getSourceBinding() {
+ return resolvedBinding;
+ }
+
+ public void setSourceBinding(Binding resolvedBinding) {
+ this.resolvedBinding = resolvedBinding;
+ }
+
+ public Binding getSourceCallbackBinding(){
+ return resolvedCallbackBinding;
+ }
+
+ public void setSourceCallbackBinding(Binding resolvedCallbackBinding){
+ this.resolvedCallbackBinding = resolvedCallbackBinding;
+ }
+
+ public List<Binding> getCandidateBindings() {
+ return candidateBindings;
+ }
+
+ public Component getTargetComponent() {
+ return targetComponent;
+ }
+
+ public void setTargetComponent(Component targetComponent) {
+ this.targetComponent = targetComponent;
+ }
+
+ public ComponentService getTargetComponentService() {
+ return targetComponentService;
+ }
+
+ public void setTargetComponentService(ComponentService targetComponentService) {
+ this.targetComponentService = targetComponentService;
+ }
+
+ public Binding getTargetBinding() {
+ return targetBinding;
+ }
+
+ public void setTargetBinding(Binding targetBinding) {
+ this.targetBinding = targetBinding;
+ }
+
+ public Binding getTargetCallbackBinding(){
+ return targetCallbackBinding;
+ }
+
+ public void setTargetCallbackBinding(Binding targetCallbackBinding){
+ this.targetCallbackBinding = targetCallbackBinding;
+ }
+
+ public InterfaceContract getInterfaceContract() {
+ return interfaceContract;
+ }
+
+ public void setInterfaceContract(InterfaceContract interfaceContract) {
+ this.interfaceContract = interfaceContract;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensibleImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensibleImpl.java
new file mode 100644
index 0000000000..9a7ca09e43
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ExtensibleImpl.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Extensible;
+
+/**
+ * Convenience base class for extensible assembly model objects.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class ExtensibleImpl extends BaseImpl implements Extensible {
+ private List<Object> extensions = new ArrayList<Object>();
+
+ /**
+ * Constructs a new base model object.
+ */
+ protected ExtensibleImpl() {
+ }
+
+ public List<Object> getExtensions() {
+ return extensions;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ImplementationImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ImplementationImpl.java
new file mode 100644
index 0000000000..aa75922489
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ImplementationImpl.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.ConfiguredOperation;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.OperationsConfigurator;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+
+/**
+ * Base implementation class of Implementation model interface
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class ImplementationImpl extends ComponentTypeImpl implements Implementation, PolicySetAttachPoint,
+ OperationsConfigurator {
+
+ private List<PolicySet> applicablePolicySets = new ArrayList<PolicySet>();
+ private List<ConfiguredOperation> configuredOperations = new ArrayList<ConfiguredOperation>();
+ private IntentAttachPointType type;
+ private List<PolicySet> policySets = new ArrayList<PolicySet>();
+ private List<Intent> requiredIntents = new ArrayList<Intent>();
+
+ protected ImplementationImpl() {
+ super();
+ }
+
+ public List<PolicySet> getApplicablePolicySets() {
+ return applicablePolicySets;
+ }
+
+ public List<ConfiguredOperation> getConfiguredOperations() {
+ return configuredOperations;
+ }
+
+ public List<PolicySet> getPolicySets() {
+ return policySets;
+ }
+
+ public List<Intent> getRequiredIntents() {
+ return requiredIntents;
+ }
+
+ public IntentAttachPointType getType() {
+ return type;
+ }
+
+ public void setType(IntentAttachPointType type) {
+ this.type = type;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/PropertyImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/PropertyImpl.java
new file mode 100644
index 0000000000..0c1051199f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/PropertyImpl.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.policy.PolicySet;
+
+/**
+ * Represents a property.
+ *
+ * @version $Rev$ $Date$
+ */
+public class PropertyImpl extends AbstractPropertyImpl implements Property, Cloneable {
+ private List<PolicySet> policySets = new ArrayList<PolicySet>();
+ private List<PolicySet> applicablePolicySets = new ArrayList<PolicySet>();
+
+ /**
+ * Constructs a new property.
+ */
+ protected PropertyImpl() {
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+ public List<PolicySet> getPolicySets() {
+ return policySets;
+ }
+
+ public void setPolicySets(List<PolicySet> policySets) {
+ this.policySets = policySets;
+ }
+
+ public List<PolicySet> getApplicablePolicySets() {
+ return applicablePolicySets;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.java
new file mode 100644
index 0000000000..1800222bfb
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ReferenceImpl.java
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Callback;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.policy.PolicySet;
+
+/**
+ * Represents a reference.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReferenceImpl extends AbstractReferenceImpl implements Reference, Cloneable {
+ private List<Binding> bindings = new ArrayList<Binding>();
+ private boolean wiredByImpl;
+ private List<PolicySet> policySets = new ArrayList<PolicySet>();
+ private List<ComponentService> targets = new ArrayList<ComponentService>();
+ private Callback callback;
+ private List<PolicySet> applicablePolicySets = new ArrayList<PolicySet>();
+ private boolean promotionOverride;
+
+ public List<PolicySet> getApplicablePolicySets() {
+ return applicablePolicySets;
+ }
+
+ /**
+ * Constructs a new reference.
+ */
+ protected ReferenceImpl() {
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ ReferenceImpl clone = (ReferenceImpl)super.clone();
+ clone.bindings = new ArrayList<Binding>();
+ clone.bindings.addAll(getBindings());
+ clone.targets = new ArrayList<ComponentService>();
+ clone.targets.addAll(getTargets());
+ return clone;
+ }
+
+ public List<Binding> getBindings() {
+ return bindings;
+ }
+
+ public <B> B getBinding(Class<B> bindingClass) {
+ for (Binding binding : bindings) {
+ if (bindingClass.isInstance(binding)) {
+ return bindingClass.cast(binding);
+ }
+ }
+ return null;
+ }
+
+ public <B> B getCallbackBinding(Class<B> bindingClass) {
+ if (callback != null) {
+ for (Binding binding : callback.getBindings()) {
+ if (bindingClass.isInstance(binding)) {
+ return bindingClass.cast(binding);
+ }
+ }
+ }
+ return null;
+ }
+
+ public boolean isWiredByImpl() {
+ return wiredByImpl;
+ }
+
+ public void setWiredByImpl(boolean wiredByImpl) {
+ this.wiredByImpl = wiredByImpl;
+ }
+
+ public boolean isPromotionOverride() {
+ return promotionOverride;
+ }
+
+ public void setPromotionOverride(boolean promotionOverride) {
+ this.promotionOverride = promotionOverride;
+ }
+
+ public List<PolicySet> getPolicySets() {
+ return policySets;
+ }
+
+ public List<ComponentService> getTargets() {
+ return targets;
+ }
+
+ public Callback getCallback() {
+ return callback;
+ }
+
+ public void setCallback(Callback callback) {
+ this.callback = callback;
+ }
+
+ public void setPolicySets(List<PolicySet> policySets) {
+ this.policySets = policySets;
+ }
+
+ /**
+ * By default return the interface contract for the reference
+ */
+ public InterfaceContract getInterfaceContract(Binding binding){
+ return getInterfaceContract();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ServiceImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ServiceImpl.java
new file mode 100644
index 0000000000..8d745cb7e1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/ServiceImpl.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Callback;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.policy.PolicySet;
+
+/**
+ * Represents a reference.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ServiceImpl extends AbstractServiceImpl implements Service, Cloneable {
+ private List<Binding> bindings = new ArrayList<Binding>();
+ private List<PolicySet> policySets = new ArrayList<PolicySet>();
+ private Callback callback;
+ private List<PolicySet> applicablePolicySets = new ArrayList<PolicySet>();
+
+ public List<PolicySet> getApplicablePolicySets() {
+ return applicablePolicySets;
+ }
+
+ /**
+ * Constructs a new service.
+ */
+ protected ServiceImpl() {
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ ServiceImpl clone = (ServiceImpl)super.clone();
+ clone.bindings = new ArrayList<Binding>();
+ clone.bindings.addAll(getBindings());
+ return clone;
+ }
+
+ public List<Binding> getBindings() {
+ return bindings;
+ }
+
+ public <B> B getBinding(Class<B> bindingClass) {
+ for (Binding binding : bindings) {
+ if (bindingClass.isInstance(binding)) {
+ return bindingClass.cast(binding);
+ }
+ }
+ return null;
+ }
+
+ public <B> B getCallbackBinding(Class<B> bindingClass) {
+ if (callback != null) {
+ for (Binding binding : callback.getBindings()) {
+ if (bindingClass.isInstance(binding)) {
+ return bindingClass.cast(binding);
+ }
+ }
+ }
+ return null;
+ }
+
+ public List<PolicySet> getPolicySets() {
+ return policySets;
+ }
+
+ public Callback getCallback() {
+ return callback;
+ }
+
+ public void setCallback(Callback callback) {
+ this.callback = callback;
+ }
+
+ public void setPolicySets(List<PolicySet> policySets) {
+ this.policySets = policySets;
+ }
+
+ /**
+ * By default return the interface contract for the service
+ */
+ public InterfaceContract getInterfaceContract(Binding binding){
+ return getInterfaceContract();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/WireImpl.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/WireImpl.java
new file mode 100644
index 0000000000..1a7abc8564
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/java/org/apache/tuscany/sca/assembly/impl/WireImpl.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Wire;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicySet;
+
+/**
+ * Represents a wire
+ *
+ * @version $Rev$ $Date$
+ */
+public class WireImpl extends ExtensibleImpl implements Wire, Cloneable {
+ private ComponentReference source;
+ private ComponentService target;
+ private List<Intent> requiredIntents = new ArrayList<Intent>();
+ private List<PolicySet> policySets = new ArrayList<PolicySet>();
+ private List<PolicySet> applicablePolicySets = new ArrayList<PolicySet>();
+
+ public List<PolicySet> getApplicablePolicySets() {
+ return applicablePolicySets;
+ }
+
+ /**
+ * Constructs a new wire.
+ */
+ protected WireImpl() {
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+ public ComponentReference getSource() {
+ return source;
+ }
+
+ public ComponentService getTarget() {
+ return target;
+ }
+
+ public void setSource(ComponentReference source) {
+ this.source = source;
+ }
+
+ public void setTarget(ComponentService target) {
+ this.target = target;
+ }
+
+ public List<Intent> getRequiredIntents() {
+ return requiredIntents;
+ }
+
+ public List<PolicySet> getPolicySets() {
+ return policySets;
+ }
+
+ public IntentAttachPointType getType() {
+ return null;
+ }
+
+ public void setType(IntentAttachPointType type) {
+ }
+
+ public void setPolicySets(List<PolicySet> policySets) {
+ this.policySets = policySets;
+ }
+
+ public void setRequiredIntents(List<Intent> intents) {
+ this.requiredIntents = intents;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.AssemblyFactory b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.AssemblyFactory
new file mode 100644
index 0000000000..859c4bde4b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.AssemblyFactory
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.assembly.DefaultAssemblyFactory \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.EndpointFactory b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.EndpointFactory
new file mode 100644
index 0000000000..8dbff76ad9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.EndpointFactory
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.assembly.DefaultEndpointFactory \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/resources/assembly-validation-messages.properties b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/resources/assembly-validation-messages.properties
new file mode 100644
index 0000000000..6aeda18aab
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/resources/assembly-validation-messages.properties
@@ -0,0 +1,62 @@
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+DuplicateComponentName = Duplicate component name: Composite = {0} Component = {1}
+DuplicateComponentServiceName = Duplicate component service name: Component = {0} Service = {1}
+DuplicateComponentReferenceName = Duplicate component reference name: Component = {0} Reference = {1}
+DuplicateComponentPropertyName = Duplicate component property name: Component = {0} Property = {1}
+NoComponentImplementation = No implementation for component: Component = {0}
+ServiceNotFoundForComponentService = Service not found for component service: Component = {0} Service = {1}
+UnresolvedComponentImplementation = Component implementation not found: Component = {0} Uri = {1}
+DuplicateImplementationPropertyName = Duplicate property name: Component = {0} Property = {1}
+DuplicateImplementationServiceName = Duplicate service name: Component = {0} Service = {1}
+DuplicateImplementationReferenceName = Duplicate reference name: Component = {0} Reference = {1}
+PropertyNotFound = Property not found for component property: Component = {0} Property = {1}
+PropertyMustSupplyIncompatible = Component property mustSupply attribute incompatible with property: Component = {0} Property = {1}
+PropertyMustSupplyNull = No value configured on a mustSupply property: Component = {0} Property = {1}
+PropertyOverrideManyAttribute = Component property many attribute incompatible with property: Component = {0} Property = {1}
+ReferenceNotFound = Reference not found for component reference: Component = {0} Reference = {1}
+ReferenceIncompatibleMultiplicity = Component reference multiplicity incompatible with reference multiplicity: Component = {0} Reference = {1}
+ReferenceIncompatibleInterface = Incompatible interfaces on component reference and target: Composite = {0} Reference = {1} Service = {2}
+ReferenceIncompatibleComponentInterface = Component reference interface incompatible with reference interface: Component = {0} Reference = {1}
+ServiceIncompatibleComponentInterface = Component service interface incompatible with service interface: Component = {0} Service = {1}
+MultipleBindingsForService = Multiple bindings with the same name for a service: Service = {0} Binding name = {1}
+MultipleBindingsForReference = Multiple bindings with the same name for a reference: Reference = {0} Binding name = {1}
+ReferenceWithoutTargets = No targets for reference: Composite = {0} Reference = {1}
+PromotedReferenceNotFound = Promoted component reference not found: Composite = {0} Reference = {1}
+PromotedServiceNotFound = Promoted component service not found: Composite = {0} Service = {1}
+ComponentReferenceTargetNotFound = Component reference target not found, it might be a remote service running elsewhere in the SCA Domain: Composite = {0} Service = {1}
+NoSCABindingAvailableForUnresolvedService = A local service cannot be found for reference {0} target {1} and there is no SCA binding available to represent the unresolved target
+NoMatchingBinding = Component reference {0} does not have a binding which matches the bindings of service {1}
+NoMatchingCallbackBinding = Component reference {0} does not have a callback binding which matches the callback bindings of service {1}
+ReferenceEndPointMixWithTarget = Reference {0} must not specify endpoints using both target attribute and with binding uri attribute
+PolicyRelatedException = Policy Related Exception occured due to : {0}
+CompositeAlreadyIncluded = Composite {0} has already been included.
+ComponentReferenceMoreWire = Component reference {0} has more than one wires
+WireTargetNotFound = Wire target not found : {0}
+WireSourceNotFound = Wire source not found : {0}
+WireIncompatibleInterface = Incompatible interfaces on wire source and target : source = {0} target = {1}
+ComponentIncompatibleInterface = Incompatible interfaces on component reference and target : reference = {0} target = {1}
+TooManyReferenceTargets = Too many targets on reference: {0}
+ReferenceInterfaceNotSubSet = Interface of composite reference {0} must be compatible with the interface declared by promoted component reference.
+ServiceInterfaceNotSubSet = Interface of composite service {0} must be subset of the interface declared by promoted component service.
+NoComponentReferenceTarget = No target services found for the component reference to be autowired: {0}
+NoTypeForComponentProperty = No type specified on component property: Component = {0} Property = {1}
+URLSyntaxException = URLSyntaxException when creating binding URI at component = {0} service = {1} binding = {2} \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/main/resources/assembly-validation-messages_it.properties b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/resources/assembly-validation-messages_it.properties
new file mode 100644
index 0000000000..b94d37ba2d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/main/resources/assembly-validation-messages_it.properties
@@ -0,0 +1,30 @@
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+DuplicateComponentName = Nome del componente duplicato: Composite = {0} Component = {1}
+DuplicateComponentServiceName = Nome del servizio del componente duplicato: Component = {0} Service = {1}
+DuplicateComponentReferenceName = Nome del reference del componente duplicato: Component = {0} Reference = {1}
+DuplicateComponentPropertyName = Nome della property del componente duplicato: Component = {0} Property = {1}
+NoComponentImplementation = Implementazione insistente per il componente: Component = {0}
+ServiceNotFoundForComponentService = Servizio non trovato per il componente: Component = {0} Service = {1}
+UnresolvedComponentImplementation = Implementazione del componente non trovata: Component = {0} Uri = {1}
+DuplicateImplementationPropertyName = Nome della property del componente duplicata: Component = {0} Property = {1}
+DuplicateImplementationReferenceName = Nome del riferimento duplicato: Component = {0} Reference = {1}
+PropertyNotFound = Property non trovata per il componente: Component = {0} Property = {1}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/AssemblyFactoryTestCase.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/AssemblyFactoryTestCase.java
new file mode 100644
index 0000000000..8a3a89aba4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/AssemblyFactoryTestCase.java
@@ -0,0 +1,209 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+
+/**
+ * Test building of assembly model instances using the assembly factory.
+ *
+ * @version $Rev$ $Date$
+ */
+public class AssemblyFactoryTestCase extends TestCase {
+
+ private AssemblyFactory assemblyFactory;
+
+ @Override
+ public void setUp() throws Exception {
+ assemblyFactory = new DefaultAssemblyFactory();
+ }
+
+ public void testCreateComponent() {
+ createComponent("AccountServiceComponent1");
+ }
+
+ public void testCreateComponentType() {
+ createComponentType();
+ }
+
+ public void testCreateComposite() {
+ createComposite();
+ }
+
+ public void testCreateConstrainingType() {
+ createConstrainingType();
+ }
+
+ /**
+ * Create a composite
+ */
+ Composite createComposite() {
+ Composite c = assemblyFactory.createComposite();
+
+ Component c1 = createComponent("AccountServiceComponent1");
+ c.getComponents().add(c1);
+ Component c2 = createComponent("AccountServiceComponent2");
+ c.getComponents().add(c2);
+
+ Wire w = assemblyFactory.createWire();
+ w.setSource(c1.getReferences().get(0));
+ w.setTarget(c2.getServices().get(0));
+ c.getWires().add(w);
+
+ CompositeService cs = assemblyFactory.createCompositeService();
+ cs.setName("AccountService");
+ cs.setPromotedService(c1.getServices().get(0));
+ cs.setInterfaceContract(new TestInterfaceContract(assemblyFactory));
+ c.getServices().add(cs);
+ cs.getBindings().add(new TestBinding(assemblyFactory));
+
+ CompositeReference cr = assemblyFactory.createCompositeReference();
+ cr.setName("StockQuoteService");
+ cr.getPromotedReferences().add(c2.getReferences().get(1));
+ cr.setInterfaceContract(new TestInterfaceContract(assemblyFactory));
+ c.getReferences().add(cr);
+ cr.getBindings().add(new TestBinding(assemblyFactory));
+
+ return c;
+ }
+
+ /**
+ * Create a new component
+ */
+ Component createComponent(String name) {
+ Component c = assemblyFactory.createComponent();
+ c.setName(name);
+
+ ConstrainingType constraint = createConstrainingType();
+ c.setConstrainingType(constraint);
+
+ Implementation i = new TestImplementation(assemblyFactory);
+ c.setImplementation(i);
+
+ ComponentProperty p = assemblyFactory.createComponentProperty();
+ p.setName("currency");
+ p.setValue("USD");
+ p.setMustSupply(true);
+ p.setXSDType(new QName("", ""));
+ p.setProperty(i.getProperties().get(0));
+ c.getProperties().add(p);
+
+ ComponentReference ref1 = assemblyFactory.createComponentReference();
+ ref1.setName("accountDataService");
+ ref1.setMultiplicity(Multiplicity.ONE_ONE);
+ ref1.setInterfaceContract(new TestInterfaceContract(assemblyFactory));
+ ref1.setReference(i.getReferences().get(0));
+ c.getReferences().add(ref1);
+ ref1.getBindings().add(new TestBinding(assemblyFactory));
+
+ ComponentReference ref2 = assemblyFactory.createComponentReference();
+ ref2.setName("stockQuoteService");
+ ref2.setMultiplicity(Multiplicity.ONE_ONE);
+ ref2.setInterfaceContract(new TestInterfaceContract(assemblyFactory));
+ ref2.setReference(i.getReferences().get(1));
+ c.getReferences().add(ref2);
+ ref2.getBindings().add(new TestBinding(assemblyFactory));
+
+ ComponentService s = assemblyFactory.createComponentService();
+ s.setName("AccountService");
+ s.setInterfaceContract(new TestInterfaceContract(assemblyFactory));
+ s.setService(i.getServices().get(0));
+ c.getServices().add(s);
+ s.getBindings().add(new TestBinding(assemblyFactory));
+
+ return c;
+ }
+
+ /**
+ * Create a new component type
+ *
+ * @return
+ */
+ ComponentType createComponentType() {
+ ComponentType ctype = assemblyFactory.createComponentType();
+
+ Property p = assemblyFactory.createProperty();
+ p.setName("currency");
+ p.setValue("USD");
+ p.setMustSupply(true);
+ p.setXSDType(new QName("", ""));
+ ctype.getProperties().add(p);
+
+ Reference ref1 = assemblyFactory.createReference();
+ ref1.setName("accountDataService");
+ ref1.setInterfaceContract(new TestInterfaceContract(assemblyFactory));
+ ref1.setMultiplicity(Multiplicity.ONE_ONE);
+ ctype.getReferences().add(ref1);
+ ref1.getBindings().add(new TestBinding(assemblyFactory));
+
+ Reference ref2 = assemblyFactory.createReference();
+ ref2.setName("stockQuoteService");
+ ref2.setInterfaceContract(new TestInterfaceContract(assemblyFactory));
+ ref2.setMultiplicity(Multiplicity.ONE_ONE);
+ ctype.getReferences().add(ref2);
+ ref2.getBindings().add(new TestBinding(assemblyFactory));
+
+ Service s = assemblyFactory.createService();
+ s.setName("AccountService");
+ s.setInterfaceContract(new TestInterfaceContract(assemblyFactory));
+ ctype.getServices().add(s);
+ s.getBindings().add(new TestBinding(assemblyFactory));
+
+ return ctype;
+ }
+
+ /**
+ * Create a new constraining type
+ *
+ * @return
+ */
+ ConstrainingType createConstrainingType() {
+ ConstrainingType ctype = assemblyFactory.createConstrainingType();
+
+ AbstractProperty p = assemblyFactory.createAbstractProperty();
+ p.setName("currency");
+ p.setValue("USD");
+ p.setMustSupply(true);
+ p.setXSDType(new QName("", ""));
+ ctype.getProperties().add(p);
+
+ AbstractReference ref1 = assemblyFactory.createAbstractReference();
+ ref1.setName("accountDataService");
+ ref1.setInterfaceContract(new TestInterfaceContract(assemblyFactory));
+ ref1.setMultiplicity(Multiplicity.ONE_ONE);
+ ctype.getReferences().add(ref1);
+
+ AbstractReference ref2 = assemblyFactory.createAbstractReference();
+ ref2.setName("stockQuoteService");
+ ref2.setInterfaceContract(new TestInterfaceContract(assemblyFactory));
+ ref2.setMultiplicity(Multiplicity.ONE_ONE);
+ ctype.getReferences().add(ref2);
+
+ AbstractService s = assemblyFactory.createAbstractService();
+ s.setName("AccountService");
+ s.setInterfaceContract(new TestInterfaceContract(assemblyFactory));
+ ctype.getServices().add(s);
+
+ return ctype;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestBinding.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestBinding.java
new file mode 100644
index 0000000000..5e0a2335d1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestBinding.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+
+/**
+ * A test interface model.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestBinding implements Binding {
+ public TestBinding(AssemblyFactory factory) {
+ }
+
+ public String getName() {
+ return null;
+ }
+
+ public String getURI() {
+ return "http://test";
+ }
+
+ public void setName(String name) {
+ }
+
+ public void setURI(String uri) {
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ }
+
+ public boolean isUnresolved() {
+ return false;
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestImplementation.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestImplementation.java
new file mode 100644
index 0000000000..19702954c9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestImplementation.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.impl.ImplementationImpl;
+
+/**
+ * A test component implementation model.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestImplementation extends ImplementationImpl implements Implementation {
+ public TestImplementation(AssemblyFactory factory) {
+
+ Property p = factory.createProperty();
+ p.setName("currency");
+ p.setValue("USD");
+ p.setMustSupply(true);
+ p.setXSDType(new QName("", ""));
+ getProperties().add(p);
+
+ Reference ref1 = factory.createReference();
+ ref1.setName("accountDataService");
+ ref1.setMultiplicity(Multiplicity.ONE_ONE);
+ getReferences().add(ref1);
+ ref1.getBindings().add(new TestBinding(factory));
+
+ Reference ref2 = factory.createReference();
+ ref2.setName("stockQuoteService");
+ ref2.setMultiplicity(Multiplicity.ONE_ONE);
+ ref2.setInterfaceContract(new TestInterfaceContract(factory));
+ getReferences().add(ref2);
+ ref2.getBindings().add(new TestBinding(factory));
+
+ Service s = factory.createService();
+ s.setName("AccountService");
+ s.setInterfaceContract(new TestInterfaceContract(factory));
+ getServices().add(s);
+ s.getBindings().add(new TestBinding(factory));
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterface.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterface.java
new file mode 100644
index 0000000000..dbe0cb8225
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterface.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.impl.InterfaceImpl;
+
+/**
+ * A test interface model.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestInterface extends InterfaceImpl implements Interface {
+
+ public TestInterface(AssemblyFactory factory) {
+
+ setRemotable(true);
+
+ Operation operation = new TestOperation();
+ operation.setName("test");
+ getOperations().add(operation);
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterfaceContract.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterfaceContract.java
new file mode 100644
index 0000000000..ee6b95edc9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestInterfaceContract.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractImpl;
+
+/**
+ * A test interface contract model.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestInterfaceContract extends InterfaceContractImpl implements InterfaceContract {
+
+ public TestInterfaceContract(AssemblyFactory factory) {
+
+ TestInterface testInterface = new TestInterface(factory);
+ setInterface(testInterface);
+
+ TestInterface testCallbackInterface = new TestInterface(factory);
+ setCallbackInterface(testCallbackInterface);
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestOperation.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestOperation.java
new file mode 100644
index 0000000000..d94a7e93a3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/TestOperation.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.assembly;
+
+import org.apache.tuscany.sca.interfacedef.impl.OperationImpl;
+
+/**
+ * A test operation model.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestOperation extends OperationImpl {
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.java
new file mode 100644
index 0000000000..fabafc998b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/CompositeBuilderTestCase.java
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeReference;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+
+/**
+ * Test the CompositeBuilder.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeBuilderTestCase extends TestCase {
+
+ private AssemblyFactory assemblyFactory;
+
+ @Override
+ protected void setUp() throws Exception {
+ assemblyFactory = new DefaultAssemblyFactory();
+ }
+
+ public void testFuseIncludes() throws Exception {
+ Composite c1 = assemblyFactory.createComposite();
+ c1.setName(new QName("http://foo", "C1"));
+ Component a = assemblyFactory.createComponent();
+ a.setName("a");
+ c1.getComponents().add(a);
+ CompositeService s = assemblyFactory.createCompositeService();
+ s.setName("s");
+ c1.getServices().add(s);
+ CompositeReference r = assemblyFactory.createCompositeReference();
+ r.setName("r");
+ c1.getReferences().add(r);
+
+ Composite c2 = assemblyFactory.createComposite();
+ c2.setName(new QName("http://foo", "C2"));
+ c1.getIncludes().add(c2);
+ Component b = assemblyFactory.createComponent();
+ b.setName("b");
+ c2.getComponents().add(b);
+
+ Composite c = assemblyFactory.createComposite();
+ c.setName(new QName("http://foo", "C"));
+ c.getIncludes().add(c1);
+
+ new CompositeIncludeBuilderImpl(null).build(c);
+
+ assertTrue(c.getComponents().get(0).getName().equals("a"));
+ assertTrue(c.getComponents().get(1).getName().equals("b"));
+ assertTrue(c.getServices().get(0).getName().equals("s"));
+ assertTrue(c.getReferences().get(0).getName().equals("r"));
+ }
+
+ public void testExpandComposites() throws Exception {
+ Composite c1 = assemblyFactory.createComposite();
+ c1.setName(new QName("http://foo", "C1"));
+ Component a = assemblyFactory.createComponent();
+ a.setName("a");
+ c1.getComponents().add(a);
+ CompositeService s = assemblyFactory.createCompositeService();
+ s.setName("s");
+ c1.getServices().add(s);
+ CompositeReference r = assemblyFactory.createCompositeReference();
+ r.setName("r");
+ c1.getReferences().add(r);
+
+ Composite c2 = assemblyFactory.createComposite();
+ c2.setName(new QName("http://foo", "C2"));
+ Component b = assemblyFactory.createComponent();
+ b.setName("b");
+ c2.getComponents().add(b);
+
+ Composite c = assemblyFactory.createComposite();
+ c.setName(new QName("http://foo", "C"));
+ Component x = assemblyFactory.createComponent();
+ x.setName("x");
+ x.setImplementation(c1);
+ c.getComponents().add(x);
+ Component y = assemblyFactory.createComponent();
+ y.setName("y");
+ y.setImplementation(c2);
+ c.getComponents().add(y);
+ Component z = assemblyFactory.createComponent();
+ z.setName("z");
+ z.setImplementation(c1);
+ c.getComponents().add(z);
+
+ new CompositeCloneBuilderImpl(null).build(c);
+
+ assertTrue(c.getComponents().get(0).getImplementation() != c1);
+ assertTrue(c.getComponents().get(1).getImplementation() != c2);
+ assertTrue(c.getComponents().get(2).getImplementation() != c1);
+
+ Composite i = (Composite)c.getComponents().get(0).getImplementation();
+ assertTrue(i.getComponents().get(0) != a);
+ assertTrue(i.getComponents().get(0).getName().equals("a"));
+ assertTrue(i.getServices().get(0).getName().equals("s"));
+ assertTrue(i.getServices().get(0) != s);
+ assertTrue(i.getReferences().get(0).getName().equals("r"));
+ assertTrue(i.getReferences().get(0) != r);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtilTestCase.java b/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtilTestCase.java
new file mode 100644
index 0000000000..82b1fd8665
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/assembly/src/test/java/org/apache/tuscany/sca/assembly/builder/impl/PrintUtilTestCase.java
@@ -0,0 +1,229 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.assembly.builder.impl;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.AbstractProperty;
+import org.apache.tuscany.sca.assembly.AbstractReference;
+import org.apache.tuscany.sca.assembly.AbstractService;
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentProperty;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeReference;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.Multiplicity;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.TestBinding;
+import org.apache.tuscany.sca.assembly.TestImplementation;
+import org.apache.tuscany.sca.assembly.TestInterfaceContract;
+import org.apache.tuscany.sca.assembly.Wire;
+import org.junit.Test;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PrintUtilTestCase {
+
+ private AssemblyFactory factory = new DefaultAssemblyFactory();
+
+ /**
+ * Create a composite
+ */
+ Composite createComposite() {
+ Composite c = factory.createComposite();
+
+ Component c1 = createComponent("AccountServiceComponent1");
+ c.getComponents().add(c1);
+ Component c2 = createComponent("AccountServiceComponent2");
+ c.getComponents().add(c2);
+
+ Wire w = factory.createWire();
+ w.setSource(c1.getReferences().get(0));
+ w.setTarget(c2.getServices().get(0));
+ c.getWires().add(w);
+
+ CompositeService cs = factory.createCompositeService();
+ cs.setName("AccountService");
+ cs.setPromotedService(c1.getServices().get(0));
+ cs.setInterfaceContract(new TestInterfaceContract(factory));
+ c.getServices().add(cs);
+ cs.getBindings().add(new TestBinding(factory));
+
+ CompositeReference cr = factory.createCompositeReference();
+ cr.setName("StockQuoteService");
+ cr.getPromotedReferences().add(c2.getReferences().get(1));
+ cr.setInterfaceContract(new TestInterfaceContract(factory));
+ c.getReferences().add(cr);
+ cr.getBindings().add(new TestBinding(factory));
+
+ return c;
+ }
+
+ /**
+ * Create a new component
+ */
+ Component createComponent(String name) {
+ Component c = factory.createComponent();
+ c.setName(name);
+
+ ConstrainingType constraint = createConstrainingType();
+ c.setConstrainingType(constraint);
+
+ Implementation i = new TestImplementation(factory);
+ c.setImplementation(i);
+
+ ComponentProperty p = factory.createComponentProperty();
+ p.setName("currency");
+ p.setValue("USD");
+ p.setMustSupply(true);
+ p.setXSDType(new QName("", ""));
+ p.setProperty(i.getProperties().get(0));
+ c.getProperties().add(p);
+
+ ComponentReference ref1 = factory.createComponentReference();
+ ref1.setName("accountDataService");
+ ref1.setMultiplicity(Multiplicity.ONE_ONE);
+ ref1.setInterfaceContract(new TestInterfaceContract(factory));
+ ref1.setReference(i.getReferences().get(0));
+ c.getReferences().add(ref1);
+ ref1.getBindings().add(new TestBinding(factory));
+
+ ComponentReference ref2 = factory.createComponentReference();
+ ref2.setName("stockQuoteService");
+ ref2.setMultiplicity(Multiplicity.ONE_ONE);
+ ref2.setInterfaceContract(new TestInterfaceContract(factory));
+ ref2.setReference(i.getReferences().get(1));
+ c.getReferences().add(ref2);
+ ref2.getBindings().add(new TestBinding(factory));
+
+ ComponentService s = factory.createComponentService();
+ s.setName("AccountService");
+ s.setInterfaceContract(new TestInterfaceContract(factory));
+ s.setService(i.getServices().get(0));
+ c.getServices().add(s);
+ s.getBindings().add(new TestBinding(factory));
+
+ return c;
+ }
+
+ /**
+ * Create a new component type
+ *
+ * @return
+ */
+ ComponentType createComponentType() {
+ ComponentType ctype = factory.createComponentType();
+
+ Property p = factory.createProperty();
+ p.setName("currency");
+ p.setValue("USD");
+ p.setMustSupply(true);
+ p.setXSDType(new QName("", ""));
+ ctype.getProperties().add(p);
+
+ Reference ref1 = factory.createReference();
+ ref1.setName("accountDataService");
+ ref1.setInterfaceContract(new TestInterfaceContract(factory));
+ ref1.setMultiplicity(Multiplicity.ONE_ONE);
+ ctype.getReferences().add(ref1);
+ ref1.getBindings().add(new TestBinding(factory));
+
+ Reference ref2 = factory.createReference();
+ ref2.setName("stockQuoteService");
+ ref2.setInterfaceContract(new TestInterfaceContract(factory));
+ ref2.setMultiplicity(Multiplicity.ONE_ONE);
+ ctype.getReferences().add(ref2);
+ ref2.getBindings().add(new TestBinding(factory));
+
+ Service s = factory.createService();
+ s.setName("AccountService");
+ s.setInterfaceContract(new TestInterfaceContract(factory));
+ ctype.getServices().add(s);
+ s.getBindings().add(new TestBinding(factory));
+
+ return ctype;
+ }
+
+ /**
+ * Create a new constraining type
+ *
+ * @return
+ */
+ ConstrainingType createConstrainingType() {
+ ConstrainingType ctype = factory.createConstrainingType();
+
+ AbstractProperty p = factory.createAbstractProperty();
+ p.setName("currency");
+ p.setValue("USD");
+ p.setMustSupply(true);
+ p.setXSDType(new QName("", ""));
+ ctype.getProperties().add(p);
+
+ AbstractReference ref1 = factory.createAbstractReference();
+ ref1.setName("accountDataService");
+ ref1.setInterfaceContract(new TestInterfaceContract(factory));
+ ref1.setMultiplicity(Multiplicity.ONE_ONE);
+ ctype.getReferences().add(ref1);
+
+ AbstractReference ref2 = factory.createAbstractReference();
+ ref2.setName("stockQuoteService");
+ ref2.setInterfaceContract(new TestInterfaceContract(factory));
+ ref2.setMultiplicity(Multiplicity.ONE_ONE);
+ ctype.getReferences().add(ref2);
+
+ AbstractService s = factory.createAbstractService();
+ s.setName("AccountService");
+ s.setInterfaceContract(new TestInterfaceContract(factory));
+ ctype.getServices().add(s);
+
+ return ctype;
+ }
+
+ @Test
+ public void testPrint1() {
+ Composite composite = createComposite();
+ StringWriter sw = new StringWriter();
+ PrintUtil p = new PrintUtil(new PrintWriter(sw), true);
+ p.print(composite);
+ // System.out.println(sw.toString());
+ }
+
+ @Test
+ public void testPrint2() {
+ Composite composite = createComposite();
+ StringWriter sw = new StringWriter();
+ PrintUtil p = new PrintUtil(new PrintWriter(sw), false);
+ p.print(composite);
+ // System.out.println(sw.toString());
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/LICENSE b/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/META-INF/README b/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/NOTICE b/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/pom.xml b/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/pom.xml
new file mode 100644
index 0000000000..e27926d1ab
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/pom.xml
@@ -0,0 +1,77 @@
+<?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.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>tuscany-binding-sca-xml</artifactId>
+ <name>Apache Tuscany SCA Default Binding XML Model</name>
+
+ <dependencies>
+
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-binding-sca</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>2.2</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.binding.sca.xml</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.binding.sca.xml*</Export-Package>
+ <Import-Package>org.apache.tuscany.sca.binding.sca.impl,*</Import-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/main/java/org/apache/tuscany/sca/binding/sca/xml/SCABindingProcessor.java b/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/main/java/org/apache/tuscany/sca/binding/sca/xml/SCABindingProcessor.java
new file mode 100644
index 0000000000..a3e582c82e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/main/java/org/apache/tuscany/sca/binding/sca/xml/SCABindingProcessor.java
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.sca.xml;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.xml.Constants;
+import org.apache.tuscany.sca.assembly.xml.PolicyAttachPointProcessor;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+
+/**
+ * A processor to read the XML that describes the SCA binding.
+ *
+ * @version $Rev$ $Date$
+ */
+
+public class SCABindingProcessor implements StAXArtifactProcessor<SCABinding>, Constants{
+
+ private PolicyFactory policyFactory;
+ private SCABindingFactory scaBindingFactory;
+ private PolicyAttachPointProcessor policyProcessor;
+ private IntentAttachPointTypeFactory intentAttachPointTypeFactory;
+ private Monitor monitor;
+
+ protected static final String BINDING_SCA = "binding.sca";
+ protected static final QName BINDING_SCA_QNAME = new QName(Constants.SCA10_NS, BINDING_SCA);
+
+ public SCABindingProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
+ this.policyFactory = modelFactories.getFactory(PolicyFactory.class);
+ this.scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class);
+ policyProcessor = new PolicyAttachPointProcessor(policyFactory);
+ this.intentAttachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class);
+ this.monitor = monitor;
+ }
+
+ public QName getArtifactType() {
+ return BINDING_SCA_QNAME;
+ }
+
+ public Class<SCABinding> getModelType() {
+ return SCABinding.class;
+ }
+
+ public SCABinding read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ SCABinding scaBinding = scaBindingFactory.createSCABinding();
+ IntentAttachPointType bindingType = intentAttachPointTypeFactory.createBindingType();
+ bindingType.setName(getArtifactType());
+ bindingType.setUnresolved(true);
+ ((PolicySetAttachPoint)scaBinding).setType(bindingType);
+
+ // Read policies
+ policyProcessor.readPolicies(scaBinding, reader);
+
+ // Read binding name
+ String name = reader.getAttributeValue(null, NAME);
+ if (name != null) {
+ scaBinding.setName(name);
+ }
+
+ // Read binding URI
+ String uri = reader.getAttributeValue(null, URI);
+ if (uri != null) {
+ scaBinding.setURI(uri);
+ }
+
+ // Skip to end element
+ while (reader.hasNext()) {
+ if (reader.next() == END_ELEMENT && BINDING_SCA_QNAME.equals(reader.getName())) {
+ break;
+ }
+ }
+ return scaBinding;
+ }
+
+ public void resolve(SCABinding model, ModelResolver resolver) throws ContributionResolveException {
+ policyProcessor.resolvePolicies(model, resolver);
+ }
+
+ public void write(SCABinding scaBinding, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+
+ // Write <binding.sca>
+ policyProcessor.writePolicyPrefixes(scaBinding, writer);
+ writer.writeStartElement(Constants.SCA10_NS, BINDING_SCA);
+ policyProcessor.writePolicyAttributes(scaBinding, writer);
+
+ // Write binding name
+ if (scaBinding.getName() != null) {
+ writer.writeAttribute(NAME, scaBinding.getName());
+ }
+
+ // Write binding URI
+ if (scaBinding.getURI() != null) {
+ writer.writeAttribute(URI, scaBinding.getURI());
+ }
+
+ writer.writeEndElement();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
new file mode 100644
index 0000000000..bc9f9b7d62
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for the artifact processor extension
+org.apache.tuscany.sca.binding.sca.xml.SCABindingProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#binding.sca,model=org.apache.tuscany.sca.binding.sca.impl.SCABindingImpl
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java b/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java
new file mode 100644
index 0000000000..a7c7c15eaa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/ReadTestCase.java
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apace.tuscany.sca.binding.sca.xml;
+
+import java.io.InputStream;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl;
+import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
+
+/**
+ * Test reading WSDL interfaces.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReadTestCase extends TestCase {
+
+ private XMLInputFactory inputFactory;
+ private StAXArtifactProcessor<Object> staxProcessor;
+ private CompositeBuilder compositeBuilder;
+
+ @Override
+ public void setUp() throws Exception {
+ ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+
+ inputFactory = XMLInputFactory.newInstance();
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null);
+
+ ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ SCABindingFactory scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class);
+ IntentAttachPointTypeFactory attachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class);
+
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class);
+ compositeBuilder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, attachPointTypeFactory, mapper, null);
+
+ }
+
+ public void testReadComponentType() throws Exception {
+ InputStream is = getClass().getResourceAsStream("/CalculatorServiceImpl.componentType");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ ComponentType componentType = (ComponentType)staxProcessor.read(reader);
+ assertNotNull(componentType);
+
+ SCABinding referenceSCABinding = (SCABinding) componentType.getReferences().get(0).getBindings().get(0);
+ assertNotNull(referenceSCABinding);
+
+ SCABinding serviceSCABinding = (SCABinding) componentType.getServices().get(0).getBindings().get(0);
+ assertNotNull(serviceSCABinding);
+
+ //new PrintUtil(System.out).print(componentType);
+ }
+
+ public void testReadComposite() throws Exception {
+ InputStream is = getClass().getResourceAsStream("/Calculator.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = (Composite)staxProcessor.read(reader);
+ assertNotNull(composite);
+
+ compositeBuilder.build(composite);
+
+ SCABinding referenceSCABinding = (SCABinding) composite.getComponents().get(0).getReferences().get(0).getBindings().get(0);
+ SCABinding serviceSCABinding = (SCABinding) composite.getComponents().get(1).getServices().get(0).getBindings().get(0);
+
+ Assert.assertNotNull(referenceSCABinding);
+ Assert.assertNotNull(serviceSCABinding);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/WriteTestCase.java b/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/WriteTestCase.java
new file mode 100644
index 0000000000..8ceaecc9c7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/test/java/org/apace/tuscany/sca/binding/sca/xml/WriteTestCase.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apace.tuscany.sca.binding.sca.xml;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+
+/**
+ * Test reading/write WSDL interfaces.
+ *
+ * @version $Rev$ $Date$
+ */
+public class WriteTestCase extends TestCase {
+
+ private StAXArtifactProcessor<Object> staxProcessor;
+ private XMLInputFactory inputFactory;
+ private XMLOutputFactory outputFactory;
+
+ @Override
+ public void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ inputFactory = XMLInputFactory.newInstance();
+ outputFactory = XMLOutputFactory.newInstance();
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null);
+ }
+
+ public void testReadWriteComponentType() throws Exception {
+ InputStream is = getClass().getResourceAsStream("/CalculatorServiceImpl.componentType");
+ ComponentType componentType = (ComponentType)staxProcessor.read(inputFactory.createXMLStreamReader(is));
+ assertNotNull(componentType);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(componentType, outputFactory.createXMLStreamWriter(bos));
+ assertEquals("<?xml version='1.0' encoding='UTF-8'?><componentType xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns1=\"http://www.osoa.org/xmlns/sca/1.0\"><service name=\"CalculatorService\"><binding.sca /><interface.java xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" class=\"calculator.CalculatorService\" /></service><reference name=\"addService\"><binding.sca /><interface.java xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" class=\"calculator.AddService\" /></reference></componentType>",
+ bos.toString());
+ }
+
+ public void testReadWriteComposite() throws Exception {
+ InputStream is = getClass().getResourceAsStream("/Calculator.composite");
+ Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is));
+ assertNotNull(composite);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos));
+ assertEquals("<?xml version='1.0' encoding='UTF-8'?><composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns1=\"http://www.osoa.org/xmlns/sca/1.0\" targetNamespace=\"http://calc\" name=\"Calculator\"><service name=\"CalculatorService\" promote=\"CalculatorServiceComponent\"><binding.sca /><interface.java xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" interface=\"calculator.CalculatorService\" /></service><component name=\"CalculatorServiceComponent\"><reference name=\"addService\" target=\"AddServiceComponent\"><binding.sca /></reference><reference name=\"subtractService\" target=\"SubtractServiceComponent\" /><reference name=\"multiplyService\" target=\"MultiplyServiceComponent\" /><reference name=\"divideService\" target=\"DivideServiceComponent\" /></component><component name=\"AddServiceComponent\"><service><binding.sca /><interface.java xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" interface=\"calculator.AddService\" /></service></component><component name=\"SubtractServiceComponent\" /><component name=\"MultiplyServiceComponent\" /><component name=\"DivideServiceComponent\" /></composite>",
+ bos.toString() );
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/test/resources/Calculator.composite b/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/test/resources/Calculator.composite
new file mode 100644
index 0000000000..9028662d05
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/test/resources/Calculator.composite
@@ -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:calc="http://calc"
+ targetNamespace="http://calc"
+ name="Calculator">
+ <service name="CalculatorService" promote="CalculatorServiceComponent">
+ <interface.java interface="calculator.CalculatorService"/>
+ <binding.sca/>
+ </service>
+
+ <component name="CalculatorServiceComponent">
+ <implementation.java class="calculator.CalculatorServiceImpl"/>
+ <reference name="addService" target="AddServiceComponent">
+ <binding.sca/>
+ </reference>
+ <reference name="subtractService" target="SubtractServiceComponent"/>
+ <reference name="multiplyService" target="MultiplyServiceComponent"/>
+ <reference name="divideService" target="DivideServiceComponent"/>
+ </component>
+
+ <component name="AddServiceComponent">
+ <implementation.java class="calculator.AddServiceImpl"/>
+ <service>
+ <interface.java interface="calculator.AddService"/>
+ <binding.sca/>
+ </service>
+ </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/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/test/resources/CalculatorServiceImpl.componentType b/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/test/resources/CalculatorServiceImpl.componentType
new file mode 100644
index 0000000000..f02e7d6fc0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca-xml/src/test/resources/CalculatorServiceImpl.componentType
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<componentType xmlns="http://www.osoa.org/xmlns/sca/1.0">
+
+ <service name="CalculatorService">
+ <interface.java class="calculator.CalculatorService" />
+ <binding.sca/>
+ </service>
+
+ <reference name="addService">
+ <interface.java class="calculator.AddService" />
+ <binding.sca/>
+ </reference>
+
+</componentType>
+ \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca/LICENSE b/sca-java-1.x/branches/sca-android/modules/binding-sca/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca/META-INF/README b/sca-java-1.x/branches/sca-android/modules/binding-sca/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca/NOTICE b/sca-java-1.x/branches/sca-android/modules/binding-sca/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca/pom.xml b/sca-java-1.x/branches/sca-android/modules/binding-sca/pom.xml
new file mode 100644
index 0000000000..c8af2d4628
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca/pom.xml
@@ -0,0 +1,93 @@
+<?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.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>tuscany-binding-sca</artifactId>
+ <name>Apache Tuscany SCA Default Binding Model</name>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core-spi</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution-impl</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>2.2</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.binding.sca</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.binding.sca*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/DistributedSCABinding.java b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/DistributedSCABinding.java
new file mode 100644
index 0000000000..167c93e86d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/DistributedSCABinding.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.binding.sca;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.SCABinding;
+
+
+/**
+ * Represents an SCA binding used in the distributed runtime.
+ * At the moment just provides us with a sensibly named type
+ * against which the distributed sca binding providers can be registered
+ *
+ * @version $Rev: 556322 $ $Date: 2007-07-14 19:53:15 +0100 (Sat, 14 Jul 2007) $
+ */
+public interface DistributedSCABinding extends Binding {
+
+ SCABinding getSCABinding();
+ void setSCABinding(SCABinding scaBinding);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/SCABindingDefinitionsProvider.java b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/SCABindingDefinitionsProvider.java
new file mode 100644
index 0000000000..bd24d4b14c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/SCABindingDefinitionsProvider.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.sca;
+
+import java.net.URI;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedExceptionAction;
+
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.provider.SCADefinitionsProvider;
+import org.apache.tuscany.sca.provider.SCADefinitionsProviderException;
+
+/**
+ * Provider for Policy Intents and PolicySet definitions related to security
+ *
+ * @version $Rev$ $Date$
+ */
+public class SCABindingDefinitionsProvider implements SCADefinitionsProvider {
+ private String definitionsFile = "org/apache/tuscany/sca/binding/sca/definitions.xml";
+ URLArtifactProcessor urlArtifactProcessor = null;
+
+ public SCABindingDefinitionsProvider(ExtensionPointRegistry registry) {
+ URLArtifactProcessorExtensionPoint documentProcessors = registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ urlArtifactProcessor = (URLArtifactProcessor)documentProcessors.getProcessor(SCADefinitions.class);
+ }
+
+ public SCADefinitions getSCADefinition() throws SCADefinitionsProviderException {
+ // Allow privileged access to load resource. Requires RuntimePermssion in security policy.
+ final URL definitionsFileUrl = AccessController.doPrivileged(new PrivilegedAction<URL>() {
+ public URL run() {
+ return getClass().getClassLoader().getResource(definitionsFile);
+ }
+ });
+
+ SCADefinitions scaDefn = null;
+ try {
+ final URI uri = new URI(definitionsFile);
+ // Allow bindings to read properties. Requires PropertyPermission read in security policy.
+ scaDefn = AccessController.doPrivileged(new PrivilegedExceptionAction<SCADefinitions>() {
+ public SCADefinitions run() throws ContributionReadException {
+ return (SCADefinitions)urlArtifactProcessor.read(null, uri, definitionsFileUrl);
+ }
+ });
+ } catch (Exception e) {
+ throw new SCADefinitionsProviderException(e);
+ }
+ return scaDefn;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/DistributedSCABindingImpl.java b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/DistributedSCABindingImpl.java
new file mode 100644
index 0000000000..43b0cd8f4e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/DistributedSCABindingImpl.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.binding.sca.impl;
+
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.binding.sca.DistributedSCABinding;
+
+/**
+ * The Distributed SCA binding wrapper for the SCA binding model object. This is currently
+ * just used to locate the remote binding extension and pass the SCA binding to the remote
+ * extension. It isn't used in the model itself
+ *
+ * @version $Rev: 564307 $ $Date: 2007-08-09 18:48:29 +0100 (Thu, 09 Aug 2007) $
+ */
+public class DistributedSCABindingImpl implements DistributedSCABinding {
+
+ private SCABinding scaBinding;
+
+ /**
+ * Getter for the wrapped sca binding model object
+ *
+ * @return the sca binding model element
+ */
+ public SCABinding getSCABinding(){
+ return scaBinding;
+ }
+
+ /**
+ * Setter for the wrapped sca binding model element
+ *
+ * @param scaBinding the sca binding model element
+ */
+ public void setSCABinding(SCABinding scaBinding){
+ this.scaBinding = scaBinding;
+ }
+
+
+ // Operation implementations provided to make this class a
+ // valid Binding
+
+ /**
+ * Returns the binding URI.
+ *
+ * @return the binding URI
+ */
+ public String getURI(){
+ return null;
+ }
+
+ /**
+ * Sets the binding URI.
+ *
+ * @param uri the binding URI
+ */
+ public void setURI(String uri){
+ }
+
+ /**
+ * Returns the binding name.
+ *
+ * @return the binding name
+ */
+ public String getName(){
+ return null;
+ }
+
+ /**
+ * Sets the binding name.
+ *
+ * @param name the binding name
+ */
+ public void setName(String name){
+ }
+
+ /**
+ * Returns true if the model element is unresolved.
+ *
+ * @return true if the model element is unresolved.
+ */
+ public boolean isUnresolved(){
+ return false;
+ }
+
+ /**
+ * Sets whether the model element is unresolved.
+ *
+ * @param unresolved whether the model element is unresolved
+ */
+ public void setUnresolved(boolean unresolved){
+ }
+
+ /**
+ * Clone the binding
+ */
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RemoteBindingHelper.java b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RemoteBindingHelper.java
new file mode 100644
index 0000000000..86629fb378
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RemoteBindingHelper.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.sca.impl;
+
+/**
+ * TODO: TUSCANY-2578, implement a pluggable mechanism so sca binding impls can
+ * add their own code to the decision on whether or not to use
+ * the remote binding provider.
+ */
+public class RemoteBindingHelper {
+
+ private static boolean alwaysRemote;
+ static {
+ try {
+ Class.forName("org.apache.tuscany.sca.binding.sca.jms.JMSSCABindingProviderFactory");
+ alwaysRemote = true;
+ } catch (ClassNotFoundException e) {
+ alwaysRemote = false;
+ }
+ }
+
+ public static boolean isTargetRemote() {
+ return alwaysRemote;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProvider.java b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProvider.java
new file mode 100644
index 0000000000..5c1cefb808
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProvider.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.sca.impl;
+
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+
+/**
+ * The local SCA Binding provider implementation. It is not currently used.
+ *
+ * @version $Rev$ $Date$
+ */
+public class RuntimeSCABindingProvider implements ReferenceBindingProvider {
+
+ private RuntimeComponentReference reference;
+
+ public RuntimeSCABindingProvider(RuntimeComponent component, RuntimeComponentReference reference, SCABinding binding) {
+ this.reference = reference;
+ }
+
+ public InterfaceContract getBindingInterfaceContract() {
+ return reference.getInterfaceContract();
+ }
+
+ public Invoker createInvoker(Operation operation) {
+ return null;
+ }
+
+ public void start() {
+ }
+
+ public void stop() {
+ }
+
+ public boolean supportsOneWayInvocation() {
+ return false;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProviderFactory.java b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProviderFactory.java
new file mode 100644
index 0000000000..5dda74f72e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCABindingProviderFactory.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.sca.impl;
+
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.provider.BindingProviderFactory;
+import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
+import org.apache.tuscany.sca.provider.ServiceBindingProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+/**
+ * The factory for creating SCA Binding providers
+ *
+ * @version $Rev$ $Date$
+ */
+public class RuntimeSCABindingProviderFactory implements BindingProviderFactory<SCABinding> {
+
+ private ExtensionPointRegistry extensionPoints;
+
+ public RuntimeSCABindingProviderFactory(ExtensionPointRegistry extensionPoints) {
+ this.extensionPoints = extensionPoints;
+
+ }
+
+ public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component,
+ RuntimeComponentReference reference,
+ SCABinding binding) {
+
+ return new RuntimeSCAReferenceBindingProvider(extensionPoints, component, reference, binding);
+ }
+
+ public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component,
+ RuntimeComponentService service,
+ SCABinding binding) {
+ return new RuntimeSCAServiceBindingProvider(extensionPoints, component, service, binding);
+ }
+
+ public Class<SCABinding> getModelType() {
+ return SCABinding.class;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java
new file mode 100644
index 0000000000..850fd77e96
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAReferenceBindingProvider.java
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.sca.impl;
+
+import java.net.URI;
+import java.util.logging.Logger;
+
+import org.apache.tuscany.sca.assembly.OptimizableBinding;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.binding.sca.DistributedSCABinding;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.provider.BindingProviderFactory;
+import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
+import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.ServiceUnavailableException;
+
+/**
+ * The sca reference binding provider mediates between the twin requirements of
+ * local sca bindings and remote sca bindings. In the local case is does
+ * very little. When the sca binding model is set as being remote (because a
+ * reference target can't be resolved in the current model) this binding will
+ * try and create a remote connection to it
+ *
+ * @version $Rev$ $Date$
+ */
+public class RuntimeSCAReferenceBindingProvider implements ReferenceBindingProvider {
+
+ private static final Logger logger = Logger.getLogger(RuntimeSCAReferenceBindingProvider.class.getName());
+
+ private RuntimeComponent component;
+ private RuntimeComponentReference reference;
+ private SCABinding binding;
+ private boolean started = false;
+
+ private BindingProviderFactory<DistributedSCABinding> distributedProviderFactory = null;
+ private ReferenceBindingProvider distributedProvider = null;
+
+ public RuntimeSCAReferenceBindingProvider(ExtensionPointRegistry extensionPoints,
+ RuntimeComponent component,
+ RuntimeComponentReference reference,
+ SCABinding binding) {
+ this.component = component;
+ this.reference = reference;
+ this.binding = binding;
+
+ // look to see if a distributed SCA binding implementation has
+ // been included on the classpath. This will be needed by the
+ // provider itself to do it's thing
+ ProviderFactoryExtensionPoint factoryExtensionPoint =
+ extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class);
+ distributedProviderFactory =
+ (BindingProviderFactory<DistributedSCABinding>)factoryExtensionPoint
+ .getProviderFactory(DistributedSCABinding.class);
+
+ }
+
+ public boolean isTargetRemote() {
+ boolean targetIsRemote = false;
+
+ // first look at the target service and see if this has been resolved
+ OptimizableBinding optimizableBinding = (OptimizableBinding)binding;
+
+ // The decision is based on the results of the wiring process in the assembly model
+ // The SCA binding is used to represent unresolved reference targets, i.e. those
+ // reference targets that need resolving at run time. We can tell by lookin if the
+ // service to which this binding refers is resolved or not.
+ //
+ // TODO - When a callback is in operation. A callback reference bindings sometimes has to
+ // act as though there is a local wire and sometimes as if there is a remote wire
+ // what are the implications of this here?
+
+ if (RemoteBindingHelper.isTargetRemote()) {
+ if (reference.getInterfaceContract() != null) {
+ targetIsRemote = reference.getInterfaceContract().getInterface().isRemotable();
+ } else {
+ targetIsRemote = true;
+ }
+ } else if (optimizableBinding.getTargetComponentService() != null) {
+ if (optimizableBinding.getTargetComponentService().isUnresolved() == true) {
+ targetIsRemote = true;
+ } else {
+ targetIsRemote = false;
+ }
+ } else {
+ // the case where the wire is specified by URI, e.g. callbacks or user specified bindings, and
+ // look at the provided URI to decide whether it is a local or remote case
+ try {
+ URI uri = new URI(binding.getURI());
+ if (uri.isAbsolute()) {
+ targetIsRemote = true;
+ } else {
+ targetIsRemote = false;
+ }
+ } catch (Exception ex) {
+ targetIsRemote = false;
+ }
+ }
+ return targetIsRemote;
+ }
+
+ private ReferenceBindingProvider getDistributedProvider() {
+
+ if (isTargetRemote()) {
+ // initialize the remote provider if it hasn't been done already
+ if (distributedProvider == null) {
+ if (reference.getInterfaceContract() != null && !reference.getInterfaceContract().getInterface().isRemotable()) {
+ throw new IllegalStateException("Reference interface not remotable for component: " + component
+ .getName()
+ + " and reference: "
+ + reference.getName());
+ }
+
+ if (distributedProviderFactory == null) {
+ throw new IllegalStateException("No distributed SCA binding available for component: " + component
+ .getName()
+ + " and reference: "
+ + reference.getName());
+ }
+
+ // create the remote provider
+ DistributedSCABinding distributedBinding = new DistributedSCABindingImpl();
+ distributedBinding.setSCABinding(binding);
+
+ distributedProvider =
+ distributedProviderFactory.createReferenceBindingProvider(component, reference, distributedBinding);
+ }
+ }
+
+ return distributedProvider;
+ }
+
+ public InterfaceContract getBindingInterfaceContract() {
+ if (isTargetRemote()) {
+ return getDistributedProvider().getBindingInterfaceContract();
+ } else {
+ if (reference.getReference() != null) {
+ return reference.getReference().getInterfaceContract();
+ } else {
+ return reference.getInterfaceContract();
+ }
+ }
+ }
+
+ public boolean supportsOneWayInvocation() {
+ if (isTargetRemote()) {
+ return getDistributedProvider().supportsOneWayInvocation();
+ } else {
+ return false;
+ }
+ }
+
+ private Invoker getInvoker(RuntimeWire wire, Operation operation) {
+ EndpointReference target = wire.getTarget();
+ if (target != null) {
+ RuntimeComponentService service = (RuntimeComponentService)target.getContract();
+ if (service != null) { // not a callback wire
+ SCABinding scaBinding = service.getBinding(SCABinding.class);
+ InvocationChain chain =
+ service.getInvocationChain(scaBinding, wire.getSource().getInterfaceContract(), operation);
+ return chain == null ? null : new SCABindingInvoker(chain);
+ }
+ }
+ return null;
+ }
+
+ public Invoker createInvoker(Operation operation) {
+ if (isTargetRemote()) {
+ return getDistributedProvider().createInvoker(operation);
+ } else {
+ RuntimeWire wire = reference.getRuntimeWire(binding);
+ Invoker invoker = getInvoker(wire, operation);
+ if (invoker == null) {
+ throw new ServiceUnavailableException("Unable to create SCA binding invoker for local target " + component.getName()
+ + " reference "
+ + reference.getName()
+ + " (bindingURI="
+ + binding.getURI()
+ + " operation="
+ + operation.getName()
+ + ")" );
+ }
+ return invoker;
+ }
+ }
+
+ public void start() {
+ if (started) {
+ return;
+ } else {
+ started = true;
+ }
+
+ if (getDistributedProvider() != null) {
+ distributedProvider.start();
+ }
+ }
+
+ public void stop() {
+ if (!started) {
+ return;
+ } else {
+ started = false;
+ }
+
+ if (getDistributedProvider() != null) {
+ distributedProvider.stop();
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAServiceBindingProvider.java b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAServiceBindingProvider.java
new file mode 100644
index 0000000000..8994ba5381
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/RuntimeSCAServiceBindingProvider.java
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.sca.impl;
+
+import java.net.URI;
+
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.binding.sca.DistributedSCABinding;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.provider.BindingProviderFactory;
+import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
+import org.apache.tuscany.sca.provider.ServiceBindingProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+/**
+ * The sca service binding provider mediates between the twin requirements of
+ * local sca bindings and remote sca bindings. In the local case is does
+ * very little. When the sca binding model is set as being remote this binding will
+ * try and create a remote service endpoint for remote references to connect to
+ *
+ * @version $Rev$ $Date$
+ */
+public class RuntimeSCAServiceBindingProvider implements ServiceBindingProvider {
+
+ private RuntimeComponentService service;
+ private BindingProviderFactory<DistributedSCABinding> distributedProviderFactory;
+ private ServiceBindingProvider distributedProvider;
+ private DistributedSCABinding distributedBinding;
+
+ public RuntimeSCAServiceBindingProvider(ExtensionPointRegistry extensionPoints,
+ RuntimeComponent component,
+ RuntimeComponentService service,
+ SCABinding binding) {
+ this.service = service;
+ // if there is potentially a wire to this service that crosses the node boundary
+ if (service.getInterfaceContract().getInterface().isRemotable()) {
+
+ // look to see if a distributed SCA binding implementation has
+ // been included on the classpath. This will be needed by the
+ // provider itself to do it's thing
+ ProviderFactoryExtensionPoint factoryExtensionPoint =
+ extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class);
+ distributedProviderFactory =
+ (BindingProviderFactory<DistributedSCABinding>)factoryExtensionPoint
+ .getProviderFactory(DistributedSCABinding.class);
+
+ // Check the things that will generally be required to set up a
+ // distributed sca domain reference provider. I.e. make sure that we have a
+ // - distributed implementation of the sca binding available
+ // - remotable interface on the service
+ if (distributedProviderFactory != null) {
+
+ URI serviceURI = null;
+ try {
+ serviceURI = new URI(binding.getURI());
+ } catch(Exception ex) {
+
+ }
+
+ if (RemoteBindingHelper.isTargetRemote() || ((serviceURI != null) && (serviceURI.isAbsolute()))) {
+
+ // create a nested provider to handle the remote case
+ distributedBinding = new DistributedSCABindingImpl();
+ distributedBinding.setSCABinding(binding);
+
+ distributedProvider =
+ distributedProviderFactory.createServiceBindingProvider(component, service, distributedBinding);
+
+
+ } else {
+ /* do nothing at the moment as only apps using the node implementation
+ * will currently have the distributed domain set.
+ *
+ throw new IllegalStateException("No distributed domain available for component: "+
+ component.getName() +
+ " and service: " +
+ service.getName());
+ */
+ }
+ } else {
+ /* do nothing at the moment as all services with remotable interfaces
+ * are marked as remote
+ throw new IllegalStateException("No distributed SCA binding available for component: "+
+ component.getName() +
+ " and service: " +
+ service.getName());
+ */
+ }
+ }
+ }
+
+ public InterfaceContract getBindingInterfaceContract() {
+ if (distributedProvider != null) {
+ return distributedProvider.getBindingInterfaceContract();
+ } else {
+ if (service.getService() != null) {
+ return service.getService().getInterfaceContract();
+ } else {
+ return service.getInterfaceContract();
+ }
+ }
+ }
+
+ public boolean supportsOneWayInvocation() {
+ return false;
+ }
+
+ public void start() {
+ if (distributedProvider != null) {
+ distributedProvider.start();
+ }
+ }
+
+ public void stop() {
+ if (distributedProvider != null) {
+ distributedProvider.stop();
+ }
+
+ if (distributedBinding != null) {
+ // reset the binding URI to null so that if the composite containing the component
+ // with the service/binding is restarted the binding will have the correct URI set
+ SCABinding scaBinding = distributedBinding.getSCABinding();
+ try {
+ URI tempURI = new URI(scaBinding.getURI());
+ if (!tempURI.isAbsolute()){
+ scaBinding.setURI(null);
+ }
+ } catch (Exception ex){
+ scaBinding.setURI(null);
+ }
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingFactoryImpl.java b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingFactoryImpl.java
new file mode 100644
index 0000000000..ea758823a9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingFactoryImpl.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.sca.impl;
+
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+
+/**
+ * A factory for the SCA binding model.
+ *
+ * @version $Rev$ $Date$
+ */
+public class SCABindingFactoryImpl implements SCABindingFactory {
+
+ public SCABindingFactoryImpl (){
+
+ }
+
+ public SCABinding createSCABinding() {
+ return new SCABindingImpl();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.java b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.java
new file mode 100644
index 0000000000..c93ddd9503
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingImpl.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.sca.binding.sca.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Extensible;
+import org.apache.tuscany.sca.assembly.OptimizableBinding;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.builder.AutomaticBinding;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+
+/**
+ * The assembly mode object for an SCA binding.
+ *
+ * @version $Rev$ $Date$
+ */
+public class SCABindingImpl implements SCABinding, Extensible, PolicySetAttachPoint, OptimizableBinding, AutomaticBinding {
+ private String name;
+ private String uri;
+ private List<Object> extensions = new ArrayList<Object>();
+ private List<Intent> requiredIntents = new ArrayList<Intent>();
+ private List<PolicySet> policySets = new ArrayList<PolicySet>();
+ private IntentAttachPointType intentAttachPointType;
+
+ private Component targetComponent;
+ private ComponentService targetComponentService;
+ private Binding targetBinding;
+ private List<PolicySet> applicablePolicySets = new ArrayList<PolicySet>();
+
+ private boolean isAutomatic = false;
+
+ public List<PolicySet> getApplicablePolicySets() {
+ return applicablePolicySets;
+ }
+
+ /**
+ * Constructs a new SCA binding.
+ */
+ protected SCABindingImpl() {
+ }
+
+ // SCA Binding operations
+
+ /**
+ * Setters for the binding name. Defaults to the
+ * name of the service or reference with which the binding is
+ * associated
+ *
+ * @return the binding name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * Setter for the binding name
+ *
+ * @param name the binding name
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * Getters for the binding URI. The computed URI for the
+ * service that the reference is targeting or which the service represents
+ * depending on whether the biding is associated with a reference or
+ * service
+ *
+ * @return the binding URI
+ */
+ public String getURI() {
+ return uri;
+ }
+
+ /**
+ * Setter for the binding URI
+ *
+ * @param uri the binding URI
+ */
+ public void setURI(String uri) {
+ this.uri = uri;
+ }
+
+ /**
+ * Returns a list of extension objects contained in this model object.
+ *
+ * @return a list of extension objects container in this model object
+ */
+ public List<Object> getExtensions() {
+ return extensions;
+ }
+
+ /**
+ * Returns true if the model element is unresolved.
+ *
+ * @return true if the model element is unresolved.
+ */
+ public boolean isUnresolved() {
+ if (targetComponentService == null){
+ return true;
+ } else {
+ return targetComponentService.isUnresolved();
+ }
+ }
+
+ /**
+ * Sets whether the model element is unresolved.
+ *
+ * @param unresolved whether the model element is unresolved
+ */
+ public void setUnresolved(boolean unresolved) {
+ }
+
+ /**
+ * @see java.lang.Object#clone()
+ */
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+ public List<PolicySet> getPolicySets() {
+ return policySets;
+ }
+
+ public List<Intent> getRequiredIntents() {
+ return requiredIntents;
+ }
+
+ public IntentAttachPointType getType() {
+ return intentAttachPointType;
+ }
+
+ public void setType(IntentAttachPointType intentAttachPointType) {
+ this.intentAttachPointType = intentAttachPointType;
+ }
+
+ // Wireable binding operations
+
+ /**
+ * @return the targetComponent
+ */
+ public Component getTargetComponent() {
+ return targetComponent;
+ }
+
+ /**
+ * @param targetComponent the targetComponent to set
+ */
+ public void setTargetComponent(Component targetComponent) {
+ this.targetComponent = targetComponent;
+ }
+
+ /**
+ * @return the targetComponentService
+ */
+ public ComponentService getTargetComponentService() {
+ return targetComponentService;
+ }
+
+ /**
+ * @param targetComponentService the targetComponentService to set
+ */
+ public void setTargetComponentService(ComponentService targetComponentService) {
+ this.targetComponentService = targetComponentService;
+ }
+
+ /**
+ * @return the targetBinding
+ */
+ public Binding getTargetBinding() {
+ return targetBinding;
+ }
+
+ /**
+ * @param targetBinding the targetBinding to set
+ */
+ public void setTargetBinding(Binding targetBinding) {
+ this.targetBinding = targetBinding;
+ }
+
+ public void setPolicySets(List<PolicySet> policySets) {
+ this.policySets = policySets;
+ }
+
+ public void setRequiredIntents(List<Intent> intents) {
+ this.requiredIntents = intents;
+ }
+
+
+ public void setIsAutomatic(boolean isAutomatic){
+ this.isAutomatic = isAutomatic;
+ }
+
+ public boolean getIsAutomatic(){
+ return this.isAutomatic;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingInvoker.java b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingInvoker.java
new file mode 100644
index 0000000000..52c0f64fe5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/java/org/apache/tuscany/sca/binding/sca/impl/SCABindingInvoker.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.sca.impl;
+
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.DataExchangeSemantics;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SCABindingInvoker implements Interceptor, DataExchangeSemantics {
+ private InvocationChain chain;
+
+ /**
+ * Construct a SCABindingInvoker that delegates to the service invocaiton chain
+ * @param chain
+ */
+ public SCABindingInvoker(InvocationChain chain) {
+ super();
+ this.chain = chain;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.invocation.Interceptor#getNext()
+ */
+ public Invoker getNext() {
+ return chain.getHeadInvoker();
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.invocation.Interceptor#setNext(org.apache.tuscany.sca.invocation.Invoker)
+ */
+ public void setNext(Invoker next) {
+ // NOOP
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.invocation.Invoker#invoke(org.apache.tuscany.sca.invocation.Message)
+ */
+ public Message invoke(Message msg) {
+ return getNext().invoke(msg);
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.invocation.DataExchangeSemantics#allowsPassByReference()
+ */
+ public boolean allowsPassByReference() {
+ return chain.allowsPassByReference();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.SCABindingFactory b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.SCABindingFactory
new file mode 100644
index 0000000000..4efa03a933
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.assembly.SCABindingFactory
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.binding.sca.impl.SCABindingFactoryImpl
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory
new file mode 100644
index 0000000000..5c6b8e21fc
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for the binding extension
+org.apache.tuscany.sca.binding.sca.impl.RuntimeSCABindingProviderFactory;model=org.apache.tuscany.sca.assembly.SCABinding
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider
new file mode 100644
index 0000000000..22c9a64b05
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProvider
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for SCA Definitions Providers
+org.apache.tuscany.sca.binding.sca.SCABindingDefinitionsProvider \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/resources/org/apache/tuscany/sca/binding/sca/definitions.xml b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/resources/org/apache/tuscany/sca/binding/sca/definitions.xml
new file mode 100644
index 0000000000..8bac9e01c9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/main/resources/org/apache/tuscany/sca/binding/sca/definitions.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<sca:definitions xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ targetNamespace="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0">
+
+ <sca:bindingType type="sca:binding.sca" mayProvide="" alwaysProvides=""/>
+ </sca:definitions> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca/src/test/java/org/apace/tuscany/sca/binding/sca/SCABindingTestCase.java b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/test/java/org/apace/tuscany/sca/binding/sca/SCABindingTestCase.java
new file mode 100644
index 0000000000..ff396566d6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/test/java/org/apace/tuscany/sca/binding/sca/SCABindingTestCase.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apace.tuscany.sca.binding.sca;
+
+import java.io.InputStream;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl;
+import org.apache.tuscany.sca.assembly.xml.CompositeModelResolver;
+import org.apache.tuscany.sca.binding.sca.impl.SCABindingFactoryImpl;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl;
+import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * SCABindingTestCase
+ *
+ * @version $Rev$ $Date$
+ */
+public class SCABindingTestCase {
+
+ private XMLInputFactory inputFactory;
+ private StAXArtifactProcessor<Object> staxProcessor;
+ private CompositeModelResolver resolver;
+ private CompositeBuilder compositeBuilder;
+
+ @Before
+ public void init() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ inputFactory = XMLInputFactory.newInstance();
+
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null);
+
+ resolver = new CompositeModelResolver(null, null);
+
+ ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ SCABindingFactory scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class);
+ IntentAttachPointTypeFactory attachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class);
+
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class);
+ compositeBuilder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, attachPointTypeFactory, mapper, null);
+
+ }
+
+ @Test
+ public void testSCABindingFactory() {
+ SCABindingFactory factory = new SCABindingFactoryImpl();
+ Assert.assertNotNull(factory.createSCABinding());
+ }
+
+ @Test
+ public void testBuildModel() {
+ try{
+ InputStream is = getClass().getResourceAsStream("/Calculator.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = (Composite)staxProcessor.read(reader);
+
+ is.close();
+ Assert.assertNotNull(composite);
+
+ resolver.addModel(composite);
+
+ staxProcessor.resolve(composite, resolver);
+
+ compositeBuilder.build(composite);
+
+ SCABinding referenceSCABinding = (SCABinding) composite.getComponents().get(0).getReferences().get(0).getBindings().get(0);
+ SCABinding serviceSCABinding = (SCABinding) composite.getComponents().get(1).getServices().get(0).getBindings().get(0);
+
+ Assert.assertNotNull(referenceSCABinding);
+ Assert.assertNotNull(serviceSCABinding);
+ } catch (Exception ex) {
+ Assert.fail(ex.getMessage());
+ }
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/binding-sca/src/test/resources/Calculator.composite b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/test/resources/Calculator.composite
new file mode 100644
index 0000000000..37b26f3d68
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/binding-sca/src/test/resources/Calculator.composite
@@ -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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:calc="http://calc"
+ targetNamespace="http://calc"
+ name="Calculator">
+
+ <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"/>
+ <service name="AddService">
+ <interface.java interface="calculator.AddService"/>
+ </service>
+ </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> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-impl/LICENSE b/sca-java-1.x/branches/sca-android/modules/contribution-impl/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-impl/META-INF/README b/sca-java-1.x/branches/sca-android/modules/contribution-impl/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-impl/NOTICE b/sca-java-1.x/branches/sca-android/modules/contribution-impl/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-impl/pom.xml b/sca-java-1.x/branches/sca-android/modules/contribution-impl/pom.xml
new file mode 100644
index 0000000000..ff83cff49c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/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>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-contribution-impl</artifactId>
+ <name>Apache Tuscany SCA Contribution Model Implementation</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ <version>3.2.1</version>
+ <scope>runtime</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.contribution.impl</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.contribution*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/FolderContributionProcessor.java b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/FolderContributionProcessor.java
new file mode 100644
index 0000000000..ab056e3214
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/FolderContributionProcessor.java
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.processor.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.contribution.PackageType;
+import org.apache.tuscany.sca.contribution.processor.PackageProcessor;
+import org.apache.tuscany.sca.contribution.service.ContributionException;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+
+/**
+ * Folder contribution package processor.
+ *
+ * @version $Rev$ $Date$
+ */
+public class FolderContributionProcessor implements PackageProcessor {
+
+ public FolderContributionProcessor() {
+ }
+
+ public String getPackageType() {
+ return PackageType.FOLDER;
+ }
+
+ /**
+ * Recursively traverse a root directory
+ *
+ * @param fileList
+ * @param file
+ * @param root
+ * @throws IOException
+ */
+ private static void traverse(List<URI> fileList, final File file, final File root) throws IOException {
+ // Allow privileged access to test file. Requires FilePermissions in security policy file.
+ Boolean isFile = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+ public Boolean run() {
+ return file.isFile();
+ }
+ });
+ if (isFile) {
+ fileList.add(AccessController.doPrivileged(new PrivilegedAction<URI>() {
+ public URI run() {
+ return root.toURI().relativize(file.toURI());
+ }
+ }));
+ } else {
+ // Allow privileged access to test file. Requires FilePermissions in security policy
+ // file.
+ Boolean isDirectory = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+ public Boolean run() {
+ return file.isDirectory();
+ }
+ });
+ if (isDirectory) {
+ String uri = AccessController.doPrivileged(new PrivilegedAction<URI>() {
+ public URI run() {
+ return root.toURI().relativize(file.toURI());
+ }
+ }).toString();
+
+ if (uri.endsWith("/")) {
+ uri = uri.substring(0, uri.length() - 1);
+ }
+ fileList.add(URI.create(uri));
+
+ // Allow privileged access to list files. Requires FilePermission in security
+ // policy.
+ File[] files = AccessController.doPrivileged(new PrivilegedAction<File[]>() {
+ public File[] run() {
+ return file.listFiles();
+ }
+ });
+ for (File f : files) {
+ if (!f.getName().startsWith(".")) {
+ traverse(fileList, f, root);
+ }
+ }
+ }
+ }
+ }
+
+ public URL getArtifactURL(URL sourceURL, URI artifact) throws MalformedURLException {
+ return new URL(sourceURL, artifact.toString());
+ }
+
+ public List<URI> getArtifacts(URL packageSourceURL, InputStream inputStream) throws ContributionException,
+ IOException {
+ if (packageSourceURL == null) {
+ throw new IllegalArgumentException("Invalid null package source URL.");
+ }
+
+ List<URI> artifacts = new ArrayList<URI>();
+
+ try {
+ // Assume the root is a jar file
+ final File rootFolder = new File(packageSourceURL.toURI());
+ // Allow privileged access to test file. Requires FilePermissions in security policy
+ // file.
+ Boolean isDirectory = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+ public Boolean run() {
+ return rootFolder.isDirectory();
+ }
+ });
+ if (isDirectory) {
+ // Allow privileged access to test file. Requires FilePermissions in security policy
+ // file.
+ Boolean folderExists = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+ public Boolean run() {
+ return rootFolder.exists();
+ }
+ });
+ if (!folderExists) {
+ throw new ContributionReadException(rootFolder.getAbsolutePath());
+ }
+
+ // Security consideration. This method gathers URIs of enclosed
+ // artifacts. The URIs are protected by the policy when a user
+ // yries to open those URLs.
+ traverse(artifacts, rootFolder, rootFolder);
+ }
+
+ } catch (URISyntaxException e) {
+ throw new ContributionReadException(packageSourceURL.toExternalForm(), e);
+ }
+
+ return artifacts;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/JarContributionProcessor.java b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/JarContributionProcessor.java
new file mode 100644
index 0000000000..3df275a7a1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/processor/impl/JarContributionProcessor.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.processor.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarInputStream;
+
+import org.apache.tuscany.sca.contribution.PackageType;
+import org.apache.tuscany.sca.contribution.processor.PackageProcessor;
+import org.apache.tuscany.sca.contribution.service.ContributionException;
+
+/**
+ * Jar Contribution package processor.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JarContributionProcessor implements PackageProcessor {
+
+ public JarContributionProcessor() {
+ }
+
+ public String getPackageType() {
+ return PackageType.JAR;
+ }
+
+ public URL getArtifactURL(URL sourceURL, URI artifact) throws MalformedURLException {
+ if (sourceURL.toString().startsWith("jar:")) {
+ return new URL(sourceURL, artifact.toString());
+ } else {
+ return new URL("jar:" + sourceURL.toExternalForm() + "!/" + artifact);
+ }
+ }
+
+ public List<URI> getArtifacts(URL packageSourceURL, InputStream inputStream) throws ContributionException,
+ IOException {
+ if (packageSourceURL == null) {
+ throw new IllegalArgumentException("Invalid null package source URL.");
+ }
+
+ if (inputStream == null) {
+ throw new IllegalArgumentException("Invalid null source inputstream.");
+ }
+
+ // Assume the root is a jar file
+ JarInputStream jar = new JarInputStream(inputStream);
+ try {
+ Set<String> names = new HashSet<String>();
+ while (true) {
+ JarEntry entry = jar.getNextJarEntry();
+ if (entry == null) {
+ // EOF
+ break;
+ }
+
+ // FIXME: Maybe we should externalize the filter as a property
+ String name = entry.getName();
+ if (!name.startsWith(".")) {
+
+ // Trim trailing /
+ if (name.endsWith("/")) {
+ name = name.substring(0, name.length() - 1);
+ }
+
+ // Add the entry name
+ if (!names.contains(name)) {
+ names.add(name);
+
+ // Add parent folder names to the list too
+ for (;;) {
+ int s = name.lastIndexOf('/');
+ if (s == -1) {
+ name = "";
+ } else {
+ name = name.substring(0, s);
+ }
+ if (!names.contains(name)) {
+ names.add(name);
+ } else {
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ // Return list of URIs
+ List<URI> artifacts = new ArrayList<URI>();
+ for (String name: names) {
+ artifacts.add(URI.create(name));
+ }
+ return artifacts;
+
+ } finally {
+ jar.close();
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryImpl.java b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryImpl.java
new file mode 100644
index 0000000000..9375cb917f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionRepositoryImpl.java
@@ -0,0 +1,399 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.service.impl;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLConnection;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.service.ContributionRepository;
+import org.apache.tuscany.sca.contribution.service.util.FileHelper;
+import org.apache.tuscany.sca.contribution.service.util.IOHelper;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ * The default implementation of ContributionRepository
+ *
+ * @version $Rev$ $Date$
+ */
+public class ContributionRepositoryImpl implements ContributionRepository {
+ private static final String NS = "http://tuscany.apache.org/xmlns/1.0-SNAPSHOT";
+ private static final String DOMAIN_INDEX_FILENAME = "sca-domain.xml";
+ private final File rootFile;
+ private Map<String, String> contributionLocations = new HashMap<String, String>();
+
+ private Map<String, Contribution> contributionMap = new HashMap<String, Contribution>();
+ private List<Contribution> contributions = new ArrayList<Contribution>();
+
+ private URI domain;
+ private XMLInputFactory factory;
+ private Monitor monitor;
+
+ /**
+ * Marshals warnings into the monitor
+ *
+ * @param message
+ * @param model
+ * @param messageParameters
+ */
+ protected void warning(String message, Object model, String... messageParameters) {
+ if (monitor != null){
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-impl-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Marshals errors into the monitor
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ protected void error(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-impl-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Marshals exceptions into the monitor
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ protected void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-impl-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Constructor with repository root
+ *
+ * @param repository
+ * @param factory
+ */
+ public ContributionRepositoryImpl(final String repository, XMLInputFactory factory, Monitor monitor) throws IOException {
+ this.monitor = monitor;
+ 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;
+ }
+ });
+ }
+
+ // Allow privileged access to File. Requires FilePermission in security policy file.
+ final String finalRoot = root;
+ this.rootFile = AccessController.doPrivileged(new PrivilegedAction<File>() {
+ public File run() {
+ return new File(finalRoot);
+ }
+ });
+
+ // Allow privileged access to File. Requires FilePermission in security policy file.
+ this.domain = AccessController.doPrivileged(new PrivilegedAction<URI>() {
+ public URI run() {
+ return rootFile.toURI();
+ }
+ });
+
+ // Allow privileged access to mkdir. Requires FilePermission in security policy file.
+ try {
+ AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
+ public Object run() throws IOException {
+ FileHelper.forceMkdir(rootFile);
+ return null;
+ }
+ });
+ } catch (PrivilegedActionException e) {
+ error("PrivilegedActionException", rootFile, (IOException)e.getException());
+ throw (IOException)e.getException();
+ }
+
+ // Allow privileged access to test file. Requires FilePermissions in security policy file.
+ Boolean notDirectory = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+ public Boolean run() {
+ return (!rootFile.exists() || !rootFile.isDirectory() || !rootFile.canRead());
+ }
+ });
+ if (notDirectory) {
+ error("RootNotDirectory", rootFile, repository);
+ throw new IOException("The root is not a directory: " + repository);
+ }
+ this.factory = factory;
+ }
+
+ public URI getDomain() {
+ return domain;
+ }
+
+ /**
+ * Resolve contribution location in the repository -> root repository /
+ * contribution file -> contribution group id / artifact id / version
+ *
+ * @param contribution
+ * @return
+ */
+ private File mapToFile(URL sourceURL) {
+ String fileName = FileHelper.toFile(sourceURL).getName();
+ return new File(rootFile, "contributions" + File.separator + fileName);
+ }
+
+ /**
+ * Write a specific source InputStream to a file on disk
+ *
+ * @param source contents of the file to be written to disk
+ * @param target file to be written
+ * @throws IOException
+ */
+ public static void copy(InputStream source, File target) throws IOException {
+ BufferedOutputStream out = null;
+ BufferedInputStream in = null;
+
+ try {
+ out = new BufferedOutputStream(new FileOutputStream(target));
+ in = new BufferedInputStream(source);
+ IOHelper.copy(in, out);
+ } finally {
+ IOHelper.closeQuietly(out);
+ IOHelper.closeQuietly(in);
+ }
+ }
+
+ public URL store(final String contribution, URL sourceURL, InputStream contributionStream) throws IOException {
+ // where the file should be stored in the repository
+ final File location = mapToFile(sourceURL);
+ FileHelper.forceMkdir(location.getParentFile());
+
+ copy(contributionStream, location);
+
+ // add contribution to repositoryContent
+ // Allow ability to read user.dir property. Requires PropertyPermission in security policy.
+ URL contributionURL;
+ try {
+ contributionURL= AccessController.doPrivileged(new PrivilegedExceptionAction<URL>() {
+ public URL run() throws IOException {
+ URL contributionURL = location.toURL();
+ URI relative = rootFile.toURI().relativize(location.toURI());
+ contributionLocations.put(contribution, relative.toString());
+ return contributionURL;
+ }
+ });
+ } catch (PrivilegedActionException e) {
+ error("PrivilegedActionException", location, (IOException)e.getException());
+ throw (IOException)e.getException();
+ }
+ saveMap();
+
+ return contributionURL;
+ }
+
+ public URL store(String contribution, URL sourceURL) throws IOException {
+ // where the file should be stored in the repository
+ File location = mapToFile(sourceURL);
+ File source = FileHelper.toFile(sourceURL);
+ if (source == null || source.isFile()) {
+ URLConnection connection = sourceURL.openConnection();
+ connection.setUseCaches(false);
+ InputStream is = connection.getInputStream();
+ try {
+ return store(contribution, sourceURL, is);
+ } finally {
+ IOHelper.closeQuietly(is);
+ }
+ }
+
+ FileHelper.forceMkdir(location);
+ FileHelper.copyDirectory(source, location);
+
+ // add contribution to repositoryContent
+ URI relative = rootFile.toURI().relativize(location.toURI());
+ contributionLocations.put(contribution, relative.toString());
+ saveMap();
+
+ return location.toURL();
+ }
+
+ public URL find(String contribution) {
+ if (contribution == null) {
+ return null;
+ }
+ String location = contributionLocations.get(contribution);
+ if (location == null) {
+ return null;
+ }
+ try {
+ return new File(rootFile, location).toURL();
+ } catch (MalformedURLException e) {
+ // Should not happen
+ error("MalformedURLException", location, new AssertionError(e));
+ throw new AssertionError(e);
+ }
+ }
+
+ public void remove(String contribution) {
+ URL contributionURL = this.find(contribution);
+ if (contributionURL != null) {
+ // remove
+ try {
+ FileHelper.forceDelete(FileHelper.toFile(contributionURL));
+ this.contributionLocations.remove(contribution);
+ saveMap();
+ } catch (IOException ioe) {
+ // handle file could not be removed
+ }
+ }
+ }
+
+ public List<String> list() {
+ return new ArrayList<String>(contributionLocations.keySet());
+ }
+
+ public void init() {
+ File domainFile = new File(rootFile, "sca-domain.xml");
+ if (!domainFile.isFile()) {
+ return;
+ }
+ FileInputStream is;
+ try {
+ is = new FileInputStream(domainFile);
+ } catch (FileNotFoundException e) {
+ warning("DomainFileNotFound", domainFile, domainFile.getAbsolutePath());
+ return;
+ }
+ try {
+ XMLStreamReader reader = factory.createXMLStreamReader(new InputStreamReader(is, "UTF-8"));
+ while (reader.hasNext()) {
+ switch (reader.getEventType()) {
+ case XMLStreamConstants.START_ELEMENT:
+ String name = reader.getName().getLocalPart();
+ if ("domain".equals(name)) {
+ String uri = reader.getAttributeValue(null, "uri");
+ if (uri != null) {
+ domain = URI.create(uri);
+ }
+ }
+ if ("contribution".equals(name)) {
+ String uri = reader.getAttributeValue(null, "uri");
+ String location = reader.getAttributeValue(null, "location");
+ contributionLocations.put(uri, location);
+ }
+ break;
+ default:
+ break;
+ }
+ reader.next();
+ }
+ } catch (Exception e) {
+ // Ignore
+ } finally {
+ IOHelper.closeQuietly(is);
+ }
+ }
+
+ private void saveMap() {
+ File domainFile = new File(rootFile, DOMAIN_INDEX_FILENAME);
+ FileOutputStream os = null;
+ try {
+ os = new FileOutputStream(domainFile);
+ PrintWriter writer = new PrintWriter(new OutputStreamWriter(os, "UTF-8"));
+ writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+ writer.println("<domain uri=\"" + getDomain() + "\" xmlns=\"" + NS + "\">");
+ for (Map.Entry<String, String> e : contributionLocations.entrySet()) {
+ writer.println(" <contribution uri=\"" + e.getKey() + "\" location=\"" + e.getValue() + "\"/>");
+ }
+ writer.println("</domain>");
+ writer.flush();
+ } catch (IOException e) {
+ IllegalArgumentException ae = new IllegalArgumentException(e);
+ error("IllegalArgumentException", os, ae);
+ throw ae;
+ } finally {
+ IOHelper.closeQuietly(os);
+ }
+ }
+
+ public void destroy() {
+ }
+
+ public void addContribution(Contribution contribution) {
+ contributionMap.put(contribution.getURI(), contribution);
+ contributions.add(contribution);
+ }
+
+ public void removeContribution(Contribution contribution) {
+ contributionMap.remove(contribution.getURI());
+ contributions.remove(contribution);
+ }
+
+ public void updateContribution(Contribution contribution) {
+ Contribution oldContribution = contributionMap.remove(contribution.getURI());
+ contributions.remove(oldContribution);
+ contributionMap.put(contribution.getURI(), contribution);
+ contributions.add(contribution);
+ }
+
+ public Contribution getContribution(String uri) {
+ return contributionMap.get(uri);
+ }
+
+ public List<Contribution> getContributions() {
+ return Collections.unmodifiableList(contributions);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java
new file mode 100644
index 0000000000..7b8b12ca9d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/ContributionServiceImpl.java
@@ -0,0 +1,584 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.service.impl;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.net.URLConnection;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.contribution.Artifact;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.ContributionMetadata;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.PackageProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
+import org.apache.tuscany.sca.contribution.service.ContributionException;
+import org.apache.tuscany.sca.contribution.service.ContributionRepository;
+import org.apache.tuscany.sca.contribution.service.ContributionService;
+import org.apache.tuscany.sca.contribution.service.ExtensibleContributionListener;
+import org.apache.tuscany.sca.contribution.service.util.IOHelper;
+import org.apache.tuscany.sca.contribution.xml.ContributionMetadataDocumentProcessor;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ * Service interface that manages artifacts contributed to a Tuscany runtime.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ContributionServiceImpl implements ContributionService {
+
+ /**
+ * Repository where contributions are stored. Usually set by injection.
+ */
+ private ContributionRepository contributionRepository;
+
+ /**
+ * Registry of available package processors.
+ */
+ private PackageProcessor packageProcessor;
+
+ /**
+ * Registry of available artifact processors
+ */
+
+ private URLArtifactProcessor artifactProcessor;
+
+ /**
+ * Registry of available StAX processors,
+ * used for loading contribution metadata in a extensible way
+ */
+ private StAXArtifactProcessor staxProcessor;
+
+ /**
+ * Event listener for contribution operations
+ */
+ private ExtensibleContributionListener contributionListener;
+
+ /**
+ * Registry of available model resolvers
+ */
+
+ private ModelResolverExtensionPoint modelResolvers;
+
+ /**
+ * Model factory extension point
+ */
+
+ private ModelFactoryExtensionPoint modelFactories;
+
+ /**
+ * XML factory used to create reader instance to load contribution metadata
+ */
+ private XMLInputFactory xmlFactory;
+
+ /**
+ * Assembly factory
+ */
+ private AssemblyFactory assemblyFactory;
+
+ /**
+ * Contribution model factory
+ */
+ private ContributionFactory contributionFactory;
+
+
+ private ModelResolver policyDefinitionsResolver;
+
+ private List policyDefinitions;
+
+ private Monitor monitor;
+
+ private String COMPOSITE_FILE_EXTN = ".composite";
+
+ public ContributionServiceImpl(ContributionRepository repository,
+ PackageProcessor packageProcessor,
+ URLArtifactProcessor documentProcessor,
+ StAXArtifactProcessor staxProcessor,
+ ExtensibleContributionListener contributionListener,
+ ModelResolver policyDefinitionsResolver,
+ ModelResolverExtensionPoint modelResolvers,
+ ModelFactoryExtensionPoint modelFactories,
+ AssemblyFactory assemblyFactory,
+ ContributionFactory contributionFactory,
+ XMLInputFactory xmlFactory,
+ List<SCADefinitions> policyDefinitions,
+ Monitor monitor) {
+ super();
+ this.contributionRepository = repository;
+ this.packageProcessor = packageProcessor;
+ this.artifactProcessor = documentProcessor;
+ this.staxProcessor = staxProcessor;
+ this.contributionListener = contributionListener;
+ this.modelResolvers = modelResolvers;
+ this.modelFactories = modelFactories;
+ this.xmlFactory = xmlFactory;
+ this.assemblyFactory = assemblyFactory;
+ this.contributionFactory = contributionFactory;
+ this.policyDefinitionsResolver = policyDefinitionsResolver;
+ this.policyDefinitions = policyDefinitions;
+ this.monitor = monitor;
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-impl-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ public Contribution contribute(String contributionURI, URL sourceURL, boolean storeInRepository)
+ throws ContributionException, IOException {
+ if (contributionURI == null) {
+ error("ContributionURINull", contributionURI);
+ throw new IllegalArgumentException("URI for the contribution is null");
+ }
+ if (sourceURL == null) {
+ error("SourceURLNull", sourceURL);
+ throw new IllegalArgumentException("Source URL for the contribution is null");
+ }
+ return addContribution(contributionURI, sourceURL, null, null, storeInRepository);
+ }
+
+ public Contribution contribute(String contributionURI,
+ URL sourceURL,
+ ModelResolver modelResolver,
+ boolean storeInRepository) throws ContributionException, IOException {
+ if (contributionURI == null) {
+ error("ContributionURINull", contributionURI);
+ throw new IllegalArgumentException("URI for the contribution is null");
+ }
+ if (sourceURL == null) {
+ error("SourceURLNull", sourceURL);
+ throw new IllegalArgumentException("Source URL for the contribution is null");
+ }
+
+ return addContribution(contributionURI, sourceURL, null, modelResolver, storeInRepository);
+ }
+
+ public Contribution contribute(String contributionURI, URL sourceURL, InputStream input)
+ throws ContributionException, IOException {
+
+ return addContribution(contributionURI, sourceURL, input, null, true);
+ }
+
+ public Contribution contribute(String contributionURI, URL sourceURL, InputStream input, ModelResolver modelResolver)
+ throws ContributionException, IOException {
+
+ return addContribution(contributionURI, sourceURL, input, modelResolver, true);
+ }
+
+ public Contribution getContribution(String uri) {
+ return this.contributionRepository.getContribution(uri);
+ }
+
+ /**
+ * Remove a contribution and notify listener that contribution was removed
+ */
+ public void remove(String uri) throws ContributionException {
+ Contribution contribution = contributionRepository.getContribution(uri);
+ this.contributionRepository.removeContribution(contribution);
+ this.contributionListener.contributionRemoved(this.contributionRepository, contribution);
+ }
+
+ /**
+ * Add a composite model to the contribution
+ */
+ public void addDeploymentComposite(Contribution contribution, Composite composite) throws ContributionException {
+ Artifact artifact = this.contributionFactory.createArtifact();
+ artifact.setURI(composite.getURI());
+ artifact.setModel(composite);
+
+ contribution.getArtifacts().add(artifact);
+
+ contribution.getDeployables().add(composite);
+ }
+
+ /**
+ * Utility/Helper methods for contribution service
+ */
+
+ /**
+ * Perform read of the contribution metadata loader (sca-contribution.xml and sca-contribution-generated.xml)
+ * When the two metadata files are available, the information provided are merged, and the sca-contribution has priorities
+ *
+ * @param sourceURL
+ * @return Contribution
+ * @throws ContributionException
+ */
+ private Contribution readContributionMetadata(URL sourceURL) throws ContributionException {
+ Contribution contributionMetadata = contributionFactory.createContribution();
+
+ ContributionMetadataDocumentProcessor metadataDocumentProcessor =
+ new ContributionMetadataDocumentProcessor(modelFactories, staxProcessor, monitor);
+
+ final URL[] urls = {sourceURL};
+ // Allow access to create classloader. Requires RuntimePermission in security policy.
+ URLClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<URLClassLoader>() {
+ public URLClassLoader run() {
+ return new URLClassLoader(urls, null);
+ }
+ });
+ for (String path: new String[]{
+ Contribution.SCA_CONTRIBUTION_GENERATED_META,
+ Contribution.SCA_CONTRIBUTION_META}) {
+ URL url = cl.getResource(path);
+ if (url != null) {
+ ContributionMetadata contribution = metadataDocumentProcessor.read(sourceURL, URI.create(path), url);
+ contributionMetadata.getImports().addAll(contribution.getImports());
+ contributionMetadata.getExports().addAll(contribution.getExports());
+ contributionMetadata.getDeployables().addAll(contribution.getDeployables());
+ }
+ }
+
+ // For debugging purposes, write it back to XML
+ // if (contributionMetadata != null) {
+ // try {
+ // ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ // XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
+ // outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
+ // staxProcessor.write(contributionMetadata, outputFactory.createXMLStreamWriter(bos));
+ // Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(bos.toByteArray()));
+ // OutputFormat format = new OutputFormat();
+ // format.setIndenting(true);
+ // format.setIndent(2);
+ // XMLSerializer serializer = new XMLSerializer(System.out, format);
+ // serializer.serialize(document);
+ // } catch (Exception e) {
+ // e.printStackTrace();
+ // }
+ // }
+
+ return contributionMetadata;
+ }
+
+ /**
+ * Note:
+ *
+ * @param contributionURI ContributionID
+ * @param sourceURL contribution location
+ * @param contributionStream contribution content
+ * @param storeInRepository flag if we store the contribution into the
+ * repository or not
+ * @return the contribution model representing the contribution
+ * @throws IOException
+ * @throws DeploymentException
+ */
+ private Contribution addContribution(String contributionURI,
+ URL sourceURL,
+ InputStream contributionStream,
+ ModelResolver modelResolver,
+ boolean storeInRepository) throws IOException, ContributionException {
+
+ if (contributionStream == null && sourceURL == null) {
+ error("ContributionContentNull", contributionStream);
+ throw new IllegalArgumentException("The content of the contribution is null.");
+ }
+
+ // store the contribution in the contribution repository
+ URL locationURL = sourceURL;
+ if (contributionRepository != null && storeInRepository) {
+ if (contributionStream == null) {
+ locationURL = contributionRepository.store(contributionURI, sourceURL);
+ } else {
+ locationURL = contributionRepository.store(contributionURI, sourceURL, contributionStream);
+ }
+ }
+
+ //initialize contribution based on it's metadata if available
+ Contribution contribution = readContributionMetadata(locationURL);
+
+ // Create contribution model resolver
+ if (modelResolver == null) {
+ //FIXME Remove this domain resolver, visibility of policy declarations should be handled by
+ // the contribution import/export mechanism instead of this domainResolver hack.
+ modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories, policyDefinitionsResolver);
+ }
+
+ //set contribution initial information
+ contribution.setURI(contributionURI);
+ contribution.setLocation(locationURL.toString());
+ contribution.setModelResolver(modelResolver);
+
+ List<URI> contributionArtifacts = null;
+
+ //NOTE: if a contribution is stored on the repository
+ //the stream would be consumed at this point
+ if (storeInRepository || contributionStream == null) {
+ URLConnection connection = sourceURL.openConnection();
+ connection.setUseCaches(false);
+ // Allow access to open URL stream. Add FilePermission to added to security policy file.
+ final URLConnection finalConnection = connection;
+ try {
+ contributionStream = AccessController.doPrivileged(new PrivilegedExceptionAction<InputStream>() {
+ public InputStream run() throws IOException {
+ return finalConnection.getInputStream();
+ }
+ });
+ } catch (PrivilegedActionException e) {
+ throw (IOException)e.getException();
+ }
+
+ try {
+ // process the contribution
+ contributionArtifacts = this.packageProcessor.getArtifacts(locationURL, contributionStream);
+ } finally {
+ IOHelper.closeQuietly(contributionStream);
+ contributionStream = null;
+ }
+ } else {
+ // process the contribution
+ contributionArtifacts = this.packageProcessor.getArtifacts(locationURL, contributionStream);
+ }
+
+ // Read all artifacts in the contribution
+ try {
+ // Allow access to read system properties. Requires PropertyPermission in security policy.
+ // Any security exceptions are caught and wrapped as ContributionException.
+ processReadPhase(contribution, contributionArtifacts);
+ } catch ( Exception e ) {
+ throw new ContributionException(e);
+ }
+
+ //
+ this.contributionListener.contributionAdded(this.contributionRepository, contribution);
+
+ // Resolve them
+ processResolvePhase(contribution);
+
+ // Add all composites under META-INF/sca-deployables to the
+ // list of deployables
+ String prefix = Contribution.SCA_CONTRIBUTION_DEPLOYABLES;
+ for (Artifact artifact : contribution.getArtifacts()) {
+ if (artifact.getModel() instanceof Composite) {
+ if (artifact.getURI().startsWith(prefix)) {
+ Composite composite = (Composite)artifact.getModel();
+ if (!contribution.getDeployables().contains(composite)) {
+ contribution.getDeployables().add(composite);
+ }
+ }
+ }
+ }
+
+ processApplicationComposite(contribution);
+
+ // store the contribution on the registry
+ this.contributionRepository.addContribution(contribution);
+
+ return contribution;
+ }
+
+ /**
+ * Process any application composite (eg see 5.1.3 of SCA JEE spec)
+ * TODO: see TUSCANY-2581
+ */
+ private void processApplicationComposite(Contribution contribution) {
+
+ Composite composite = findComposite("web-inf/web.composite", contribution);
+ if (composite != null) {
+ if (!contribution.getDeployables().contains(composite)) {
+ contribution.getDeployables().add(createDeploymentComposite(composite));
+ }
+ }
+ }
+
+ /**
+ * Create a deployment composite for the composite
+ * See line 247 section 5.1.3 of SCA JEE spec
+ */
+ private Composite createDeploymentComposite(Composite composite) {
+ // TODO: for now just use as-is
+ return composite;
+ }
+
+ private Composite findComposite(String name, Contribution contribution) {
+ for (Artifact artifact : contribution.getArtifacts()) {
+ if (artifact.getModel() instanceof Composite) {
+ if (name.equalsIgnoreCase(artifact.getURI())) {
+ return (Composite)artifact.getModel();
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * This utility method process each artifact and delegates to proper
+ * artifactProcessor to read the model and generate the in-memory representation
+ *
+ * @param contribution
+ * @param artifacts
+ * @throws ContributionException
+ * @throws MalformedURLException
+ */
+ private void processReadPhase(Contribution contribution, List<URI> artifacts) throws ContributionException,
+ MalformedURLException, XMLStreamException {
+
+ ModelResolver modelResolver = contribution.getModelResolver();
+ URL contributionURL = new URL(contribution.getLocation());
+
+ List<URI> compositeUris = new ArrayList<URI>();
+
+ Object model = null;
+ for (URI anArtifactUri : artifacts) {
+ if ( anArtifactUri.toString().endsWith(COMPOSITE_FILE_EXTN)) {
+ compositeUris.add(anArtifactUri);
+ } else {
+ URL artifactURL = packageProcessor.getArtifactURL(new URL(contribution.getLocation()), anArtifactUri);
+
+ // Add the deployed artifact model to the resolver
+ Artifact artifact = this.contributionFactory.createArtifact();
+ artifact.setURI(anArtifactUri.toString());
+ artifact.setLocation(artifactURL.toString());
+ contribution.getArtifacts().add(artifact);
+ modelResolver.addModel(artifact);
+
+ model = this.artifactProcessor.read(contributionURL, anArtifactUri, artifactURL);
+
+ if (model != null) {
+ artifact.setModel(model);
+
+ // Add the loaded model to the model resolver
+ modelResolver.addModel(model);
+
+ // Add policy definitions to the list of policy definitions
+ if (model instanceof SCADefinitions) {
+ policyDefinitions.add(model);
+
+ SCADefinitions definitions = (SCADefinitions)model;
+ for (Intent intent : definitions.getPolicyIntents() ) {
+ policyDefinitionsResolver.addModel(intent);
+ }
+
+ for (PolicySet policySet : definitions.getPolicySets() ) {
+ policyDefinitionsResolver.addModel(policySet);
+ }
+
+ for (IntentAttachPointType attachPointType : definitions.getBindingTypes() ) {
+ policyDefinitionsResolver.addModel(attachPointType);
+ }
+
+ for (IntentAttachPointType attachPointType : definitions.getImplementationTypes() ) {
+ policyDefinitionsResolver.addModel(attachPointType);
+ }
+ for (Object binding : definitions.getBindings() ) {
+ policyDefinitionsResolver.addModel(binding);
+ }
+ }
+ }
+ }
+ }
+
+ for (URI anArtifactUri : compositeUris) {
+ URL artifactURL = packageProcessor.getArtifactURL(new URL(contribution.getLocation()), anArtifactUri);
+
+ // Add the deployed artifact model to the resolver
+ Artifact artifact = this.contributionFactory.createArtifact();
+ artifact.setURI(anArtifactUri.toString());
+ artifact.setLocation(artifactURL.toString());
+ contribution.getArtifacts().add(artifact);
+ modelResolver.addModel(artifact);
+
+ model = this.artifactProcessor.read(contributionURL, anArtifactUri, artifactURL);
+ if (model != null) {
+ artifact.setModel(model);
+ // Add the loaded model to the model resolver
+ modelResolver.addModel(model);
+ }
+ }
+ }
+
+ /**
+ * This utility method process each artifact and delegates to proper
+ * artifactProcessor to resolve the model references
+ *
+ * @param contribution
+ * @throws ContributionException
+ */
+ @SuppressWarnings("unchecked")
+ private void processResolvePhase(Contribution contribution) throws ContributionException {
+ List<Artifact> composites = new ArrayList<Artifact>();
+
+ // for each artifact that was processed on the contribution
+ for (Artifact artifact : contribution.getArtifacts()) {
+ //leave the composites to be resolved at the end
+ if (artifact.getURI().endsWith(".composite")) {
+ composites.add(artifact);
+ } else {
+ // resolve the model object
+ if (artifact.getModel() != null) {
+ // System.out.println("Processing Resolve Phase : " + artifact.getURI());
+ this.artifactProcessor.resolve(artifact.getModel(), contribution.getModelResolver());
+ }
+ }
+ }
+
+ //process each composite file
+ for (Artifact artifact : composites) {
+ // resolve the model object
+ if (artifact.getModel() != null) {
+ this.artifactProcessor.resolve(artifact.getModel(), contribution.getModelResolver());
+ }
+ }
+
+ //resolve deployables from contribution metadata
+ List<Composite> resolvedDeployables = new ArrayList<Composite>();
+ for (Composite deployableComposite : contribution.getDeployables()) {
+ Composite resolvedDeployable =
+ contribution.getModelResolver().resolveModel(Composite.class, deployableComposite);
+
+ resolvedDeployables.add(resolvedDeployable);
+ }
+ contribution.getDeployables().clear();
+ contribution.getDeployables().addAll(resolvedDeployables);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImpl.java b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImpl.java
new file mode 100644
index 0000000000..9f04c4af27
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/impl/PackageTypeDescriberImpl.java
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.service.impl;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.contribution.PackageType;
+import org.apache.tuscany.sca.contribution.service.TypeDescriber;
+import org.apache.tuscany.sca.contribution.service.util.FileHelper;
+
+/**
+ * Implementation of the content describer for contribution packages
+ *
+ * @version $Rev$ $Date$
+ */
+public class PackageTypeDescriberImpl implements TypeDescriber {
+ private final Map<String, String> contentTypeRegistry = new HashMap<String, String>();
+
+ public PackageTypeDescriberImpl() {
+ super();
+ init();
+ }
+
+ /**
+ * Initialize contentType registry with know types based on known file extensions
+ */
+ private void init() {
+ contentTypeRegistry.put("JAR", PackageType.JAR);
+ contentTypeRegistry.put("WAR", PackageType.JAR);
+ }
+
+ protected String resolveContentyTypeByExtension(URL resourceURL) {
+ String artifactExtension = FileHelper.getExtension(resourceURL.getPath());
+ if (artifactExtension == null) {
+ return null;
+ }
+ return contentTypeRegistry.get(artifactExtension.toUpperCase());
+ }
+
+ /**
+ * Build contentType for a specific resource. We first check if the file is a supported one
+ * (looking into our registry based on resource extension) If not found, we try to check file
+ * contentType Or we return defaultContentType provided
+ *
+ * @param resourceURL The artifact URL
+ * @param defaultContentType The default content type if we can't find the correct one
+ * @return The content type
+ */
+ public String getType(URL resourceURL, String defaultContentType) {
+ URLConnection connection = null;
+ String contentType = defaultContentType;
+ final String urlProtocol = resourceURL.getProtocol();
+
+ if (urlProtocol.equals("file")) {
+ final File fileOrDir = FileHelper.toFile(resourceURL);
+ // Allow privileged access to test file. Requires FilePermissions in security policy.
+ Boolean isDirectory = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+ public Boolean run() {
+ return fileOrDir.isDirectory();
+ }
+ });
+ if (isDirectory) {
+ // Special case : contribution is a folder
+ contentType = PackageType.FOLDER;
+ }
+
+ String type = resolveContentyTypeByExtension(resourceURL);
+ if (type != null) {
+ return type;
+ }
+ } else if (urlProtocol.equals("bundle") || urlProtocol.equals("bundleresource")) {
+ contentType = PackageType.BUNDLE;
+ } else {
+ contentType = resolveContentyTypeByExtension(resourceURL);
+ if (contentType == null) {
+ try {
+ connection = resourceURL.openConnection();
+ connection.setUseCaches(false);
+ contentType = connection.getContentType();
+
+ if (contentType == null || contentType.equals("content/unknown")) {
+ // here we couldn't figure out from our registry or from URL and it's not a
+ // special file
+ // return defaultContentType if provided
+ contentType = defaultContentType;
+ }
+ } catch (IOException io) {
+ // could not access artifact, just ignore and we will return
+ // null contentType
+ }
+ }
+ }
+ return contentType == null ? defaultContentType : contentType;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/FileHelper.java b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/FileHelper.java
new file mode 100644
index 0000000000..cd5e87ca42
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/FileHelper.java
@@ -0,0 +1,701 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.service.util;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.net.URL;
+import java.util.regex.Pattern;
+
+public class FileHelper {
+ /**
+ * The extension separator character.
+ */
+ private static final char EXTENSION_SEPARATOR = '.';
+
+ /**
+ * The Unix separator character.
+ */
+ private static final char UNIX_SEPARATOR = '/';
+
+ /**
+ * The Windows separator character.
+ */
+ private static final char WINDOWS_SEPARATOR = '\\';
+
+ /**
+ * Returns the index of the last directory separator character.
+ * <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()) { //NOPMD
+ throw new IOException("Destination '" + destFile + "' directory cannot be created");
+ }
+ }
+ if (!(destFile.exists() && destFile.canWrite())) {
+ throw new IOException("Destination '" + destFile + "' exists but is read-only");
+ }
+ doCopyFile(srcFile, destFile, preserveFileDate);
+ }
+
+ // -----------------------------------------------------------------------
+ /**
+ * Copies a file to a directory preserving the file date.
+ * <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/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/IOHelper.java b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/IOHelper.java
new file mode 100644
index 0000000000..630d1f6bf4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/java/org/apache/tuscany/sca/contribution/service/util/IOHelper.java
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.service.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.JarURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.jar.JarFile;
+
+public class IOHelper {
+ /**
+ * The default buffer size to use.
+ */
+ private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
+
+ /**
+ * Unconditionally close an <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 {
+ URLConnection connection = url.openConnection();
+ connection.setUseCaches(false);
+ is = connection.getInputStream();
+ }
+ }
+
+ public SafeURLInputStream(JarURLConnection connection) throws IOException {
+ // We cannot use cache
+ connection.setUseCaches(false);
+ is = connection.getInputStream();
+ jarFile = connection.getJarFile();
+ }
+
+ @Override
+ public int available() throws IOException {
+ return is.available();
+ }
+
+ @Override
+ public void close() throws IOException {
+ is.close();
+ // We need to close the JAR file
+ if (jarFile != null) {
+ jarFile.close();
+ }
+ }
+
+ @Override
+ public synchronized void mark(int readlimit) {
+ is.mark(readlimit);
+ }
+
+ @Override
+ public boolean markSupported() {
+ return is.markSupported();
+ }
+
+ @Override
+ public int read() throws IOException {
+ return is.read();
+ }
+
+ @Override
+ public int read(byte[] b, int off, int len) throws IOException {
+ return is.read(b, off, len);
+ }
+
+ @Override
+ public int read(byte[] b) throws IOException {
+ return is.read(b);
+ }
+
+ @Override
+ public synchronized void reset() throws IOException {
+ is.reset();
+ }
+
+ @Override
+ public long skip(long n) throws IOException {
+ return is.skip(n);
+ }
+ }
+} \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessor b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessor
new file mode 100644
index 0000000000..b644709266
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessor
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.contribution.processor.impl.FolderContributionProcessor;type=application/vnd.tuscany.folder
+org.apache.tuscany.sca.contribution.processor.impl.JarContributionProcessor;type=application/x-compressed
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/resources/contribution-impl-validation-messages.properties b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/resources/contribution-impl-validation-messages.properties
new file mode 100644
index 0000000000..158ee2102d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/main/resources/contribution-impl-validation-messages.properties
@@ -0,0 +1,28 @@
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+ContributionURINull =URI for the contribution is null
+SourceURLNull = Source URL for the contribution is null
+ContributionContentNull = The content of the contribution is null
+PrivilegedActionException = Exception occured due to FilePermissions in security policy file
+RootNotDirectory = The root is not a directory {0}
+IllegalArgumentException = IllegalArgumentException occured due to :
+DomainFileNotFound = Domain file "sca-domain.xml" not found ({0})
+MalformedURLException = MalformedURLException occured due to : \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/FolderContributionPackageProcessorTestCase.java b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/FolderContributionPackageProcessorTestCase.java
new file mode 100644
index 0000000000..c33b31b550
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/FolderContributionPackageProcessorTestCase.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.processor;
+
+import java.io.File;
+import java.net.URI;
+import java.net.URL;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.contribution.processor.impl.FolderContributionProcessor;
+
+/**
+ * Folder Package Processor test case
+ * Verifies proper handle of File System structured contributions
+ *
+ * @version $Rev$ $Date$
+ */
+public class FolderContributionPackageProcessorTestCase extends TestCase {
+ private static final String FOLDER_CONTRIBUTION = ".";
+
+ public final void testProcessPackageArtifacts() throws Exception {
+ FolderContributionProcessor folderProcessor = new FolderContributionProcessor();
+ URL contributionURL = new File(FOLDER_CONTRIBUTION).toURL().toURI().toURL();
+
+ List<URI> artifacts = folderProcessor.getArtifacts(contributionURL, null);
+ assertNotNull(artifacts);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/JarContributionPackageProcessorTestCase.java b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/JarContributionPackageProcessorTestCase.java
new file mode 100644
index 0000000000..9b3dce7029
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/JarContributionPackageProcessorTestCase.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.processor;
+
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.contribution.processor.impl.JarContributionProcessor;
+import org.apache.tuscany.sca.contribution.service.util.IOHelper;
+
+/**
+ * JAR Package Processor test case
+ * Verifies proper handle of JAR Archives contributions
+ *
+ * @version $Rev$ $Date$
+ */
+
+public class JarContributionPackageProcessorTestCase extends TestCase {
+ private static final String JAR_CONTRIBUTION = "/repository/sample-calculator.jar";
+
+ public final void testProcessPackageArtifacts() throws Exception {
+ JarContributionProcessor jarProcessor = new JarContributionProcessor();
+
+ URL jarURL = getClass().getResource(JAR_CONTRIBUTION);
+ InputStream jarStream = jarURL.openStream();
+ List<URI> artifacts = null;
+ try {
+ artifacts = jarProcessor.getArtifacts(jarURL, jarStream);
+ } finally {
+ IOHelper.closeQuietly(jarStream);
+ }
+
+ assertNotNull(artifacts);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java
new file mode 100644
index 0000000000..46b4183380
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/processor/URLartifactProcessorExtensionPointTestCase.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.processor;
+
+import java.net.URI;
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+
+
+/**
+ * URL Artifact Processor Extension Point test case
+ * Verifies the right registration and lookup for processors that handle filename and file types
+ *
+ * @version $Rev$ $Date$
+ */
+public class URLartifactProcessorExtensionPointTestCase extends TestCase {
+
+ private URLArtifactProcessorExtensionPoint artifactProcessors;
+
+ @Override
+ protected void setUp() throws Exception {
+ ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ artifactProcessors = new DefaultURLArtifactProcessorExtensionPoint(extensionPoints);
+ artifactProcessors.addArtifactProcessor(new FileTypeArtifactProcessor());
+ artifactProcessors.addArtifactProcessor(new FileNameArtifactProcessor());
+ }
+
+
+ public final void testFileTypeProcessor() {
+ assertNotNull(artifactProcessors.getProcessor(".m1"));
+ }
+
+
+ public final void testFileNameProcessor() {
+ assertNotNull(artifactProcessors.getProcessor("file.m2"));
+
+ }
+
+ /**
+ * Internal mock classes
+ *
+ */
+
+ private class M1 {
+ }
+
+ private class M2 {
+ }
+
+ private class FileTypeArtifactProcessor implements URLArtifactProcessor<M1> {
+ public FileTypeArtifactProcessor() {
+ }
+
+ public M1 read(URL contributionURL, URI uri, URL url) throws ContributionReadException {
+ return null;
+ }
+
+ public void resolve(M1 m1, ModelResolver resolver) throws ContributionResolveException {
+ }
+
+ public String getArtifactType() {
+ return ".m1";
+ }
+
+ public Class<M1> getModelType() {
+ return M1.class;
+ }
+ }
+
+ private class FileNameArtifactProcessor implements URLArtifactProcessor<M2> {
+ public FileNameArtifactProcessor() {
+ }
+
+ public M2 read(URL contributionURL, URI uri, URL url) throws ContributionReadException {
+ return null;
+ }
+
+ public void resolve(M2 m2, ModelResolver resolver) throws ContributionResolveException {
+ }
+
+ public String getArtifactType() {
+ return "file.m2";
+ }
+
+ public Class<M2> getModelType() {
+ return M2.class;
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverTestCase.java b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverTestCase.java
new file mode 100644
index 0000000000..98852e951c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverTestCase.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.resolver;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.contribution.Artifact;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.DefaultContributionFactory;
+
+/**
+ * Test the default model resolver implementation.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultModelResolverTestCase extends TestCase {
+
+ private ModelResolver resolver;
+ private ContributionFactory factory;
+
+ @Override
+ protected void setUp() throws Exception {
+ resolver = new DefaultModelResolver();
+ factory = new DefaultContributionFactory();
+ }
+
+ public void testResolved() {
+ Model a = new Model("a");
+ resolver.addModel(a);
+ Model x = new Model("a");
+ x = resolver.resolveModel(Model.class, x);
+ assertTrue(x == a);
+ }
+
+ public void testUnresolved() {
+ Model x = new Model("a");
+ Model y = resolver.resolveModel(Model.class, x);
+ assertTrue(x == y);
+ }
+
+ public void testResolvedArtifact() {
+ Artifact artifact = factory.createArtifact();
+ artifact.setURI("foo/bar");
+ resolver.addModel(artifact);
+ Artifact x = factory.createArtifact();
+ x.setURI("foo/bar");
+ x = resolver.resolveModel(Artifact.class, x);
+ assertTrue(x == artifact);
+ }
+
+ class Model {
+ private String name;
+
+ Model(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return name.equals(((Model)obj).name);
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java
new file mode 100644
index 0000000000..01083cc6a6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolverTestCase.java
@@ -0,0 +1,126 @@
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.resolver;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.contribution.Artifact;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.DefaultContributionFactory;
+import org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+
+/**
+ * Test DefaultArtifactResolver.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ExtensibleModelResolverTestCase extends TestCase {
+ private ExtensibleModelResolver resolver;
+
+ private ContributionFactory factory;
+
+ @Override
+ protected void setUp() throws Exception {
+
+ ModelResolverExtensionPoint resolvers = new DefaultModelResolverExtensionPoint();
+ resolvers.addResolver(Model.class, TestModelResolver.class);
+
+ ModelFactoryExtensionPoint factories = new DefaultModelFactoryExtensionPoint();
+
+ resolver = new ExtensibleModelResolver(null, resolvers, factories, null);
+
+ factory = new DefaultContributionFactory();
+ }
+
+ public void testResolvedDefault() {
+ OtherModel a = new OtherModel("a");
+ resolver.addModel(a);
+ OtherModel x = new OtherModel("a");
+ x = resolver.resolveModel(OtherModel.class, x);
+ assertTrue(x == a);
+ }
+
+ public void testResolvedRegisteredClass() {
+ Model a = new Model("a");
+ resolver.addModel(a);
+ Model x = new Model("a");
+ x = resolver.resolveModel(Model.class, x);
+ assertTrue(x == a);
+ }
+
+ public void testUnresolvedDefault() {
+ OtherModel x = new OtherModel("a");
+ OtherModel y = resolver.resolveModel(OtherModel.class, x);
+ assertTrue(x == y);
+ }
+
+ public void testUnresolved() {
+ Model x = new Model("a");
+ Model y = resolver.resolveModel(Model.class, x);
+ assertTrue(x == y);
+ }
+
+ public void testResolvedArtifact() {
+ Artifact artifact = factory.createArtifact();
+ artifact.setURI("foo/bar");
+ resolver.addModel(artifact);
+ Artifact x = factory.createArtifact();
+ x.setURI("foo/bar");
+ x = resolver.resolveModel(Artifact.class, x);
+ assertTrue(x == artifact);
+ }
+
+ private class Model {
+ private String name;
+
+ Model(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return name.equals(((Model)obj).name);
+ }
+ }
+
+ private class OtherModel {
+ private String name;
+
+ OtherModel(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public int hashCode() {
+ return name.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return name.equals(((OtherModel)obj).name);
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java
new file mode 100644
index 0000000000..66ecd33da6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/resolver/TestModelResolver.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.resolver;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+
+/**
+ * A test implementation of a model resolver, based on a map.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestModelResolver implements ModelResolver {
+
+ private Map<Object, Object> map = new HashMap<Object, Object>();
+
+ public TestModelResolver(Contribution contribution, ModelFactoryExtensionPoint modelFactories) {
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ Object resolved = map.get(unresolved);
+ if (resolved != null) {
+ // Return the resolved object
+ return modelClass.cast(resolved);
+ }
+ // Return the unresolved object
+ return unresolved;
+ }
+
+ public void addModel(Object resolved) {
+ map.put(resolved, resolved);
+ }
+
+ public Object removeModel(Object resolved) {
+ return map.remove(resolved);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContributionRepositoryTestCase.java b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContributionRepositoryTestCase.java
new file mode 100644
index 0000000000..2e5354fb96
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/ContributionRepositoryTestCase.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.services;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+
+import javax.xml.stream.XMLInputFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.contribution.service.impl.ContributionRepositoryImpl;
+import org.apache.tuscany.sca.contribution.service.util.FileHelper;
+
+public class ContributionRepositoryTestCase extends TestCase {
+ private ContributionRepositoryImpl repository;
+
+ @Override
+ protected void setUp() throws Exception {
+ // create repository (this should re-create the root directory)
+ this.repository = new ContributionRepositoryImpl("target/repository/", XMLInputFactory.newInstance(), null);
+ repository.init();
+ }
+
+ public void testStore() throws Exception {
+ String resourceLocation = "/repository/sample-calculator.jar";
+ String contribution = "sample-calculator.jar";
+ URL contributionLocation = getClass().getResource(resourceLocation);
+ InputStream contributionStream = getClass().getResourceAsStream(resourceLocation);
+ repository.store(contribution, contributionLocation, contributionStream);
+
+ URL contributionURL = repository.find(contribution);
+ assertNotNull(contributionURL);
+ }
+
+ public void testRemove() throws Exception {
+ String resourceLocation = "/repository/sample-calculator.jar";
+ String contribution = "sample-calculator.jar";
+ URL contributionLocation = getClass().getResource(resourceLocation);
+ InputStream contributionStream = getClass().getResourceAsStream(resourceLocation);
+ repository.store(contribution, contributionLocation, contributionStream);
+
+ repository.remove(contribution);
+ URL contributionURL = repository.find(contribution);
+ assertNull(contributionURL);
+ }
+
+ public void testList() throws Exception {
+ String resourceLocation = "/repository/sample-calculator.jar";
+ String contribution = "sample-calculator.jar";
+ URL contributionLocation = getClass().getResource(resourceLocation);
+ InputStream contributionStream = getClass().getResourceAsStream(resourceLocation);
+ repository.store(contribution, contributionLocation, contributionStream);
+
+ assertEquals(1, repository.list().size());
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ FileHelper.deleteDirectory(new File("target/repository"));
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/PackageTypeDescriberImplTestCase.java b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/PackageTypeDescriberImplTestCase.java
new file mode 100644
index 0000000000..dfb600153e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/java/org/apache/tuscany/sca/contribution/services/PackageTypeDescriberImplTestCase.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.services;
+
+import java.net.URL;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.contribution.PackageType;
+import org.apache.tuscany.sca.contribution.service.impl.PackageTypeDescriberImpl;
+
+public class PackageTypeDescriberImplTestCase extends TestCase {
+ private PackageTypeDescriberImpl packageTypeDescriber;
+
+ public void testResolveArchivePackageType() throws Exception {
+ URL artifactURL = getClass().getResource("/deployables/sample-calculator.jar");
+ assertEquals(PackageType.JAR, this.packageTypeDescriber.getType(artifactURL, null));
+ }
+
+ public void testResolveFolderPackageType() throws Exception {
+ URL artifactURL = getClass().getResource("/deployables/");
+ assertEquals(PackageType.FOLDER, this.packageTypeDescriber.getType(artifactURL, null));
+ }
+
+ public void testResolveFolder2PackageType() throws Exception {
+ URL artifactURL = getClass().getResource("/deployables");
+ assertEquals(PackageType.FOLDER, this.packageTypeDescriber.getType(artifactURL, null));
+ }
+
+
+ public void testResolveUnknownPackageType() throws Exception {
+ URL artifactURL = getClass().getResource("/test.ext");
+ assertNull(this.packageTypeDescriber.getType(artifactURL, null));
+ }
+
+ public void testDefaultPackageType() throws Exception {
+ URL artifactURL = getClass().getResource("/test.ext");
+ assertEquals("application/vnd.tuscany.ext",
+ packageTypeDescriber.getType(artifactURL, "application/vnd.tuscany.ext"));
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ packageTypeDescriber = new PackageTypeDescriberImpl();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/resources/deployables/sample-calculator.jar b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/resources/deployables/sample-calculator.jar
new file mode 100644
index 0000000000..0ca3a1b781
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/resources/deployables/sample-calculator.jar
Binary files differ
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/resources/repository/sample-calculator.jar b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/resources/repository/sample-calculator.jar
new file mode 100644
index 0000000000..9c46c679d2
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/resources/repository/sample-calculator.jar
Binary files differ
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/resources/test.composite b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/resources/test.composite
new file mode 100644
index 0000000000..1e09549194
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/resources/test.composite
@@ -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/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/resources/test.ext b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/resources/test.ext
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-impl/src/test/resources/test.ext
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/LICENSE b/sca-java-1.x/branches/sca-android/modules/contribution-java/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/META-INF/README b/sca-java-1.x/branches/sca-android/modules/contribution-java/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/NOTICE b/sca-java-1.x/branches/sca-android/modules/contribution-java/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/pom.xml b/sca-java-1.x/branches/sca-android/modules/contribution-java/pom.xml
new file mode 100644
index 0000000000..153a4f7c5e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/pom.xml
@@ -0,0 +1,77 @@
+<?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.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-contribution-java</artifactId>
+ <name>Apache Tuscany SCA Java Import/Export Model</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core-spi</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ <version>3.2.1</version>
+ <scope>runtime</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.contribution.java</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.contribution.java*</Export-Package>
+ <DynamicImport-Package>org.apache.tuscany.sca.contribution.osgi.impl</DynamicImport-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultJavaImportExportFactory.java b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultJavaImportExportFactory.java
new file mode 100644
index 0000000000..886c61c00a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/DefaultJavaImportExportFactory.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.java;
+
+import org.apache.tuscany.sca.contribution.java.impl.JavaImportExportFactoryImpl;
+
+/**
+ * Default Java Import/Export Factory implementation
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultJavaImportExportFactory extends JavaImportExportFactoryImpl implements JavaImportExportFactory {
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaExport.java b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaExport.java
new file mode 100644
index 0000000000..41e93ec148
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaExport.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.java;
+
+import org.apache.tuscany.sca.contribution.Export;
+
+/**
+ * Base Java Export model interface
+ *
+ * @version $Rev$ $Date$
+ */
+public interface JavaExport extends Export {
+ /**
+ * Get java package that identifies the import
+ *
+ * @return The package name
+ */
+ String getPackage();
+
+ /**
+ * Set java package that identifies the import
+ *
+ * @param packageName The package name
+ */
+ void setPackage(String packageName);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImport.java b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImport.java
new file mode 100644
index 0000000000..d3568f6283
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImport.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.java;
+
+import org.apache.tuscany.sca.contribution.Import;
+
+/**
+ * Base Java Import model interface
+ *
+ * @version $Rev$ $Date$
+ */
+public interface JavaImport extends Import {
+
+ /**
+ * Get the location used to resolve the definitions for this import
+ *
+ * @return The import location
+ */
+ String getLocation();
+
+ /**
+ * Set the location used to resolve the definitions for this import
+ *
+ * @param location The import location
+ */
+ void setLocation(String location);
+
+ /**
+ * Get java package that identifies the import
+ *
+ * @return The package name
+ */
+ String getPackage();
+
+ /**
+ * Set java package that identifies the import
+ *
+ * @param packageName The package name
+ */
+ void setPackage(String packageName);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImportExportFactory.java b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImportExportFactory.java
new file mode 100644
index 0000000000..af2ca9cd57
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/JavaImportExportFactory.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.java;
+
+/**
+ * Base Java Import/Export model factory
+ *
+ * @version $Rev$ $Date$
+ */
+public interface JavaImportExportFactory {
+
+ /**
+ * Create a java import model object
+ *
+ * @return The new JavaImport model object
+ */
+ JavaImport createJavaImport();
+
+ /**
+ * Create a java export model object
+ *
+ * @return The new JavaExport model object
+ */
+ JavaExport createJavaExport();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java
new file mode 100644
index 0000000000..61c73bf2f8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassLoaderModelResolver.java
@@ -0,0 +1,161 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.java.impl;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.Import;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.java.JavaImport;
+import org.apache.tuscany.sca.contribution.resolver.ClassReference;
+import org.apache.tuscany.sca.contribution.resolver.DefaultDelegatingModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+
+/**
+ * A Model Resolver for ClassReferences.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ClassLoaderModelResolver extends URLClassLoader implements ModelResolver {
+ private Contribution contribution;
+ private Map<String, ModelResolver> importResolvers = new HashMap<String, ModelResolver>();
+
+ private static ClassLoader parentClassLoader() {
+ ClassLoader parentClassLoader = ServiceDiscovery.getInstance().getServiceDiscoverer().getClass().getClassLoader();
+ return parentClassLoader;
+ }
+
+ public ClassLoaderModelResolver(final Contribution contribution, ModelFactoryExtensionPoint modelFactories) throws MalformedURLException {
+ super(new URL[] {new URL(contribution.getLocation())}, parentClassLoader());
+ this.contribution = contribution;
+
+ // Index Java import resolvers by package name
+ Map<String, List<ModelResolver>> resolverMap = new HashMap<String, List<ModelResolver>>();
+ for (Import import_: this.contribution.getImports()) {
+ if (import_ instanceof JavaImport) {
+ JavaImport javaImport = (JavaImport)import_;
+ List<ModelResolver> resolvers = resolverMap.get(javaImport.getPackage());
+ if (resolvers == null) {
+ resolvers = new ArrayList<ModelResolver>();
+ resolverMap.put(javaImport.getPackage(), resolvers);
+ }
+ resolvers.add(javaImport.getModelResolver());
+ }
+ }
+
+ // Create a delegating model resolver for each imported package
+ for (Map.Entry<String, List<ModelResolver>> entry: resolverMap.entrySet()) {
+ importResolvers.put(entry.getKey(), new DefaultDelegatingModelResolver(entry.getValue()));
+ }
+ }
+
+ public void addModel(Object resolved) {
+ throw new IllegalStateException();
+ }
+
+ public Object removeModel(Object resolved) {
+ throw new IllegalStateException();
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ if (!(unresolved instanceof ClassReference)) {
+ return unresolved;
+ }
+
+ try {
+
+ // Load the class and return a class reference for it
+ String className = ((ClassReference)unresolved).getClassName();
+ Class<?> clazz = Class.forName(className, true, this);
+ return modelClass.cast(new ClassReference(clazz));
+
+ } catch (ClassNotFoundException e) {
+ return unresolved;
+ } catch (NoClassDefFoundError e) {
+ return unresolved;
+ }
+ }
+
+ @Override
+ public URL findResource(String name) {
+
+ //TODO delegate to the Java import resolvers
+
+ URL url = super.findResource(name);
+ return url;
+ }
+
+ @Override
+ public Enumeration<URL> findResources(String name) throws IOException {
+
+ //TODO delegate to the Java import resolvers
+ //Enumeration<URL> importedResources;
+
+ Enumeration<URL> resources = super.findResources(name);
+ List<URL> allResources = new ArrayList<URL>();
+ //for (; importedResources.hasMoreElements(); ) {
+ // allResources.add(importedResources.nextElement());
+ //}
+ for (; resources.hasMoreElements(); ) {
+ allResources.add(resources.nextElement());
+ }
+ return Collections.enumeration(allResources);
+ }
+
+ @Override
+ protected Class<?> findClass(String name) throws ClassNotFoundException {
+
+ // Extract the package name
+ int d = name.lastIndexOf('.');
+ String packageName;
+ if (d != -1) {
+ packageName = name.substring(0, d);
+ } else {
+ packageName = null;
+ }
+
+ // First try to load the class using the Java import resolvers
+ ModelResolver importResolver = importResolvers.get(packageName);
+ if (importResolver != null) {
+ ClassReference classReference = importResolver.resolveModel(ClassReference.class, new ClassReference(name));
+ if (!classReference.isUnresolved()) {
+ return classReference.getJavaClass();
+ }
+ }
+
+ // Next, try to load the class from the current contribution
+ Class<?> clazz = super.findClass(name);
+ return clazz;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java
new file mode 100644
index 0000000000..962512a745
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceModelResolver.java
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.java.impl;
+
+import java.lang.ref.WeakReference;
+import java.lang.reflect.Constructor;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ClassReference;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+
+/**
+ * A Model Resolver for ClassReferences.
+ *
+ * @version $Rev: 557916 $ $Date: 2007-07-20 01:04:40 -0700 (Fri, 20 Jul 2007) $
+ */
+public class ClassReferenceModelResolver implements ModelResolver {
+ private Contribution contribution;
+ private WeakReference<ClassLoader> classLoader;
+ private Map<String, ClassReference> map = new HashMap<String, ClassReference>();
+
+ private ModelResolver osgiResolver;
+
+ public ClassReferenceModelResolver(final Contribution contribution, ModelFactoryExtensionPoint modelFactories) {
+ this.contribution = contribution;
+ if (this.contribution != null) {
+ // Allow privileged access to get ClassLoader. Requires RuntimePermission in security policy.
+ // ClassLoader cl = contribution.getClassLoader();
+ ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+ public ClassLoader run() {
+ return contribution.getClassLoader();
+ }
+ });
+
+ if (cl == null) {
+ // Allow privileged access to get ClassLoader. Requires RuntimePermission in security policy.
+ //ClassLoader contextClassLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+ // public ClassLoader run() {
+ // return Thread.currentThread().getContextClassLoader();
+ // }
+ //});
+ ClassLoader contextClassLoader = ServiceDiscovery.getInstance().getServiceDiscoverer().getClass().getClassLoader();
+ cl = new ContributionClassLoader(contribution, contextClassLoader);
+ contribution.setClassLoader(cl);
+ }
+ this.classLoader = new WeakReference<ClassLoader>(cl);
+ } else {
+ // This path should be used only for unit testing.
+ // Allow privileged access to get ClassLoader. Requires RuntimePermission in security policy.
+ // this.classLoader = new WeakReference<ClassLoader>(this.getClass().getClassLoader());
+ ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+ public ClassLoader run() {
+ return this.getClass().getClassLoader();
+ }
+ });
+ this.classLoader = new WeakReference<ClassLoader>( cl );
+ }
+
+ try {
+ Class<?> osgiResolverClass =
+ Class.forName("org.apache.tuscany.sca.contribution.osgi.impl.OSGiClassReferenceModelResolver");
+ if (osgiResolverClass != null) {
+ Constructor constructor =
+ osgiResolverClass.getConstructor(Contribution.class, ModelFactoryExtensionPoint.class);
+ this.osgiResolver = (ModelResolver)constructor.newInstance(contribution, modelFactories);
+ }
+ } catch (Throwable e) {
+ // Ignore error, non-OSGi classloading is used in this case
+ }
+ }
+
+ public void addModel(Object resolved) {
+ ClassReference clazz = (ClassReference)resolved;
+ map.put(clazz.getClassName(), clazz);
+ }
+
+ public Object removeModel(Object resolved) {
+ return map.remove(((ClassReference)resolved).getClassName());
+ }
+
+
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ if (!(unresolved instanceof ClassReference)) {
+ return unresolved;
+ }
+ Object resolved = map.get(((ClassReference)unresolved).getClassName());
+
+ if (resolved != null) {
+ return modelClass.cast(resolved);
+ }
+
+ //Load a class on demand
+ Class clazz = null;
+
+ if (osgiResolver != null) {
+ resolved = osgiResolver.resolveModel(modelClass, unresolved);
+ clazz = ((ClassReference)resolved).getJavaClass();
+ }
+
+ if (clazz == null) {
+ try {
+ // Search contribution ClassLoader (which has visibility of classes in the contribution
+ // as well as explicitly imported packages from other contributions)
+ clazz = Class.forName(((ClassReference)unresolved).getClassName(), true, classLoader.get());
+ } catch (ClassNotFoundException e) {
+ } catch (NoClassDefFoundError e) {
+ }
+ }
+
+ if (clazz != null) {
+ //if we load the class
+ // Store a new ClassReference wrapping the loaded class
+ ClassReference classReference = new ClassReference(clazz);
+ map.put(clazz.getName(), classReference);
+
+ // Return the resolved ClassReference
+ return modelClass.cast(classReference);
+ } else {
+ return unresolved;
+ }
+
+ }
+
+
+ /***************
+ * Helper methods
+ ***************/
+
+ private String getPackageName(ClassReference clazz) {
+ int pos = clazz.getClassName().lastIndexOf(".");
+ return clazz.getClassName().substring(0, pos);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ContributionClassLoader.java b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ContributionClassLoader.java
new file mode 100644
index 0000000000..aa68925376
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/ContributionClassLoader.java
@@ -0,0 +1,385 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.java.impl;
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.Export;
+import org.apache.tuscany.sca.contribution.Import;
+import org.apache.tuscany.sca.contribution.java.JavaImport;
+
+
+public class ContributionClassLoader extends URLClassLoader {
+// public class ContributionClassLoader {
+
+ private Contribution contribution;
+ // private b urlClassLoader;
+
+ /**
+ * Constructor for contribution ClassLoader
+ *
+ * @param contribution
+ * @param parent
+ * @throws MalformedURLException
+ */
+ public ContributionClassLoader(Contribution contribution, final ClassLoader parent) {
+ super(new URL[0], parent);
+ // Note that privileged use of getContextClassLoader have been promoted to callers.
+ // super(new URL[0], parent == null?Thread.currentThread().getContextClassLoader(): null);
+ this.contribution = contribution;
+ if (contribution.getLocation() != null) {
+ try {
+ this.addURL(new URL(contribution.getLocation()));
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ /*
+ * Return the ClassLoader corresponding to a contribution providing an export
+ * Create a new ClassLoader for the contribution if one does not exist
+ */
+ private ClassLoader getExportClassLoader(Contribution exportingContribution) {
+ ClassLoader cl = exportingContribution.getClassLoader();
+ if (!(cl instanceof ContributionClassLoader)) {
+ if (cl == null) {
+ cl = getParent();
+ }
+
+ cl = new ContributionClassLoader(exportingContribution, cl);
+ exportingContribution.setClassLoader(cl);
+ }
+ return cl;
+ }
+
+ /* (non-Javadoc)
+ * @see java.net.URLClassLoader#findClass(java.lang.String)
+ *
+ * Search path for class:
+ * This contribution
+ * Imported contributions
+ */
+ @Override
+ protected Class<?> findClass(String className) throws ClassNotFoundException {
+
+ Class<?> clazz = null;
+ try {
+ clazz = findClassFromContribution(className);
+ } catch (ClassNotFoundException e) {
+
+ for (Import import_ : this.contribution.getImports()) {
+ if (classNameMatchesImport(className, import_)) {
+ // Delegate the resolution to the imported contribution
+ for (Contribution exportingContribution : ((JavaImportModelResolver)import_.getModelResolver()).getExportContributions()) {
+
+ ClassLoader exportClassLoader = getExportClassLoader(exportingContribution);
+ if (exportClassLoader instanceof ContributionClassLoader) {
+
+ for (Export export : exportingContribution.getExports()) {
+ try {
+ if (import_.match(export)) {
+ clazz = ((ContributionClassLoader)exportClassLoader).findClassFromContribution(className);
+ break;
+ }
+ } catch (ClassNotFoundException e1) {
+ continue;
+ }
+
+ }
+ if (clazz != null) break;
+ }
+ }
+ if (clazz != null) break;
+ }
+ }
+
+ if (clazz == null) throw e;
+ }
+ return clazz;
+ }
+
+
+ /* (non-Javadoc)
+ * @see java.lang.ClassLoader#loadClass(java.lang.String, boolean)
+ *
+ * Search path for class:
+ * Parent ClassLoader
+ * This contribution
+ * Imported contributions
+ *
+ */
+ @Override
+ protected synchronized Class<?> loadClass(String className, boolean resolveClass)
+ throws ClassNotFoundException {
+
+ Class<?> clazz = null;
+ try {
+
+ if (this.getParent() != null)
+ clazz = this.getParent().loadClass(className);
+
+ } catch (ClassNotFoundException e) {
+ }
+
+ if (clazz == null)
+ clazz = findClass(className);
+
+
+ if (resolveClass)
+ this.resolveClass(clazz);
+ return clazz;
+
+ }
+
+
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.net.URLClassLoader#findResource(java.lang.String)
+ */
+ @Override
+ public URL findResource(String name) {
+
+ URL url = findResourceFromContribution(name);
+
+ if (url == null) {
+ for (Import import_ : this.contribution.getImports()) {
+ if (resourceNameMatchesImport(name, import_)) {
+ // Delegate the resolution to the imported contribution
+ for (Contribution exportingContribution : ((JavaImportModelResolver)import_.getModelResolver()).getExportContributions()) {
+
+ ClassLoader exportClassLoader = getExportClassLoader(exportingContribution);
+ if (exportClassLoader instanceof ContributionClassLoader) {
+
+ for (Export export : exportingContribution.getExports()) {
+ if (import_.match(export)) {
+ url = ((ContributionClassLoader)exportClassLoader).findResourceFromContribution(name);
+ if (url != null) break;
+ }
+ }
+ if (url != null) break;
+ }
+ }
+ if (url != null) break;
+ }
+ }
+
+ }
+ return url;
+ }
+
+
+ /* (non-Javadoc)
+ * @see java.net.URLClassLoader#findResources(java.lang.String)
+ */
+ @Override
+ public Enumeration<URL> findResources(String name) throws IOException {
+
+ return Collections.enumeration(findResourceSet(name));
+ }
+
+
+
+
+ /* (non-Javadoc)
+ * @see java.lang.ClassLoader#getResource(java.lang.String)
+ *
+ * Find a resource.
+ * Search path for resource:
+ * Parent ClassLoader
+ * This contribution
+ * Imported contributions
+ */
+ @Override
+ public URL getResource(String resName) {
+
+ URL resource = null;
+
+ if (this.getParent() != null) {
+ resource = this.getParent().getResource(resName);
+ }
+ if (resource == null)
+ resource = findResource(resName);
+
+ return resource;
+ }
+
+
+
+ /* (non-Javadoc)
+ * @see java.lang.ClassLoader#getResources(java.lang.String)
+ *
+ * Return list of resources from this contribution, resources
+ * imported through imported contributions and resources from parent
+ * ClassLoader.
+ */
+ @Override
+ public Enumeration<URL> getResources(String resName) throws IOException {
+
+ HashSet<URL> resourceSet = findResourceSet(resName);
+ addEnumerationToCollection(resourceSet, super.getResources(resName));
+
+ return Collections.enumeration(resourceSet);
+ }
+
+
+ /*
+ * Find set of resources
+ */
+ private HashSet<URL> findResourceSet(String name) throws IOException {
+
+ HashSet<URL> resources = new HashSet<URL>();
+
+ addEnumerationToCollection(resources, super.findResources(name));
+
+ for (Import import_ : this.contribution.getImports()) {
+ if (!(import_ instanceof JavaImport)) {
+ continue;
+ }
+ if (resourceNameMatchesImport(name, import_)) {
+ // Delegate the resolution to the imported contribution
+ for (Contribution exportingContribution : ((JavaImportModelResolver)import_.getModelResolver()).getExportContributions()) {
+
+ ClassLoader exportClassLoader = getExportClassLoader(exportingContribution);
+ if (exportClassLoader instanceof ContributionClassLoader) {
+
+ for (Export export : exportingContribution.getExports()) {
+ if (import_.match(export)) {
+ addEnumerationToCollection(resources,
+ ((ContributionClassLoader)exportClassLoader).findResources(name));
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return resources;
+ }
+
+
+ /*
+ * Find class from contribution. If class has already been loaded, return loaded class.
+ */
+ private Class<?> findClassFromContribution(String className) throws ClassNotFoundException {
+
+ Class<?> clazz = findLoadedClass(className);
+ if (clazz == null)
+ clazz = super.findClass(className);
+ return clazz;
+
+ }
+
+ /*
+ * Find resource from contribution.
+ */
+ private URL findResourceFromContribution(String name) {
+
+ return super.findResource(name);
+ }
+
+ /**
+ * Check if a class name matches an import statement.
+ * Class matches if the package name used in <import.java/> matches
+ *
+ * @param name Name of class
+ * @param import_ SCA contribution import
+ * @return true if this is a matching import
+ */
+ private boolean classNameMatchesImport(String name, Import import_) {
+
+ if (import_ instanceof JavaImport && name != null && name.lastIndexOf('.') > 0) {
+ JavaImport javaImport = (JavaImport) import_;
+
+ String packageName = name.substring(0, name.lastIndexOf('.'));
+ if (javaImport.getPackage().endsWith(".*")) {
+ String prefix = javaImport.getPackage().substring(0, javaImport.getPackage().length() -1);
+ if (packageName.startsWith(prefix)) {
+ return true;
+ }
+ } else {
+ return packageName.equals(javaImport.getPackage());
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * Check if a resource name matches an import statement.
+ * Resource matches if package/namespace match the directory of resource.
+ *
+ * @param name Name of resource
+ * @param import_ SCA contribution import
+ * @return true if this is a matching import
+ */
+ private boolean resourceNameMatchesImport(String name, Import import_) {
+
+
+ if (name == null || name.lastIndexOf('/') <= 0)
+ return false;
+ else if (import_ instanceof JavaImport) {
+ JavaImport javaImport = (JavaImport) import_;
+
+ if (javaImport.getPackage().endsWith(".*")) {
+ String packageName = name.substring(0, name.lastIndexOf('/')).replace('/', '.');
+ String prefix = javaImport.getPackage().substring(0, javaImport.getPackage().length() -1);
+ if (packageName.startsWith(prefix)) {
+ return true;
+ }
+ } else {
+ // 'name' is a resource : contains "/" as separators
+ // Get package name from resource name
+ String packageName = name.substring(0, name.lastIndexOf('/'));
+ return packageName.equals(javaImport.getPackage().replaceAll("\\.", "/"));
+ }
+ }
+ return false;
+ }
+
+ /*
+ * Add an enumeration to a Collection
+ */
+ private <T extends Object> void addEnumerationToCollection(Collection<T> collection, Enumeration<T> enumeration) {
+
+ while (enumeration.hasMoreElements())
+ collection.add(enumeration.nextElement());
+ }
+
+
+ @Override
+ public String toString() {
+ return "SCA Contribution ClassLoader location: " + contribution.getLocation() + " parent ClassLoader: " + getParent();
+ }
+
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportImpl.java b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportImpl.java
new file mode 100644
index 0000000000..f35f35ac4c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportImpl.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.java.impl;
+
+import org.apache.tuscany.sca.contribution.java.JavaExport;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+/**
+ * Implementation of a Java Import model
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaExportImpl implements JavaExport {
+ private ModelResolver modelResolver;
+
+ /**
+ * Java package being exported
+ */
+ private String packageName;
+
+ public JavaExportImpl() {
+ super();
+ }
+
+ public String getPackage() {
+ return this.packageName;
+ }
+
+ public void setPackage(String packageName) {
+ this.packageName = packageName;
+ }
+
+ public ModelResolver getModelResolver() {
+ return modelResolver;
+ }
+
+ public void setModelResolver(ModelResolver modelResolver) {
+ this.modelResolver = modelResolver;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportModelResolver.java b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportModelResolver.java
new file mode 100644
index 0000000000..8d5412f6d7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportModelResolver.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.java.impl;
+
+import org.apache.tuscany.sca.contribution.java.JavaExport;
+import org.apache.tuscany.sca.contribution.resolver.ClassReference;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+/**
+ * A model resolver for Java exports.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaExportModelResolver implements ModelResolver {
+
+ private JavaExport export;
+ private ModelResolver resolver;
+
+ public JavaExportModelResolver(JavaExport export, ModelResolver resolver) {
+ this.export = export;
+ this.resolver = resolver;
+ }
+
+ public void addModel(Object resolved) {
+ throw new IllegalStateException();
+ }
+
+ public Object removeModel(Object resolved) {
+ throw new IllegalStateException();
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ if (!(unresolved instanceof ClassReference)) {
+ return unresolved;
+ }
+
+ // Filter package name
+ ClassReference classReference = (ClassReference)unresolved;
+ String className = classReference.getClassName();
+ int d = className.lastIndexOf('.');
+ String packageName;
+ if (d != -1) {
+ packageName = className.substring(0, d);
+ } else {
+ packageName = "";
+ }
+ if (export.getPackage().equals(packageName)) {
+
+ // Package matches the exported package, delegate to the
+ // contribution's resolver
+ return resolver.resolveModel(modelClass, unresolved);
+ } else {
+
+ // Package is not exported, return the unresolved object
+ return unresolved;
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java
new file mode 100644
index 0000000000..9f6ff52289
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessor.java
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.java.impl;
+
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.java.JavaExport;
+import org.apache.tuscany.sca.contribution.java.JavaImportExportFactory;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ * Artifact processor for Java Export
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaExportProcessor implements StAXArtifactProcessor<JavaExport> {
+ private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0";
+
+ private static final QName EXPORT_JAVA = new QName(SCA10_NS, "export.java");
+
+ private static final String PACKAGE = "package";
+
+ private final JavaImportExportFactory factory;
+ private final Monitor monitor;
+
+ public JavaExportProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
+ super();
+ this.factory = modelFactories.getFactory(JavaImportExportFactory.class);
+ this.monitor = monitor;
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-java-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ public QName getArtifactType() {
+ return EXPORT_JAVA;
+ }
+
+ public Class<JavaExport> getModelType() {
+ return JavaExport.class;
+ }
+
+ /**
+ * Process <export package=""/>
+ */
+ public JavaExport read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ JavaExport javaExport = this.factory.createJavaExport();
+ QName element = null;
+
+ while (reader.hasNext()) {
+ int event = reader.getEventType();
+ switch (event) {
+ case START_ELEMENT:
+ element = reader.getName();
+
+ // Read <export.java>
+ if (EXPORT_JAVA.equals(element)) {
+ String packageName = reader.getAttributeValue(null, PACKAGE);
+ if (packageName == null) {
+ error("AttributePackageMissing", reader);
+ //throw new ContributionReadException("Attribute 'package' is missing");
+ } else
+ javaExport.setPackage(packageName);
+ }
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ if (EXPORT_JAVA.equals(reader.getName())) {
+ return javaExport;
+ }
+ break;
+ }
+
+ //Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
+ }
+
+ return javaExport;
+ }
+
+ public void write(JavaExport javaExport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+
+ // Write <export.java>
+ writer.writeStartElement(EXPORT_JAVA.getNamespaceURI(), EXPORT_JAVA.getLocalPart());
+
+ if (javaExport.getPackage() != null) {
+ writer.writeAttribute(PACKAGE, javaExport.getPackage());
+ }
+
+ writer.writeEndElement();
+ }
+
+ public void resolve(JavaExport javaExport, ModelResolver resolver) throws ContributionResolveException {
+
+ if (javaExport.getPackage() != null)
+ // Initialize the export resolver
+ javaExport.setModelResolver(new JavaExportModelResolver(javaExport, resolver));
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportFactoryImpl.java b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportFactoryImpl.java
new file mode 100644
index 0000000000..e5dc397f4e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportFactoryImpl.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.java.impl;
+
+import org.apache.tuscany.sca.contribution.java.JavaExport;
+import org.apache.tuscany.sca.contribution.java.JavaImport;
+import org.apache.tuscany.sca.contribution.java.JavaImportExportFactory;
+
+/**
+ * Java Import/Export Factory implementation
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaImportExportFactoryImpl implements JavaImportExportFactory {
+
+ public JavaImport createJavaImport() {
+ return new JavaImportImpl();
+ }
+
+ public JavaExport createJavaExport() {
+ return new JavaExportImpl();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportListener.java b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportListener.java
new file mode 100644
index 0000000000..47cdc9767b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportExportListener.java
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.java.impl;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.tuscany.sca.contribution.Artifact;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.Export;
+import org.apache.tuscany.sca.contribution.Import;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.java.JavaExport;
+import org.apache.tuscany.sca.contribution.java.JavaImport;
+import org.apache.tuscany.sca.contribution.resolver.DefaultImportAllModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionListener;
+import org.apache.tuscany.sca.contribution.service.ContributionRepository;
+
+/**
+ * Java Import/Export contribution listener
+ * The listener would process all import/export from a given contribution
+ * and initialize the model resolvers properly
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaImportExportListener implements ContributionListener {
+
+ private ContributionFactory contributionFactory;
+
+ /**
+ * Constructs a new JavaImportExportListener
+ */
+ public JavaImportExportListener(ModelFactoryExtensionPoint modelFactories) {
+ contributionFactory = modelFactories.getFactory(ContributionFactory.class);
+ }
+
+ /**
+ * Initialize the import/export model resolvers
+ * Export model resolvers are same as Contribution model resolver
+ * Import model resolvers are matched to a specific contribution if a location URI is specified,
+ * otherwise it try to resolve against all the other contributions
+ * Also set the exporting contributions used by contribution ClassLoaders to
+ * match import/export for class loading.
+ */
+ public void contributionAdded(ContributionRepository repository, Contribution contribution) {
+
+ // If the contribution does not contain sca-contribution.xml metadata
+ // (for example it's an existing JAR developed before SCA existed)
+ // export all its Java packages
+ ModelResolver modelResolver = contribution.getModelResolver();
+
+ // Look for META-INF/sca-contribution.xml
+ Artifact artifact = contributionFactory.createArtifact();
+ artifact.setURI(Contribution.SCA_CONTRIBUTION_META);
+ artifact = modelResolver.resolveModel(Artifact.class, artifact);
+ if (artifact.getLocation() == null) {
+
+ // Look for META-INF/sca-contribution-generated.xml
+ artifact.setURI(Contribution.SCA_CONTRIBUTION_GENERATED_META);
+ artifact = modelResolver.resolveModel(Artifact.class, artifact);
+ if (artifact.getLocation() == null) {
+
+ // No contribution metadata file was found, default to export all the
+ // Java packages found in the contribution
+ Set<String> packages = new HashSet<String>();
+ for (Artifact a: contribution.getArtifacts()) {
+ String uri = a.getURI();
+ if (uri.endsWith(".class")) {
+ uri = uri.substring(0, uri.length() - 6);
+ int d = uri.lastIndexOf('/');
+ if (d != -1) {
+ packages.add(uri.substring(0, d).replace('/', '.'));
+ }
+ }
+ }
+
+ // Add Java export model objects for all the packages we found
+ for (String pkg: packages) {
+ JavaExport export = new JavaExportImpl();
+ export.setPackage(pkg);
+ contribution.getExports().add(export);
+ }
+ }
+ }
+
+ // Initialize the contribution exports
+ for (Export export: contribution.getExports()) {
+ export.setModelResolver(contribution.getModelResolver());
+ }
+
+ // Initialize the contribution imports
+ for (Import import_: contribution.getImports()) {
+ boolean initialized = false;
+
+ if(import_ instanceof JavaImport) {
+ JavaImport javaImport = (JavaImport) import_;
+
+ //Find a matching contribution
+ if(javaImport.getLocation() != null) {
+ Contribution targetContribution = repository.getContribution(javaImport.getLocation());
+ if (targetContribution != null) {
+
+ // Find a matching contribution export
+ for (Export export: targetContribution.getExports()) {
+ if (export instanceof JavaExport) {
+ JavaExport javaExport = (JavaExport)export;
+ if (javaImport.getPackage().equals(javaExport.getPackage())) {
+ List<Contribution> exportingContributions = new ArrayList<Contribution>();
+ exportingContributions.add(targetContribution);
+ javaImport.setModelResolver(new JavaImportModelResolver(exportingContributions, javaExport.getModelResolver()));
+ initialized = true;
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ //if no location was specified, try to resolve with any contribution
+ if (!initialized) {
+ //Use a resolver that will consider all contributions
+ import_.setModelResolver(new JavaImportModelResolver(repository.getContributions(), new DefaultImportAllModelResolver(import_, repository.getContributions())));
+ }
+ }
+ }
+ }
+
+ public void contributionRemoved(ContributionRepository repository, Contribution contribution) {
+
+ }
+
+ public void contributionUpdated(ContributionRepository repository, Contribution oldContribution, Contribution contribution) {
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportImpl.java b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportImpl.java
new file mode 100644
index 0000000000..cc18d5f798
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportImpl.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.java.impl;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.Export;
+import org.apache.tuscany.sca.contribution.java.JavaExport;
+import org.apache.tuscany.sca.contribution.java.JavaImport;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+/**
+ * Implementation of a Java Import model
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaImportImpl implements JavaImport {
+ private ModelResolver modelResolver;
+ private List<Contribution> contributions;
+ /**
+ * Java package name being imported
+ */
+ private String packageName;
+ /**
+ * Contribution URI where the artifact is imported from
+ */
+ private String location;
+
+ public JavaImportImpl() {
+ super();
+ }
+
+ public String getLocation() {
+ return this.location;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ public String getPackage() {
+ return this.packageName;
+ }
+
+ public void setPackage(String packageName) {
+ this.packageName = packageName;
+ }
+
+ public ModelResolver getModelResolver() {
+ return this.modelResolver;
+ }
+
+ public void setModelResolver(ModelResolver modelResolver) {
+ this.modelResolver = modelResolver;
+ }
+ public List<Contribution> getExportContributions() {
+ return contributions;
+ }
+
+ public void setExportContributions(List<Contribution> contributions) {
+ this.contributions = contributions;
+ }
+
+ /**
+ * Match a JavaImport to a given JavaExport based on :
+ * location is not provided
+ * import and export packages match
+ */
+ public boolean match(Export export) {
+ if(export instanceof JavaExport) {
+ JavaExport javaExport = (JavaExport)export;
+ String exportedPackage = javaExport.getPackage();
+ if (packageName.equals(exportedPackage)) {
+ return true;
+ } else {
+ if (packageName.endsWith(".*")) {
+ String prefix = packageName.substring(0, packageName.length() - 1);
+ if (exportedPackage.startsWith(prefix)) {
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return String.valueOf(packageName);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportModelResolver.java b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportModelResolver.java
new file mode 100644
index 0000000000..484eddd222
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportModelResolver.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.java.impl;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+/**
+ * A JavaImport specific model resolver. This model resolver is temporary
+ * and provides the ContributionClassLoader with the list of exporting
+ * contributions that it currently needs.
+ *
+ * FIXME Remove this class after the ContributionClassLoader is simplified
+ * and cleaned up.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaImportModelResolver implements ModelResolver {
+
+ private ModelResolver modelResolver;
+ private List<Contribution> contributions;
+
+ public JavaImportModelResolver(List<Contribution> contributions, ModelResolver modelResolver) {
+ this.modelResolver = modelResolver;
+ this.contributions = contributions;
+ }
+
+ public List<Contribution> getExportContributions() {
+ return contributions;
+ }
+
+ public void addModel(Object resolved) {
+ modelResolver.addModel(resolved);
+ }
+
+ public Object removeModel(Object resolved) {
+ return modelResolver.removeModel(resolved);
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ return modelResolver.resolveModel(modelClass, unresolved);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java
new file mode 100644
index 0000000000..d027d75b32
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessor.java
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.java.impl;
+
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.java.JavaImport;
+import org.apache.tuscany.sca.contribution.java.JavaImportExportFactory;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ * Artifact Processor for Java Imports
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaImportProcessor implements StAXArtifactProcessor<JavaImport> {
+ private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0";
+
+ private static final QName IMPORT_JAVA = new QName(SCA10_NS, "import.java");
+
+ private static final String PACKAGE = "package";
+ private static final String LOCATION = "location";
+
+ private final JavaImportExportFactory factory;
+ private final Monitor monitor;
+
+ public JavaImportProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
+ super();
+ this.factory = modelFactories.getFactory(JavaImportExportFactory.class);
+ this.monitor = monitor;
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-java-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ public QName getArtifactType() {
+ return IMPORT_JAVA;
+ }
+
+ public Class<JavaImport> getModelType() {
+ return JavaImport.class;
+ }
+
+ /**
+ * Process <import.java package="" location=""/>
+ */
+ public JavaImport read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ JavaImport javaImport = this.factory.createJavaImport();
+ QName element = null;
+
+ while (reader.hasNext()) {
+ int event = reader.getEventType();
+ switch (event) {
+ case START_ELEMENT:
+ element = reader.getName();
+
+ // Read <import.java>
+ if (IMPORT_JAVA.equals(element)) {
+ String packageName = reader.getAttributeValue(null, PACKAGE);
+ if (packageName == null) {
+ error("AttributePackageMissing", reader);
+ //throw new ContributionReadException("Attribute 'package' is missing");
+ } else
+ javaImport.setPackage(packageName);
+
+ String location = reader.getAttributeValue(null, LOCATION);
+ javaImport.setLocation(location);
+ }
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ if (IMPORT_JAVA.equals(reader.getName())) {
+ return javaImport;
+ }
+ break;
+ }
+
+ // Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
+ }
+
+ return javaImport;
+ }
+
+ public void write(JavaImport javaImport, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+
+ // Write <import.java>
+ writer.writeStartElement(IMPORT_JAVA.getNamespaceURI(), IMPORT_JAVA.getLocalPart());
+
+ if (javaImport.getPackage() != null) {
+ writer.writeAttribute(PACKAGE, javaImport.getPackage());
+ }
+ if (javaImport.getLocation() != null) {
+ writer.writeAttribute(LOCATION, javaImport.getLocation());
+ }
+
+ writer.writeEndElement();
+ }
+
+
+ public void resolve(JavaImport model, ModelResolver resolver) throws ContributionResolveException {
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.JavaImportExportFactory b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.JavaImportExportFactory
new file mode 100644
index 0000000000..a293330a57
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.java.JavaImportExportFactory
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.contribution.java.impl.JavaImportExportFactoryImpl
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
new file mode 100644
index 0000000000..ac1fa9aade
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.contribution.java.impl.JavaImportProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#import.java,model=org.apache.tuscany.sca.contribution.java.JavaImport
+org.apache.tuscany.sca.contribution.java.impl.JavaExportProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#export.java,model=org.apache.tuscany.sca.contribution.java.JavaExport
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver
new file mode 100644
index 0000000000..c69eb40636
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.contribution.java.impl.ClassReferenceModelResolver;model=org.apache.tuscany.sca.contribution.resolver.ClassReference
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener
new file mode 100644
index 0000000000..7debb3d3c6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListener
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.contribution.java.impl.JavaImportExportListener
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/resources/contribution-java-validation-messages.properties b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/resources/contribution-java-validation-messages.properties
new file mode 100644
index 0000000000..70b58f75c0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/main/resources/contribution-java-validation-messages.properties
@@ -0,0 +1,22 @@
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+AttributePackageMissing = Attribute 'package' is missing
+
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java
new file mode 100644
index 0000000000..1405ad4bd5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ClassReferenceArtifactResolverTestCase.java
@@ -0,0 +1,70 @@
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.java.impl;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ClassReference;
+import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+
+/**
+ * Test ClassReferenceArtifactResolver.
+ *
+ * @version $Rev: 560435 $ $Date: 2007-07-27 18:26:55 -0700 (Fri, 27 Jul 2007) $
+ */
+public class ClassReferenceArtifactResolverTestCase extends TestCase {
+ private ExtensibleModelResolver resolver;
+
+ @Override
+ protected void setUp() throws Exception {
+ ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+
+ ModelResolverExtensionPoint resolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class);
+ resolvers.addResolver(ClassReference.class, ClassReferenceModelResolver.class);
+ ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ resolver = new ExtensibleModelResolver(null, resolvers, modelFactories);
+ }
+
+ /**
+ * Test ClassReference resolution
+ *
+ */
+ public void testResolveClass() {
+ ClassReference ref = new ClassReference(getClass().getName());
+ ClassReference clazz = resolver.resolveModel(ClassReference.class, ref);
+ assertFalse(clazz.isUnresolved());
+ assertTrue(clazz.getJavaClass() == getClass());
+ }
+
+ /**
+ * Test ClassReference resolution of inexistent class
+ *
+ */
+ public void testUnresolvedClass() {
+ ClassReference ref = new ClassReference("NonExistentClass");
+ ClassReference clazz = resolver.resolveModel(ClassReference.class, ref);
+ assertTrue(clazz.isUnresolved());
+ assertTrue(clazz.getJavaClass() == null);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ContributionClassLoaderTestCase.java b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ContributionClassLoaderTestCase.java
new file mode 100644
index 0000000000..3ae161642d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/ContributionClassLoaderTestCase.java
@@ -0,0 +1,262 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.java.impl;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.java.JavaExport;
+import org.apache.tuscany.sca.contribution.java.JavaImport;
+import org.apache.tuscany.sca.contribution.java.JavaImportExportFactory;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+
+/**
+ * Test ContributionClassLoader.
+ *
+ */
+public class ContributionClassLoaderTestCase {
+
+ private ContributionFactory contributionFactory;
+ private JavaImportExportFactory javaImportExportFactory;
+
+ @Before
+ public void setUp() throws Exception {
+ ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ contributionFactory = modelFactories.getFactory(ContributionFactory.class);
+ javaImportExportFactory = modelFactories.getFactory(JavaImportExportFactory.class);
+ }
+
+ private Contribution createContribution(String fileName) throws MalformedURLException {
+ Contribution contrib = contributionFactory.createContribution();
+ File contribDir = new File(fileName);
+ contrib.setLocation(contribDir.toURI().toURL().toString());
+ ClassLoader contextClassLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+ public ClassLoader run() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ contrib.setClassLoader(new ContributionClassLoader(contrib, contextClassLoader));
+ return contrib;
+ }
+
+
+ @Test
+ public void testClassLoadingFromContribution() throws ClassNotFoundException, MalformedURLException {
+
+ Contribution contribA = createContribution("target/test-classes");
+ Contribution contribB = createContribution("target");
+ Contribution contribC = createContribution("target/test-classes/deployables/sample-calculator.jar");
+
+ // Class present in contribution, also in parent. Class is loaded from parent
+ Class<?> testClassA = contribA.getClassLoader().loadClass(this.getClass().getName());
+ Assert.assertNotNull(testClassA);
+ Assert.assertSame(this.getClass(), testClassA);
+
+ // Class not present in contribution, but present in parent ClassLoader
+ Class<?> testClassB = contribB.getClassLoader().loadClass(this.getClass().getName());
+ Assert.assertNotNull(testClassB);
+ Assert.assertSame(this.getClass(), testClassB);
+
+ // Class present in contribution, but not in parent
+ Class<?> testClassC = contribC.getClassLoader().loadClass("calculator.AddService");
+ Assert.assertNotNull(testClassC);
+
+ // Class not present in contribution or in parent
+ try {
+ contribA.getClassLoader().loadClass("NonExistent");
+
+ Assert.assertTrue("ClassNotFoundException not thrown as expected", false);
+
+ } catch (ClassNotFoundException e) {
+ }
+
+
+
+ }
+
+ @Test
+ public void testResourceLoadingFromContribution() throws ClassNotFoundException, MalformedURLException {
+
+ Contribution contribA = createContribution("target/test-classes");
+ Contribution contribB = createContribution("target");
+ Contribution contribC = createContribution("target/test-classes/deployables/sample-calculator.jar");
+
+ // Resource present in contribution, and in parent
+ URL resA = contribA.getClassLoader().getResource("deployables/sample-calculator.jar");
+ Assert.assertNotNull(resA);
+
+ // Resource not present in contribution, but present in parent ClassLoader
+ URL resB = contribB.getClassLoader().getResource("deployables/sample-calculator.jar");
+ Assert.assertNotNull(resB);
+
+ // Resource present in contribution, but not in parent
+ URL resC = contribC.getClassLoader().getResource("calculator/AddService.class");
+ Assert.assertNotNull(resC);
+
+ // Load Java class as resource from parent
+ String classResName = this.getClass().getName().replaceAll("\\.", "/") + ".class";
+ URL classResA = contribA.getClassLoader().getResource(classResName);
+ Assert.assertNotNull(classResA);
+
+ // Non-existent resource
+ URL res = contribA.getClassLoader().getResource("deployables/NonExistent");
+ Assert.assertNull(res);
+
+ }
+
+ private static String getPackageName(Class<?> cls) {
+ String name = cls.getName();
+ int index = name.lastIndexOf('.');
+ return index == -1 ? "" : name.substring(0, index);
+ }
+
+ @Test
+ public void testClassLoadingFromImportedContribution() throws ClassNotFoundException, MalformedURLException {
+
+ Contribution contribA = createContribution("target/test-classes");
+ Contribution contribB = createContribution("target");
+ Contribution contribC = createContribution("target/test-classes/deployables/sample-calculator.jar");
+ ArrayList<Contribution> exportContribList = new ArrayList<Contribution>();
+ exportContribList.add(contribA);
+ exportContribList.add(contribC);
+
+ JavaImport import_ = javaImportExportFactory.createJavaImport();
+ import_.setPackage(getPackageName(getClass()));
+ import_.setModelResolver(new JavaImportModelResolver(exportContribList, null));
+ contribB.getImports().add(import_);
+ import_ = javaImportExportFactory.createJavaImport();
+ import_.setPackage("calculator");
+ import_.setModelResolver(new JavaImportModelResolver(exportContribList, null));
+ contribB.getImports().add(import_);
+
+ JavaExport export = javaImportExportFactory.createJavaExport();
+ export.setPackage(getPackageName(getClass()));
+ contribA.getExports().add(export);
+ export = javaImportExportFactory.createJavaExport();
+ export.setPackage("calculator");
+ contribC.getExports().add(export);
+
+ // Load class from parent, class is also present in imported contribution. Class should
+ // be loaded from parent
+ Class<?> testClassB = contribB.getClassLoader().loadClass(this.getClass().getName());
+ Assert.assertNotNull(testClassB);
+ Assert.assertSame(this.getClass(), testClassB);
+
+ // Load class from parent, class is also present in parent. Class should be loaded
+ // from parent.
+ Class<?> testClassA = contribA.getClassLoader().loadClass(this.getClass().getName());
+ Assert.assertNotNull(testClassA);
+ Assert.assertSame(this.getClass(), testClassA);
+
+ // Imported class should be the same as the one loaded by the exporting contribution
+ Assert.assertSame(testClassA, testClassB);
+
+ // Load class from imported contribution, class is not present in parent
+ Class<?> testClassB1 = contribB.getClassLoader().loadClass("calculator.AddService");
+ Assert.assertNotNull(testClassB1);
+
+ // Imported class should be the same as the one loaded by the exporting contribution
+ Class<?> testClassC = contribC.getClassLoader().loadClass("calculator.AddService");
+ Assert.assertNotNull(testClassC);
+ Assert.assertSame(testClassC, testClassB1);
+
+
+ // Try to load class from package which is not explicitly imported - should throw ClassNotFoundException
+ try {
+ contribA.getClassLoader().loadClass("calculator.AddService");
+
+ Assert.assertTrue("ClassNotFoundException not thrown as expected", false);
+
+ } catch (ClassNotFoundException e) {
+ }
+
+ // Try to load non-existent class from imported package - should throw ClassNotFoundException
+ try {
+ contribB.getClassLoader().loadClass(getPackageName(getClass()) + ".NonExistentClass");
+
+ Assert.assertTrue("ClassNotFoundException not thrown as expected", false);
+
+ } catch (ClassNotFoundException e) {
+ }
+
+ }
+
+ @Test
+ public void testResourceLoadingFromImportedContribution() throws ClassNotFoundException, MalformedURLException {
+
+ Contribution contribA = createContribution("target/test-classes");
+ Contribution contribB = createContribution("target");
+ Contribution contribC = createContribution("target/test-classes/deployables/sample-calculator.jar");
+
+ ArrayList<Contribution> exportContribList = new ArrayList<Contribution>();
+ exportContribList.add(contribA);
+ exportContribList.add(contribC);
+
+ JavaImport import_ = javaImportExportFactory.createJavaImport();
+ import_.setPackage(getPackageName(getClass()));
+ import_.setModelResolver(new JavaImportModelResolver(exportContribList, null));
+ contribB.getImports().add(import_);
+ JavaImport import1_ = javaImportExportFactory.createJavaImport();
+ import1_.setPackage("calculator");
+ import1_.setModelResolver(new JavaImportModelResolver(exportContribList, null));
+ contribB.getImports().add(import1_);
+
+ JavaExport export = javaImportExportFactory.createJavaExport();
+ export.setPackage(getPackageName(getClass()));
+ contribA.getExports().add(export);
+ JavaExport export1 = javaImportExportFactory.createJavaExport();
+ export1.setPackage("calculator");
+ contribC.getExports().add(export1);
+
+
+ // Load resource from parent
+ URL resB = contribB.getClassLoader().getResource("deployables/sample-calculator.jar");
+ Assert.assertNotNull(resB);
+
+ // Load Java class as resource from imported contribution with JavaImport
+ String classResName = this.getClass().getName().replaceAll("\\.", "/") + ".class";
+ URL classResB = contribB.getClassLoader().getResource(classResName);
+ Assert.assertNotNull(classResB);
+
+ // Load Java class as resource from imported contribution with JavaImport
+ URL classResB1 = contribB.getClassLoader().getResource("calculator/AddService.class");
+ Assert.assertNotNull(classResB1);
+
+ // Try to load resource not explicitly imported by contribution
+ URL classResA1 = contribA.getClassLoader().getResource("calculator/AddService.class");
+ Assert.assertNull(classResA1);
+
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java
new file mode 100644
index 0000000000..0ec5bfba39
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaExportProcessorTestCase.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.java.impl;
+
+import java.io.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.contribution.java.JavaExport;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl;
+import org.apache.tuscany.sca.monitor.impl.DefaultMonitorImpl;
+
+/**
+ * Test JavaExportProcessorTestCase
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaExportProcessorTestCase extends TestCase {
+
+ private static final String VALID_XML =
+ "<?xml version=\"1.0\" encoding=\"ASCII\"?>"
+ + "<export.java xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns=\"http://ns\" package=\"org.apache.tuscany.sca.contribution.java\"/>";
+
+ private static final String INVALID_XML =
+ "<?xml version=\"1.0\" encoding=\"ASCII\"?>"
+ + "<export.java xmlns=\"http://www.osoa.org/xmlns/sca/1.0\"/>";
+
+ private XMLInputFactory inputFactory;
+ private StAXArtifactProcessor<Object> staxProcessor;
+ private Monitor monitor;
+
+ @Override
+ protected void setUp() throws Exception {
+ ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ inputFactory = XMLInputFactory.newInstance();
+ // Create a monitor
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl();
+ if (monitorFactory != null) {
+ monitor = monitorFactory.createMonitor();
+ utilities.addUtility(monitorFactory);
+ }
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null);
+ }
+
+ /**
+ * Test loading a valid export element from a contribution metadata stream
+ * @throws Exception
+ */
+ public void testLoad() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML));
+ JavaExport javaExport = (JavaExport)staxProcessor.read(reader);
+ assertEquals("org.apache.tuscany.sca.contribution.java", javaExport.getPackage());
+ }
+
+ /**
+ * Test loading an INVALID export element from a contribution metadata stream
+ * @throws Exception
+ */
+ public void testLoadInvalid() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(INVALID_XML));
+ /*try {
+ staxProcessor.read(reader);
+ fail("readerException should have been thrown");
+ } catch (ContributionReadException e) {
+ assertTrue(true);
+ }*/
+ staxProcessor.read(reader);
+ Problem problem = ((DefaultMonitorImpl)monitor).getLastLoggedProblem();
+ assertNotNull(problem);
+ assertEquals("AttributePackageMissing", problem.getMessageId());
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java
new file mode 100644
index 0000000000..9e43b744cf
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/test/java/org/apache/tuscany/sca/contribution/java/impl/JavaImportProcessorTestCase.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.java.impl;
+
+import java.io.StringReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.contribution.java.JavaImport;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl;
+import org.apache.tuscany.sca.monitor.impl.DefaultMonitorImpl;
+
+/**
+ * Test JavaImportProcessorTestCase
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaImportProcessorTestCase extends TestCase {
+
+ private static final String VALID_XML =
+ "<?xml version=\"1.0\" encoding=\"ASCII\"?>"
+ + "<import.java xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns=\"http://ns\" package=\"org.apache.tuscany.sca.contribution.java\" location=\"sca://contributions/001\"/>";
+
+ private static final String INVALID_XML =
+ "<?xml version=\"1.0\" encoding=\"ASCII\"?>"
+ + "<import.java xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns=\"http://ns\" location=\"sca://contributions/001\"/>";
+
+ private XMLInputFactory inputFactory;
+ private StAXArtifactProcessor<Object> staxProcessor;
+ private Monitor monitor;
+
+ @Override
+ protected void setUp() throws Exception {
+ ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ inputFactory = XMLInputFactory.newInstance();
+ // Create a monitor
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl();
+ if (monitorFactory != null) {
+ monitor = monitorFactory.createMonitor();
+ utilities.addUtility(monitorFactory);
+ }
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null);
+ }
+
+ /**
+ * Test loading a valid import element from a contribution metadata stream
+ * @throws Exception
+ */
+ public void testLoad() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML));
+ JavaImport javaImport = (JavaImport)staxProcessor.read(reader);
+
+ assertEquals("org.apache.tuscany.sca.contribution.java", javaImport.getPackage());
+ assertEquals("sca://contributions/001", javaImport.getLocation());
+ }
+
+ /**
+ * Test loading a INVALID import element from a contribution metadata stream
+ * @throws Exception
+ */
+ public void testLoadInvalid() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(INVALID_XML));
+ /*try {
+ staxProcessor.read(reader);
+ fail("readerException should have been thrown");
+ } catch (ContributionReadException e) {
+ assertTrue(true);
+ }*/
+ staxProcessor.read(reader);
+ Problem problem = ((DefaultMonitorImpl)monitor).getLastLoggedProblem();
+ assertNotNull(problem);
+ assertEquals("AttributePackageMissing", problem.getMessageId());
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-java/src/test/resources/deployables/sample-calculator.jar b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/test/resources/deployables/sample-calculator.jar
new file mode 100644
index 0000000000..0ca3a1b781
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-java/src/test/resources/deployables/sample-calculator.jar
Binary files differ
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-xml/LICENSE b/sca-java-1.x/branches/sca-android/modules/contribution-xml/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-xml/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-xml/META-INF/README b/sca-java-1.x/branches/sca-android/modules/contribution-xml/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-xml/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-xml/NOTICE b/sca-java-1.x/branches/sca-android/modules/contribution-xml/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-xml/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-xml/pom.xml b/sca-java-1.x/branches/sca-android/modules/contribution-xml/pom.xml
new file mode 100644
index 0000000000..b1a06c2d11
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-xml/pom.xml
@@ -0,0 +1,70 @@
+<?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.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-contribution-xml</artifactId>
+ <name>Apache Tuscany SCA XML Contribution Model</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ <version>3.2.1</version>
+ <scope>runtime</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.contribution.xml</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.contribution.xml*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionGeneratedMetadataDocumentProcessor.java b/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionGeneratedMetadataDocumentProcessor.java
new file mode 100644
index 0000000000..a4cf1b3566
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionGeneratedMetadataDocumentProcessor.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.xml;
+
+import javax.xml.stream.XMLInputFactory;
+
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/**
+ * URLArtifactProcessor that handles sca-contribution-generated.xml files.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ContributionGeneratedMetadataDocumentProcessor extends ContributionMetadataDocumentProcessor {
+
+ public ContributionGeneratedMetadataDocumentProcessor(XMLInputFactory inputFactory,
+ StAXArtifactProcessor staxProcessor,
+ Monitor monitor) {
+ super(inputFactory, staxProcessor, monitor);
+ }
+
+ public ContributionGeneratedMetadataDocumentProcessor(ModelFactoryExtensionPoint modelFactories,
+ StAXArtifactProcessor staxProcessor,
+ Monitor monitor) {
+ super(modelFactories, staxProcessor, monitor);
+ }
+
+ @Override
+ public String getArtifactType() {
+ return "sca-contribution-generated.xml";
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java b/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.java
new file mode 100644
index 0000000000..e2e97239e0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataDocumentProcessor.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.contribution.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLConnection;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.contribution.ContributionMetadata;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ * URLArtifactProcessor that handles sca-contribution.xml files.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ContributionMetadataDocumentProcessor implements URLArtifactProcessor<ContributionMetadata>{
+ private final StAXArtifactProcessor staxProcessor;
+ private final XMLInputFactory inputFactory;
+ private final Monitor monitor;
+
+ public ContributionMetadataDocumentProcessor(XMLInputFactory inputFactory,
+ StAXArtifactProcessor staxProcessor,
+ Monitor monitor) {
+ this.inputFactory = inputFactory;
+ this.staxProcessor = staxProcessor;
+ this.monitor = monitor;
+ }
+
+ public ContributionMetadataDocumentProcessor(ModelFactoryExtensionPoint modelFactories,
+ StAXArtifactProcessor staxProcessor,
+ Monitor monitor) {
+ this.inputFactory = modelFactories.getFactory(XMLInputFactory.class);
+ this.staxProcessor = staxProcessor;
+ this.monitor = monitor;
+ }
+
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-xml-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
+ public String getArtifactType() {
+ return "sca-contribution.xml";
+ }
+
+ public Class<ContributionMetadata> getModelType() {
+ return ContributionMetadata.class;
+ }
+
+ public ContributionMetadata read(URL contributionURL, URI uri, URL url) throws ContributionReadException {
+ InputStream urlStream = null;
+ try {
+
+ // Create a stream reader
+ URLConnection connection = url.openConnection();
+ connection.setUseCaches(false);
+ urlStream = connection.getInputStream();
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(url.toString(), urlStream);
+ reader.nextTag();
+
+ // Read the contribution model
+ ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader);
+
+ return contribution;
+
+ } catch (XMLStreamException e) {
+ ContributionReadException ex = new ContributionReadException(e);
+ error("XMLStreamException", inputFactory, ex);
+ throw ex;
+ } catch (IOException e) {
+ ContributionReadException ex = new ContributionReadException(e);
+ error("IOException", inputFactory, ex);
+ throw ex;
+ } finally {
+ try {
+ if (urlStream != null) {
+ urlStream.close();
+ urlStream = null;
+ }
+ } catch (IOException ioe) {
+ //ignore
+ }
+ }
+ }
+
+ public void resolve(ContributionMetadata contribution, ModelResolver resolver) throws ContributionResolveException {
+ staxProcessor.resolve(contribution, resolver);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java b/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.java
new file mode 100644
index 0000000000..3f5aacb541
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessor.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.sca.contribution.xml;
+
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.ContributionMetadata;
+import org.apache.tuscany.sca.contribution.Export;
+import org.apache.tuscany.sca.contribution.Import;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ * Processor for contribution metadata
+ *
+ * @version $Rev$ $Date$
+ */
+public class ContributionMetadataProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<ContributionMetadata> {
+
+ private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0";
+
+ private static final QName CONTRIBUTION_QNAME = new QName(SCA10_NS, "contribution");
+ private static final QName DEPLOYABLE_QNAME = new QName(SCA10_NS, "deployable");
+
+ private final AssemblyFactory assemblyFactory;
+ private final ContributionFactory contributionFactory;
+
+ private final StAXArtifactProcessor<Object> extensionProcessor;
+ private Monitor monitor;
+
+ public ContributionMetadataProcessor(AssemblyFactory assemblyFactory,
+ ContributionFactory contributionFactory,
+ StAXArtifactProcessor<Object> extensionProcessor,
+ Monitor monitor) {
+ this.assemblyFactory = assemblyFactory;
+ this.contributionFactory = contributionFactory;
+ this.extensionProcessor = extensionProcessor;
+ this.monitor = monitor;
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-xml-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ public ContributionMetadataProcessor(ModelFactoryExtensionPoint modelFactories,
+ StAXArtifactProcessor<Object> extensionProcessor,
+ Monitor monitor) {
+ this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ this.contributionFactory = modelFactories.getFactory(ContributionFactory.class);
+ this.extensionProcessor = extensionProcessor;
+ this.monitor = monitor;
+ }
+
+
+ public QName getArtifactType() {
+ return CONTRIBUTION_QNAME;
+ }
+
+ public Class<ContributionMetadata> getModelType() {
+ return ContributionMetadata.class;
+ }
+
+ public ContributionMetadata read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ ContributionMetadata contribution = null;
+ QName name = null;
+
+ while (reader.hasNext()) {
+ int event = reader.getEventType();
+ switch (event) {
+ case START_ELEMENT:
+ name = reader.getName();
+
+ if (CONTRIBUTION_QNAME.equals(name)) {
+
+ // Read <contribution>
+ contribution = this.contributionFactory.createContributionMetadata();
+ contribution.setUnresolved(true);
+
+ } else if (DEPLOYABLE_QNAME.equals(name)) {
+
+ // Read <deployable>
+ QName compositeName = getQName(reader, "composite");
+ if (compositeName == null) {
+ error("AttributeCompositeMissing", reader);
+ //throw new ContributionReadException("Attribute 'composite' is missing");
+ } else {
+ if (contribution != null) {
+ Composite composite = assemblyFactory.createComposite();
+ composite.setName(compositeName);
+ composite.setUnresolved(true);
+ contribution.getDeployables().add(composite);
+ }
+ }
+ } else {
+
+ // Read an extension element
+ Object extension = extensionProcessor.read(reader);
+ if (extension != null && contribution != null) {
+ if (extension instanceof Import) {
+ contribution.getImports().add((Import)extension);
+ } else if (extension instanceof Export) {
+ contribution.getExports().add((Export)extension);
+ }
+ }
+ }
+ break;
+
+ case XMLStreamConstants.END_ELEMENT:
+ if (CONTRIBUTION_QNAME.equals(reader.getName())) {
+ return contribution;
+ }
+ break;
+ }
+
+ //Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
+ }
+
+ return contribution;
+ }
+
+ public void write(ContributionMetadata contribution, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+
+ // Write <contribution>
+ writeStartDocument(writer, CONTRIBUTION_QNAME.getNamespaceURI(), CONTRIBUTION_QNAME.getLocalPart());
+
+ // Write <import>
+ for (Import imp: contribution.getImports()) {
+ extensionProcessor.write(imp, writer);
+ }
+
+ // Write <export>
+ for (Export export: contribution.getExports()) {
+ extensionProcessor.write(export, writer);
+ }
+
+ // Write <deployable>
+ for (Composite deployable: contribution.getDeployables()) {
+ writeStart(writer, DEPLOYABLE_QNAME.getNamespaceURI(), DEPLOYABLE_QNAME.getLocalPart(),
+ new XAttr("composite", deployable.getName()));
+ writeEnd(writer);
+ }
+
+ writeEndDocument(writer);
+ }
+
+ public void resolve(ContributionMetadata contribution, ModelResolver resolver) throws ContributionResolveException {
+
+ // Resolve imports and exports
+ for (Export export: contribution.getExports()) {
+ extensionProcessor.resolve(export, resolver);
+ }
+ for (Import import_: contribution.getImports()) {
+ extensionProcessor.resolve(import_, resolver);
+ }
+
+ // Resolve deployable composites
+ List<Composite> deployables = contribution.getDeployables();
+ for (int i = 0, n = deployables.size(); i < n; i++) {
+ Composite deployable = deployables.get(i);
+ Composite resolved = (Composite)resolver.resolveModel(Composite.class, deployable);
+ if (resolved != deployable) {
+ deployables.set(i, resolved);
+ }
+ }
+
+ contribution.setUnresolved(false);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionModelResolver.java b/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionModelResolver.java
new file mode 100644
index 0000000000..f226dbbee3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/java/org/apache/tuscany/sca/contribution/xml/ContributionModelResolver.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.xml;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+/**
+ * A Model Resolver for Contribution models.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ContributionModelResolver implements ModelResolver {
+
+ private Map<String, Contribution> map = new HashMap<String, Contribution>();
+
+ public ContributionModelResolver(Contribution contribution, ModelFactoryExtensionPoint modelFactories) {
+ }
+
+ public void addModel(Object resolved) {
+ Contribution contribution = (Contribution)resolved;
+ map.put(contribution.getURI(), contribution);
+ }
+
+ public Object removeModel(Object resolved) {
+ return map.remove(((Contribution)resolved).getURI());
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+
+ // Lookup a contribution for the given URI
+ String uri = ((Contribution)unresolved).getURI();
+ if (uri != null) {
+ Contribution resolved = (Contribution) map.get(uri);
+ if (resolved != null) {
+ return modelClass.cast(resolved);
+ }
+ return unresolved;
+ } else {
+
+ // If no URI was specified, just return the first contribution
+ if (!map.isEmpty()) {
+ Contribution resolved = map.values().iterator().next();
+ return modelClass.cast(resolved);
+ } else {
+ return unresolved;
+ }
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
new file mode 100644
index 0000000000..b73c380370
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for the artifact processor extension
+org.apache.tuscany.sca.contribution.xml.ContributionMetadataProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#contribution,model=org.apache.tuscany.sca.contribution.ContributionMetadata
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor b/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor
new file mode 100644
index 0000000000..23adab56b9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor
@@ -0,0 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for the artifact processor extension
+org.apache.tuscany.sca.contribution.xml.ContributionMetadataDocumentProcessor;type=sca-contribution.xml,model=org.apache.tuscany.sca.contribution.ContributionMetadata
+org.apache.tuscany.sca.contribution.xml.ContributionGeneratedMetadataDocumentProcessor;type=sca-contribution-generated.xml
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver
new file mode 100644
index 0000000000..68030bf6e6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.contribution.xml.ContributionModelResolver;model=org.apache.tuscany.sca.contribution.Contribution
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties b/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties
new file mode 100644
index 0000000000..3e1a0187fe
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/main/resources/contribution-xml-validation-messages.properties
@@ -0,0 +1,23 @@
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+XMLStreamException = XMLStreamException occured due to:
+IOException = IOException occured due to:
+AttributeCompositeMissing = Attribute 'composite' is missing \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java b/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java
new file mode 100644
index 0000000000..8f69f15cd1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution-xml/src/test/java/org/apache/tuscany/sca/contribution/xml/ContributionMetadataProcessorTestCase.java
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.xml;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.contribution.ContributionMetadata;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl;
+import org.apache.tuscany.sca.monitor.impl.DefaultMonitorImpl;
+
+/**
+ * Test the contribution metadata processor.
+ *
+ * @version $Rev$ $Date$
+ */
+
+public class ContributionMetadataProcessorTestCase extends TestCase {
+
+ private static final String VALID_XML =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ + "<contribution xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns=\"http://ns\">"
+ + "<deployable composite=\"ns:Composite1\"/>"
+ + "<deployable composite=\"ns:Composite2\"/>"
+ + "</contribution>";
+
+ private static final String INVALID_XML =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ + "<contribution xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns=\"http://ns\">"
+ + "<deployable composite=\"ns:Composite1\"/>"
+ + "<deployable/>"
+ + "</contribution>";
+
+ private XMLInputFactory inputFactory;
+ private XMLOutputFactory outputFactory;
+ private StAXArtifactProcessor<Object> staxProcessor;
+ private Monitor monitor;
+
+ @Override
+ protected void setUp() throws Exception {
+ ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+
+ inputFactory = XMLInputFactory.newInstance();
+ outputFactory = XMLOutputFactory.newInstance();
+
+ // Create a monitor
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl();
+ if (monitorFactory != null) {
+ monitor = monitorFactory.createMonitor();
+ utilities.addUtility(monitorFactory);
+ }
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null);
+ }
+
+ public void testRead() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML));
+ ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader);
+ assertNotNull(contribution);
+ assertEquals(2, contribution.getDeployables().size());
+ }
+
+ public void testReadInvalid() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(INVALID_XML));
+ /*try {
+ staxProcessor.read(reader);
+ fail("InvalidException should have been thrown");
+ } catch (ContributionReadException e) {
+ assertTrue(true);
+ }*/
+ staxProcessor.read(reader);
+ Problem problem = ((DefaultMonitorImpl)monitor).getLastLoggedProblem();
+ assertNotNull(problem);
+ assertEquals("AttributeCompositeMissing", problem.getMessageId());
+ }
+
+ public void testWrite() throws Exception {
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML));
+ ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader);
+
+ validateContribution(contribution);
+
+ //write the contribution metadata contents
+ StringWriter stringWriter = new StringWriter();
+ XMLStreamWriter writer = outputFactory.createXMLStreamWriter(stringWriter);
+ staxProcessor.write(contribution, writer);
+ stringWriter.close();
+
+ reader = inputFactory.createXMLStreamReader(new StringReader(stringWriter.toString()));
+ contribution = (ContributionMetadata)staxProcessor.read(reader);
+
+ validateContribution(contribution);
+ }
+
+ private void validateContribution(ContributionMetadata contribution) {
+ QName deployable;
+
+ assertNotNull(contribution);
+ assertEquals(2, contribution.getDeployables().size());
+ deployable = new QName("http://ns", "Composite1");
+ assertEquals(deployable, contribution.getDeployables().get(0).getName());
+ deployable = new QName("http://ns", "Composite2");
+ assertEquals(deployable, contribution.getDeployables().get(1).getName());
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/LICENSE b/sca-java-1.x/branches/sca-android/modules/contribution/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/META-INF/README b/sca-java-1.x/branches/sca-android/modules/contribution/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/NOTICE b/sca-java-1.x/branches/sca-android/modules/contribution/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/pom.xml b/sca-java-1.x/branches/sca-android/modules/contribution/pom.xml
new file mode 100644
index 0000000000..5a1c4b55b5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/pom.xml
@@ -0,0 +1,69 @@
+<?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.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-contribution</artifactId>
+ <name>Apache Tuscany SCA Contribution Model</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-extensibility</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.xml.stream</groupId>
+ <artifactId>stax-api</artifactId>
+ <version>1.0-2</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.contribution</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.contribution*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.java
new file mode 100644
index 0000000000..7400501d85
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution;
+
+import org.apache.tuscany.sca.assembly.Base;
+
+
+/**
+ * Represents an artifact in an SCA contribution.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Artifact extends Base {
+
+ /**
+ * Returns the URI that unique identifies the artifact inside the contribution.
+ *
+ * @return The artifact URI
+ */
+ String getURI();
+
+ /**
+ * Sets the URI that uniquely identifies the artifact inside the contribution.
+ *
+ * @param uri The artifact URI
+ */
+ void setURI(String uri);
+
+ /**
+ * Returns the location of the artifact.
+ *
+ * @return The artifact location
+ */
+ String getLocation();
+
+ /**
+ * Set the location of the artifact.
+ *
+ * @param location The artifact location
+ */
+ void setLocation(String location);
+
+
+ /**
+ * Returns the in-memory model representing the artifact.
+ *
+ * @return The model object
+ */
+ Object getModel();
+
+ /**
+ * Sets the in-memory model representing the artifact.
+ *
+ * @param model The model object
+ */
+ void setModel(Object model);
+
+ /**
+ * Returns the contents of the artifact cached here.
+ * @return the contents of the artifact
+ */
+ byte[] getContents();
+
+ /**
+ * Sets the contents of the artifact.
+ * @param contents the contents of the artifact
+ */
+ void setContents(byte[] contents);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Constants.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Constants.java
new file mode 100644
index 0000000000..4cf20125b9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Constants.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution;
+
+/**
+ * Constants used in SCA contribution.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Constants {
+ String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0";
+ String SCA10_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.0";
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContentType.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContentType.java
new file mode 100644
index 0000000000..81b0b08b9d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContentType.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution;
+
+/**
+ * Constants for the main supported contribution package type.
+ *
+ * @version $Rev$ $Date$
+ */
+@Deprecated
+public interface ContentType {
+
+ /**
+ * Java compressed contribution package
+ */
+ String JAR = "application/x-compressed";
+
+ /**
+ * Filesystem folder contribution package
+ */
+ String FOLDER = "application/vnd.tuscany.folder";
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java
new file mode 100644
index 0000000000..743c2356d7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+/**
+ * The representation of an SCA contribution.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Contribution extends Artifact {
+
+ /**
+ * Default location of contribution metadata in an SCA contribution.
+ */
+ String SCA_CONTRIBUTION_META = "META-INF/sca-contribution.xml";
+
+ /**
+ * Default location of a generated contribution metadata in an SCA contribution.
+ */
+ String SCA_CONTRIBUTION_GENERATED_META = "META-INF/sca-contribution-generated.xml";
+
+ /**
+ * Default location of deployable composites in an SCA contribution.
+ */
+ String SCA_CONTRIBUTION_DEPLOYABLES = "META-INF/sca-deployables/";
+
+
+ /**
+ * Returns a list of exports based on the contribution metadata.
+ *
+ * @return The list of exports in this contribution
+ */
+ List<Export> getExports();
+
+ /**
+ * Returns a list of imports based on the contribution metadata.
+ *
+ * @return The list of imports in this contribution
+ */
+ List<Import> getImports();
+
+ /**
+ * Returns the list of deployable composites in the contribution.
+ *
+ * @return The list of deployable composites
+ */
+ List<Composite> getDeployables();
+
+ /**
+ * Returns the list of artifacts in the contribution.
+ *
+ * @return The list of artifacts in the contribution
+ */
+ List<Artifact> getArtifacts();
+
+ /**
+ * Returns the model resolver for the models representing the artifacts
+ * visible in the scope of this contribution.
+ *
+ * @return The model resolver
+ */
+ ModelResolver getModelResolver();
+
+ /**
+ * Sets the model resolver for the models representing the artifacts
+ * visible in the scope of this contribution.
+ *
+ * @param modelResolver The model resolver
+ */
+ void setModelResolver(ModelResolver modelResolver);
+
+ /**
+ * Returns the ClassLoader used to load classes and resources from
+ * this contribution
+ *
+ * FIXME Remove this, the base contribution model should not depend
+ * on Java ClassLoaders.
+ *
+ * @return The contribution ClassLoader
+ */
+ ClassLoader getClassLoader();
+
+ /**
+ * Sets the ClassLoader used to load classes and resources from
+ * this contribution
+ *
+ * FIXME Remove this, the base contribution model should not depend
+ * on Java ClassLoaders.
+ *
+ * @param classLoader the contribution class loader
+ */
+ void setClassLoader(ClassLoader classLoader);
+
+} \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionFactory.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionFactory.java
new file mode 100644
index 0000000000..67c9a05a0b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionFactory.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution;
+
+
+/**
+ * A factory for the contribution model.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ContributionFactory {
+
+ /**
+ * Create a contribution model object
+ *
+ * @return The new contribution model object
+ */
+ Contribution createContribution();
+
+ /**
+ * Create a contribution metadata model object
+ *
+ * @return The new contribution metadata model object
+ */
+ ContributionMetadata createContributionMetadata();
+
+ /**
+ * Create a deployedArtifact model object
+ *
+ * @return The new deployedArtifact model object
+ */
+ @Deprecated
+ DeployedArtifact createDeployedArtifact();
+
+ /**
+ * Create an artifact model object
+ *
+ * @return The new artifact model object
+ */
+ Artifact createArtifact();
+
+ /**
+ * Create a default import model object.
+ *
+ * @return the new default import model object
+ */
+ DefaultImport createDefaultImport();
+
+ /**
+ * Create a default export model object.
+ *
+ * @return the new default export model object
+ */
+ DefaultExport createDefaultExport();
+
+} \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionMetadata.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionMetadata.java
new file mode 100644
index 0000000000..4043fb9eda
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionMetadata.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Base;
+import org.apache.tuscany.sca.assembly.Composite;
+
+/**
+ * The representation of SCA contribution metadata.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ContributionMetadata extends Base {
+
+ /**
+ * Returns a list of exports based on the contribution metadata.
+ *
+ * @return The list of exports
+ */
+ List<Export> getExports();
+
+ /**
+ * Returns a list of imports based on the contribution metadata.
+ *
+ * @return The list of imports
+ */
+ List<Import> getImports();
+
+ /**
+ * Returns the list of deployable based on the contribution metadata.
+ *
+ * @return The list of deployable composites
+ */
+ List<Composite> getDeployables();
+
+} \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultContributionFactory.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultContributionFactory.java
new file mode 100644
index 0000000000..98954c288a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultContributionFactory.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution;
+
+import org.apache.tuscany.sca.contribution.impl.ContributionFactoryImpl;
+
+
+/**
+ * Default implementation of a contribution model factory.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultContributionFactory extends ContributionFactoryImpl {
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultExport.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultExport.java
new file mode 100644
index 0000000000..b2eddb8336
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultExport.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution;
+
+
+/**
+ * The representation of an export that exports all artifacts in
+ * a contribution.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface DefaultExport extends Export {
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultImport.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultImport.java
new file mode 100644
index 0000000000..20798dcd17
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultImport.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution;
+
+
+/**
+ * The representation of a default import that imports artifacts from
+ * all contributions.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface DefaultImport extends Import {
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultModelFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultModelFactoryExtensionPoint.java
new file mode 100644
index 0000000000..b69c58a0ff
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DefaultModelFactoryExtensionPoint.java
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution;
+
+import java.lang.reflect.Constructor;
+import java.util.HashMap;
+
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+
+
+/**
+ * Default implementation of a model factory extension point.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultModelFactoryExtensionPoint implements ModelFactoryExtensionPoint {
+
+ private HashMap<Class<?>, Object> factories = new HashMap<Class<?>, Object>();
+
+ /**
+ * Constructs a new DefaultModelFactoryExtensionPoint.
+ */
+ public DefaultModelFactoryExtensionPoint() {
+ }
+
+ /**
+ * Add a model factory extension.
+ *
+ * @param factory The factory to add
+ */
+ public void addFactory(Object factory) {
+ Class<?>[] interfaces = factory.getClass().getInterfaces();
+ if (interfaces.length == 0) {
+ Class<?> sc = factory.getClass().getSuperclass();
+ if (sc != Object.class) {
+ factories.put(sc, factory);
+ }
+ } else {
+ for (int i = 0; i<interfaces.length; i++) {
+ factories.put(interfaces[i], factory);
+ }
+ }
+ }
+
+ /**
+ * Remove a model factory.
+ *
+ * @param factory The factory to remove
+ */
+ public void removeFactory(Object factory) {
+ Class<?>[] interfaces = factory.getClass().getInterfaces();
+ if (interfaces.length == 0) {
+ Class<?> sc = factory.getClass().getSuperclass();
+ if (sc != Object.class) {
+ factories.remove(sc);
+ }
+ } else {
+ for (int i = 0; i<interfaces.length; i++) {
+ factories.remove(interfaces[i]);
+ }
+ }
+ }
+
+ /**
+ * Get a factory implementing the given interface.
+ * @param factoryInterface The lookup key (factory interface)
+ * @return The factory
+ */
+ public <T> T getFactory(Class<T> factoryInterface) {
+ Object factory = factories.get(factoryInterface);
+ if (factory == null) {
+
+ if (factoryInterface.isInterface()) {
+
+ // Dynamically load a factory class declared under META-INF/services
+ try {
+ Class<?> factoryClass = ServiceDiscovery.getInstance().loadFirstServiceClass(factoryInterface);
+ if (factoryClass != null) {
+
+ try {
+ // Default empty constructor
+ Constructor<?> constructor = factoryClass.getConstructor();
+ factory = constructor.newInstance();
+ } catch (NoSuchMethodException e) {
+
+ // Constructor taking the model factory extension point
+ Constructor<?> constructor = factoryClass.getConstructor(ModelFactoryExtensionPoint.class);
+ factory = constructor.newInstance(this);
+ }
+
+ // Cache the loaded factory
+ addFactory(factory);
+ }
+ } catch (Exception e) {
+ throw new IllegalArgumentException(e);
+ }
+ } else {
+
+ // Call the newInstance static method on the factory abstract class
+ try {
+ factory = ServiceDiscovery.getInstance().newFactoryClassInstance(factoryInterface);
+ } catch (Exception e) {
+ throw new IllegalArgumentException(e);
+ }
+
+ // Cache the factory
+ addFactory(factory);
+ }
+ }
+ return factoryInterface.cast(factory);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DeployedArtifact.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DeployedArtifact.java
new file mode 100644
index 0000000000..ffe190132c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/DeployedArtifact.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution;
+
+/**
+ * Representation of a deployed artifact
+ *
+ * @version $Rev$ $Date$
+ */
+@Deprecated
+public interface DeployedArtifact extends Artifact {
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Export.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Export.java
new file mode 100644
index 0000000000..bfa16b1ce3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Export.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution;
+
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+/**
+ * The representation of an export.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Export {
+
+ /**
+ * Returns the model resolver for the models representing artifacts
+ * made available by this export.
+ *
+ * @return The model resolver
+ */
+ ModelResolver getModelResolver();
+
+ /**
+ * Sets the model resolver for the models representing artifacts
+ * made available by this export.
+ *
+ * @param modelResolver
+ */
+ void setModelResolver(ModelResolver modelResolver);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Import.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Import.java
new file mode 100644
index 0000000000..35076f55a7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Import.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution;
+
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+
+/**
+ * The representation of an import.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Import {
+
+ /**
+ * Returns the model resolver for the models representing artifacts
+ * made available by this import.
+ *
+ * @return The model resolver
+ */
+ ModelResolver getModelResolver();
+
+ /**
+ * Sets the model resolver for the models representing artifacts
+ * made available by this import.
+ *
+ * @param modelResolver The model resolver
+ */
+ void setModelResolver(ModelResolver modelResolver);
+
+ /**
+ * Verify that a specific export actually exports what is being imported.
+ *
+ * @param export The Exported being verified
+ * @return true/false
+ */
+ boolean match(Export export);
+
+} \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ModelFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ModelFactoryExtensionPoint.java
new file mode 100644
index 0000000000..0ada4ebec3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ModelFactoryExtensionPoint.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution;
+
+/**
+ * An extension point for model factories. Model factories are provided to
+ * abstract the classes that represent artifacts in the assembly model away
+ * from their creation mechanism. When the runtime needs to extend the model
+ * as it reads in contributed artifacts it looks up the factory for the
+ * artifact required in this registry
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ModelFactoryExtensionPoint {
+
+ /**
+ * Add a model factory extension.
+ *
+ * @param factory The factory to add
+ */
+ void addFactory(Object factory);
+
+ /**
+ * Remove a model factory extension.
+ *
+ * @param factory The factory to remove
+ */
+ void removeFactory(Object factory);
+
+ /**
+ * Get a factory implementing the given interface.
+ * @param factoryInterface the lookup key (factory interface)
+ * @return The factory
+ */
+ <T> T getFactory(Class<T> factoryInterface);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/PackageType.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/PackageType.java
new file mode 100644
index 0000000000..c0dd5431d7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/PackageType.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution;
+
+/**
+ * Constants for the main supported contribution package types.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface PackageType {
+
+ /**
+ * Java compressed contribution package
+ */
+ String JAR = "application/x-compressed";
+
+ /**
+ * Filesystem folder contribution package
+ */
+ String FOLDER = "application/vnd.tuscany.folder";
+
+
+ String BUNDLE = "application/osgi.bundle";
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.java
new file mode 100644
index 0000000000..881987f622
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.impl;
+
+import org.apache.tuscany.sca.contribution.Artifact;
+
+
+/**
+ * The model representing an artifact in a contribution.
+ *
+ * @version $Rev$ $Date$
+ */
+class ArtifactImpl implements Artifact {
+ private String uri;
+ private String location;
+ private Object model;
+ private boolean unresolved;
+ private byte[] contents;
+
+ ArtifactImpl() {
+ }
+
+ public String getLocation() {
+ return location;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ public String getURI() {
+ return uri;
+ }
+
+ public void setURI(String uri) {
+ this.uri = uri;
+ }
+
+ public Object getModel() {
+ return model;
+ }
+
+ public void setModel(Object model) {
+ this.model = model;
+ }
+
+ public byte[] getContents() {
+ return contents;
+ }
+
+ public void setContents(byte[] contents) {
+ this.contents = contents;
+ }
+
+ public boolean isUnresolved() {
+ return unresolved;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ this.unresolved = unresolved;
+ }
+
+ @Override
+ public int hashCode() {
+ return uri.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ } else {
+ if (obj instanceof Artifact) {
+ return uri.equals(((Artifact)obj).getURI());
+ } else {
+ return false;
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "Artifact:" + uri + "\n" +
+ "at: " + location;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionFactoryImpl.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionFactoryImpl.java
new file mode 100644
index 0000000000..c678c2eaef
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionFactoryImpl.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.impl;
+
+import org.apache.tuscany.sca.contribution.Artifact;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.ContributionMetadata;
+import org.apache.tuscany.sca.contribution.DefaultExport;
+import org.apache.tuscany.sca.contribution.DefaultImport;
+import org.apache.tuscany.sca.contribution.DeployedArtifact;
+
+
+/**
+ * Default implementation of a contribution model factory.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ContributionFactoryImpl implements ContributionFactory {
+
+ protected ContributionFactoryImpl() {
+ }
+
+ public Contribution createContribution() {
+ return new ContributionImpl();
+ }
+
+ public ContributionMetadata createContributionMetadata() {
+ return new ContributionMetadataImpl();
+ }
+
+ public Artifact createArtifact() {
+ return new ArtifactImpl();
+ }
+
+ public DefaultExport createDefaultExport() {
+ return new DefaultExportImpl();
+ }
+
+ public DefaultImport createDefaultImport() {
+ return new DefaultImportImpl();
+ }
+
+ @Deprecated
+ public DeployedArtifact createDeployedArtifact() {
+ class DeployedArtifactImpl extends ArtifactImpl implements DeployedArtifact {
+ }
+ return new DeployedArtifactImpl();
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java
new file mode 100644
index 0000000000..fc9ae607e7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.Artifact;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.Export;
+import org.apache.tuscany.sca.contribution.Import;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+/**
+ * The representation of a deployed contribution
+ *
+ * @version $Rev$ $Date$
+ */
+class ContributionImpl implements Contribution {
+ private String uri;
+ private String location;
+ private Object model;
+ private byte[] contents;
+ private boolean unresolved;
+ private List<Export> exports = new ArrayList<Export>();
+ private List<Import> imports = new ArrayList<Import>();
+ private List<Composite> deployables = new ArrayList<Composite>();
+ private List<Artifact> artifacts = new ArrayList<Artifact>();
+ private ModelResolver modelResolver;
+
+ // FIXME remove this dependency on Java ClassLoaders
+ private ClassLoader classLoader;
+
+ ContributionImpl() {
+ }
+
+ public String getLocation() {
+ return this.location;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ //FIXME Remove dependency on Java ClassLoaders
+ public ClassLoader getClassLoader() {
+ return classLoader;
+ }
+
+ //FIXME Remove dependency on Java ClassLoaders
+ public void setClassLoader(ClassLoader classLoader) {
+ this.classLoader = classLoader;
+ }
+
+
+ public String getURI() {
+ return this.uri;
+ }
+
+ public void setURI(String uri) {
+ this.uri = uri;
+ }
+
+ public Object getModel() {
+ return model;
+ }
+
+ public void setModel(Object model) {
+ this.model = model;
+ }
+
+ public byte[] getContents() {
+ return contents;
+ }
+
+ public void setContents(byte[] contents) {
+ this.contents = contents;
+ }
+
+ public boolean isUnresolved() {
+ return unresolved;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ this.unresolved = unresolved;
+ }
+
+ public ModelResolver getModelResolver() {
+ return modelResolver;
+ }
+
+ public void setModelResolver(ModelResolver modelResolver) {
+ this.modelResolver = modelResolver;
+ }
+
+ public List<Export> getExports() {
+ return exports;
+ }
+
+ public List<Import> getImports() {
+ return imports;
+ }
+
+ public List<Composite> getDeployables() {
+ return deployables;
+ }
+
+ public List<Artifact> getArtifacts() {
+ return artifacts;
+ }
+
+ @Override
+ public int hashCode() {
+ return uri.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ } else {
+ if (obj instanceof Artifact) {
+ return uri.equals(((Artifact)obj).getURI());
+ } else {
+ return false;
+ }
+ }
+ }
+
+ @Override
+ public String toString() {
+ return "Contribution : " + uri + " \n" +
+ "from: " + location;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionMetadataImpl.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionMetadataImpl.java
new file mode 100644
index 0000000000..75b12b1260
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionMetadataImpl.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.ContributionMetadata;
+import org.apache.tuscany.sca.contribution.Export;
+import org.apache.tuscany.sca.contribution.Import;
+
+/**
+ * The representation of a deployed contribution
+ *
+ * @version $Rev$ $Date$
+ */
+class ContributionMetadataImpl implements ContributionMetadata {
+ private boolean unresolved;
+ private List<Export> exports = new ArrayList<Export>();
+ private List<Import> imports = new ArrayList<Import>();
+ private List<Composite> deployables = new ArrayList<Composite>();
+
+ ContributionMetadataImpl() {
+ }
+
+ public boolean isUnresolved() {
+ return unresolved;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ this.unresolved = unresolved;
+ }
+
+ public List<Export> getExports() {
+ return exports;
+ }
+
+ public List<Import> getImports() {
+ return imports;
+ }
+
+ public List<Composite> getDeployables() {
+ return deployables;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultExportImpl.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultExportImpl.java
new file mode 100644
index 0000000000..e67395337a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultExportImpl.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.impl;
+
+import org.apache.tuscany.sca.contribution.DefaultExport;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+/**
+ * The representation of an export for the contribution
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultExportImpl implements DefaultExport {
+ private ModelResolver modelResolver;
+
+ protected DefaultExportImpl() {
+ super();
+ }
+
+ public ModelResolver getModelResolver() {
+ return modelResolver;
+ }
+
+ public void setModelResolver(ModelResolver modelResolver) {
+ this.modelResolver = modelResolver;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultImportImpl.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultImportImpl.java
new file mode 100644
index 0000000000..17c09f2cbc
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultImportImpl.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.impl;
+
+import org.apache.tuscany.sca.contribution.DefaultExport;
+import org.apache.tuscany.sca.contribution.DefaultImport;
+import org.apache.tuscany.sca.contribution.Export;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+/**
+ * The representation of an import for the contribution
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultImportImpl implements DefaultImport {
+ private ModelResolver modelResolver;
+
+ protected DefaultImportImpl() {
+ super();
+ }
+
+ public ModelResolver getModelResolver() {
+ return modelResolver;
+ }
+
+ public void setModelResolver(ModelResolver modelResolver) {
+ this.modelResolver = modelResolver;
+ }
+
+
+ public boolean match(Export export) {
+ if (export instanceof DefaultExport) {
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java
new file mode 100644
index 0000000000..b5f536c431
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessor.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.processor;
+
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+
+/**
+ * Base interface for artifact processors.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ArtifactProcessor<M> {
+
+ /**
+ * Resolve references from this model to other models. For example references
+ * from a composite to another one, or references from a composite to a WSDL
+ * model.
+ *
+ * @param model The model to resolve
+ * @param resolver The resolver to use to resolve referenced models
+ */
+ void resolve(M model, ModelResolver resolver) throws ContributionResolveException;
+
+ /**
+ * Returns the type of model handled by this artifact processor.
+ *
+ * @return The type of model handled by this artifact processor
+ */
+ Class<M> getModelType();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessorExtensionPoint.java
new file mode 100644
index 0000000000..029df61f0f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessorExtensionPoint.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.processor;
+
+/**
+ * An extension point for artifact processors.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ArtifactProcessorExtensionPoint<P extends ArtifactProcessor> {
+
+ /**
+ * Add an artifact processor.
+ *
+ * @param artifactProcessor The artifact processor to add
+ */
+ void addArtifactProcessor(P artifactProcessor);
+
+ /**
+ * Remove an artifact processor.
+ *
+ * @param artifactProcessor The artifact processor to remove
+ */
+ void removeArtifactProcessor(P artifactProcessor);
+
+ /**
+ * Returns the processor associated with the given artifact type.
+ *
+ * @param artifactType An artifact type
+ * @return The processor associated with the given artifact type
+ */
+ P getProcessor(Object artifactType);
+
+ /**
+ * Returns the processor associated with the given model type.
+ *
+ * @param modelType A model type
+ * @return The processor associated with the given model type
+ */
+ P getProcessor(Class<?> modelType);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java
new file mode 100644
index 0000000000..f23797a831
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java
@@ -0,0 +1,539 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.processor;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+
+/**
+ * A base class with utility methods for the other artifact processors in this module.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class BaseStAXArtifactProcessor {
+
+ /**
+ * Returns a QName from a string.
+ * @param reader
+ * @param value
+ * @return
+ */
+ protected QName getQNameValue(XMLStreamReader reader, String value) {
+ if (value != null) {
+ int index = value.indexOf(':');
+ String prefix = index == -1 ? "" : value.substring(0, index);
+ String localName = index == -1 ? value : value.substring(index + 1);
+ String ns = reader.getNamespaceContext().getNamespaceURI(prefix);
+ if (ns == null) {
+ ns = "";
+ }
+ return new QName(ns, localName, prefix);
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Returns the boolean value of an attribute.
+ * @param reader
+ * @param name
+ * @return
+ */
+ protected boolean getBoolean(XMLStreamReader reader, String name) {
+ String value = reader.getAttributeValue(null, name);
+ if (value == null) {
+ return false;
+ }
+ return Boolean.valueOf(value);
+ }
+
+ /**
+ * Returns the QName value of an attribute.
+ * @param reader
+ * @param name
+ * @return
+ */
+ protected QName getQName(XMLStreamReader reader, String name) {
+ String qname = reader.getAttributeValue(null, name);
+ return getQNameValue(reader, qname);
+ }
+
+ /**
+ * Returns the value of an attribute as a list of QNames.
+ * @param reader
+ * @param name
+ * @return
+ */
+ protected List<QName> getQNames(XMLStreamReader reader, String name) {
+ String value = reader.getAttributeValue(null, name);
+ if (value != null) {
+ List<QName> qnames = new ArrayList<QName>();
+ for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
+ qnames.add(getQName(reader, tokens.nextToken()));
+ }
+ return qnames;
+ } else {
+ return Collections.emptyList();
+ }
+ }
+
+ /**
+ * Returns the string value of an attribute.
+ * @param reader
+ * @param name
+ * @return
+ */
+ protected String getString(XMLStreamReader reader, String name) {
+ return reader.getAttributeValue(null, name);
+ }
+
+ /**
+ * Test if an attribute is explicitly set
+ * @param reader
+ * @param name
+ * @return
+ */
+ protected boolean isSet(XMLStreamReader reader, String name) {
+ return reader.getAttributeValue(null, name) != null;
+ }
+
+ /**
+ * Returns the value of xsi:type attribute
+ * @param reader The XML stream reader
+ * @return The QName of the type, if the attribute is not present, null is
+ * returned.
+ */
+ protected QName getXSIType(XMLStreamReader reader) {
+ String qname = reader.getAttributeValue(XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI, "type");
+ return getQNameValue(reader, qname);
+ }
+
+ /**
+ * Parse the next child element.
+ * @param reader
+ * @return
+ * @throws XMLStreamException
+ */
+ protected boolean nextChildElement(XMLStreamReader reader) throws XMLStreamException {
+ while (reader.hasNext()) {
+ int event = reader.next();
+ if (event == END_ELEMENT) {
+ return false;
+ }
+ if (event == START_ELEMENT) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Advance the stream to the next END_ELEMENT event skipping any nested
+ * content.
+ * @param reader the reader to advance
+ * @throws XMLStreamException if there was a problem reading the stream
+ */
+ protected void skipToEndElement(XMLStreamReader reader) throws XMLStreamException {
+ int depth = 0;
+ while (reader.hasNext()) {
+ int event = reader.next();
+ if (event == XMLStreamConstants.START_ELEMENT) {
+ depth++;
+ } else if (event == XMLStreamConstants.END_ELEMENT) {
+ if (depth == 0) {
+ return;
+ }
+ depth--;
+ }
+ }
+ }
+
+ /**
+ *
+ * @param writer
+ * @param uri
+ * @throws XMLStreamException
+ */
+ private String writeElementPrefix(XMLStreamWriter writer, String uri) throws XMLStreamException {
+ if (uri == null) {
+ return null;
+ }
+ String prefix = writer.getPrefix(uri);
+ if (prefix != null) {
+ return null;
+ } else {
+
+ // Find an available prefix and bind it to the given URI
+ NamespaceContext nsc = writer.getNamespaceContext();
+ for (int i=1; ; i++) {
+ prefix = "ns" + i;
+ if (nsc.getNamespaceURI(prefix) == null) {
+ break;
+ }
+ }
+ writer.setPrefix(prefix, uri);
+ return prefix;
+ }
+
+ }
+
+ /**
+ * Start an element.
+ * @param uri
+ * @param name
+ * @param attrs
+ * @throws XMLStreamException
+ */
+ protected void writeStart(XMLStreamWriter writer, String uri, String name, XAttr... attrs) throws XMLStreamException {
+ String prefix = writeElementPrefix(writer, uri);
+ writer.writeStartElement(uri, name);
+ if (prefix != null){
+ writer.writeNamespace(prefix,uri);
+ }
+ writeAttributePrefixes(writer, attrs);
+ writeAttributes(writer, attrs);
+ }
+
+ /**
+ * Start an element.
+ * @param qname
+ * @param attrs
+ * @throws XMLStreamException
+ */
+ protected void writeStart(XMLStreamWriter writer, QName qname, XAttr... attrs) throws XMLStreamException {
+ writeStart(writer, qname.getNamespaceURI(), qname.getLocalPart(), attrs);
+ }
+
+ /**
+ * End an element.
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void writeEnd(XMLStreamWriter writer) throws XMLStreamException {
+ writer.writeEndElement();
+ }
+
+ /**
+ * Start a document.
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void writeStartDocument(XMLStreamWriter writer, String uri, String name, XAttr... attrs) throws XMLStreamException {
+ writer.writeStartDocument();
+ writer.setDefaultNamespace(uri);
+ writeStart(writer, uri, name, attrs);
+ writer.writeDefaultNamespace(uri);
+ }
+
+ /**
+ * Start a document.
+ * @param writer
+ * @param qname
+ * @param attrs
+ * @throws XMLStreamException
+ */
+ protected void writeStartDocument(XMLStreamWriter writer, QName qname, XAttr... attrs) throws XMLStreamException {
+ writeStartDocument(writer, qname.getNamespaceURI(), qname.getLocalPart(), attrs);
+ }
+
+ /**
+ * End a document.
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void writeEndDocument(XMLStreamWriter writer) throws XMLStreamException {
+ writer.writeEndDocument();
+ }
+
+ /**
+ * Write attributes to the current element.
+ * @param writer
+ * @param attrs
+ * @throws XMLStreamException
+ */
+ protected void writeAttributes(XMLStreamWriter writer, XAttr... attrs) throws XMLStreamException {
+ for (XAttr attr : attrs) {
+ if (attr != null)
+ attr.write(writer);
+ }
+ }
+
+ /**
+ * Write attribute prefixes to the current element.
+ * @param writer
+ * @param attrs
+ * @throws XMLStreamException
+ */
+ protected void writeAttributePrefixes(XMLStreamWriter writer, XAttr... attrs) throws XMLStreamException {
+ for (XAttr attr : attrs) {
+ if (attr != null)
+ attr.writePrefix(writer);
+ }
+ }
+
+ /**
+ * Represents an XML attribute that needs to be written to a document.
+ */
+ public static class XAttr {
+
+ private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0";
+
+ private String uri = SCA10_NS;
+ private String name;
+ private Object value;
+
+ public XAttr(String uri, String name, String value) {
+ this.uri = uri;
+ this.name = name;
+ this.value = value;
+ }
+
+ public XAttr(String name, String value) {
+ this(null, name, value);
+ }
+
+ public XAttr(String uri, String name, List<?> values) {
+ this.uri = uri;
+ this.name = name;
+ this.value = values;
+ }
+
+ public XAttr(String name, List<?> values) {
+ this(null, name, values);
+ }
+
+ public XAttr(String uri, String name, Boolean value) {
+ this.uri = uri;
+ this.name = name;
+ this.value = value;
+ }
+
+ public XAttr(String name, Boolean value) {
+ this(null, name, value);
+ }
+
+ public XAttr(String uri, String name, Integer value) {
+ this.uri = uri;
+ this.name = name;
+ this.value = value;
+ }
+
+ public XAttr(String name, Integer value) {
+ this(null, name, value);
+ }
+
+ public XAttr(String uri, String name, Double value) {
+ this.uri = uri;
+ this.name = name;
+ this.value = value;
+ }
+
+ public XAttr(String name, Double value) {
+ this(null, name, value);
+ }
+
+ public XAttr(String uri, String name, QName value) {
+ this.uri = uri;
+ this.name = name;
+ this.value = value;
+ }
+
+ public XAttr(String name, QName value) {
+ this(null, name, value);
+ }
+
+ /**
+ * Writes a string from a QName and registers a prefix for its namespace.
+ * @param reader
+ * @param value
+ * @return
+ */
+ private String writeQNameValue(XMLStreamWriter writer, QName qname) throws XMLStreamException {
+ if (qname != null) {
+ String prefix = qname.getPrefix();
+ String uri = qname.getNamespaceURI();
+ prefix = writer.getPrefix(uri);
+ if (prefix != null) {
+
+ // Use the prefix already bound to the given URI
+ if (prefix.length() > 0) {
+ return prefix + ":" + qname.getLocalPart();
+ } else {
+
+ // Empty prefix, just return the local part of the given qname
+ return qname.getLocalPart();
+ }
+
+ } else {
+
+ // Find an available prefix and bind it to the given URI
+ NamespaceContext nsc = writer.getNamespaceContext();
+ for (int i=1; ; i++) {
+ prefix = "ns" + i;
+ if (nsc.getNamespaceURI(prefix) == null) {
+ break;
+ }
+ }
+ writer.setPrefix(prefix, uri);
+ writer.writeNamespace(prefix, uri);
+ return prefix + ":" + qname.getLocalPart();
+ }
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Registers a prefix for the namespace of a QName.
+ * @param reader
+ * @param value
+ * @return
+ */
+ private void writeQNamePrefix(XMLStreamWriter writer, QName qname) throws XMLStreamException {
+ if (qname != null) {
+ String prefix = qname.getPrefix();
+ String uri = qname.getNamespaceURI();
+ prefix = writer.getPrefix(uri);
+ if (prefix != null) {
+ return;
+ } else {
+
+ // Find an available prefix and bind it to the given URI
+ NamespaceContext nsc = writer.getNamespaceContext();
+ for (int i=1; ; i++) {
+ prefix = "ns" + i;
+ if (nsc.getNamespaceURI(prefix) == null) {
+ break;
+ }
+ }
+ writer.setPrefix(prefix, uri);
+ writer.writeNamespace(prefix, uri);
+ }
+ }
+ }
+
+ /**
+ * Write to document
+ * @param writer
+ * @throws XMLStreamException
+ */
+ public void write(XMLStreamWriter writer) throws XMLStreamException {
+ String str;
+ if (value instanceof QName) {
+
+ // Write a QName
+ str = writeQNameValue(writer, (QName)value);
+
+ } else if (value instanceof List) {
+
+ // Write a list of values
+ List<?> values = (List<?>)value;
+ if (values.isEmpty()) {
+ return;
+ }
+ StringBuffer buffer = new StringBuffer();
+ for (Object v: values) {
+ if (v == null) {
+ // Skip null values
+ continue;
+ }
+
+ if (v instanceof XAttr) {
+ // Write an XAttr value
+ ((XAttr)v).write(writer);
+ continue;
+ }
+
+ if (buffer.length() != 0) {
+ buffer.append(' ');
+ }
+ if (v instanceof QName) {
+ // Write a QName value
+ buffer.append(writeQNameValue(writer, (QName)v));
+ } else {
+ // Write value as a string
+ buffer.append(String.valueOf(v));
+ }
+ }
+ str = buffer.toString();
+
+ } else {
+
+ // Write a string
+ if (value == null) {
+ return;
+ }
+ str = String.valueOf(value);
+ }
+ if (str.length() == 0) {
+ return;
+ }
+
+ // Write the attribute
+ if (uri != null && !uri.equals(SCA10_NS)) {
+ writer.writeAttribute(uri, name, str);
+ } else {
+ writer.writeAttribute(name,str);
+ }
+ }
+
+ /**
+ * Registers a prefix for the namespace of a QName or list of QNames
+ * @param writer
+ * @throws XMLStreamException
+ */
+ public void writePrefix(XMLStreamWriter writer) throws XMLStreamException {
+ if (value instanceof QName) {
+
+ // Write prefix for a single QName value
+ writeQNamePrefix(writer, (QName)value);
+
+ } else if (value instanceof List) {
+
+ // Write prefixes for a list of values
+ for (Object v: (List<?>)value) {
+ if (v instanceof QName) {
+ // Write prefix for a QName value
+ writeQNamePrefix(writer, (QName)v);
+
+ } else if (v instanceof XAttr) {
+ // Write prefix for an XAttr value
+ ((XAttr)v).writePrefix(writer);
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java
new file mode 100644
index 0000000000..3c67a8c550
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.processor;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * The default implementation of an artifact processor extension point.
+ *
+ * @version $Rev$ $Date$
+ */
+abstract class DefaultArtifactProcessorExtensionPoint<P> {
+ protected final Map<Object, P> processorsByArtifactType = new HashMap<Object, P>();
+ protected final Map<Class<?>, P> processorsByModelType = new HashMap<Class<?>, P>();
+
+ /**
+ * Constructs a new loader registry.
+ */
+ DefaultArtifactProcessorExtensionPoint() {
+ }
+
+ /**
+ * Returns the processor associated with the given artifact type.
+ *
+ * @param artifactType An artifact type
+ * @return The processor associated with the given artifact type
+ */
+ public P getProcessor(Object artifactType) {
+ return processorsByArtifactType.get(artifactType);
+ }
+
+ /**
+ * Returns the processor associated with the given model type.
+ *
+ * @param modelType A model type
+ * @return The processor associated with the given model type
+ */
+ public P getProcessor(Class<?> modelType) {
+ Class<?>[] classes = modelType.getInterfaces();
+ for (Class<?> c : classes) {
+ P processor = processorsByModelType.get(c);
+ if (processor != null) {
+ return processor;
+ }
+ }
+ return processorsByModelType.get(modelType);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.java
new file mode 100644
index 0000000000..426d7beb29
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultPackageProcessorExtensionPoint.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.processor;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.reflect.Constructor;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tuscany.sca.contribution.service.ContributionException;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+
+/**
+ * Default implementation of a package processor extension point.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultPackageProcessorExtensionPoint implements PackageProcessorExtensionPoint {
+
+ private Map<String, PackageProcessor> processors = new HashMap<String, PackageProcessor>();
+ private boolean loaded;
+
+ public DefaultPackageProcessorExtensionPoint() {
+ }
+
+ public void addPackageProcessor(PackageProcessor processor) {
+ processors.put(processor.getPackageType(), processor);
+ }
+
+ public void removePackageProcessor(PackageProcessor processor) {
+ processors.remove(processor.getPackageType());
+ }
+
+ public PackageProcessor getPackageProcessor(String contentType) {
+ loadProcessors();
+ return processors.get(contentType);
+ }
+
+ private void loadProcessors() {
+ if (loaded)
+ return;
+
+ // Get the processor service declarations
+ Set<ServiceDeclaration> processorDeclarations;
+ try {
+ processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(PackageProcessor.class);
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+
+ for (ServiceDeclaration processorDeclaration: processorDeclarations) {
+ Map<String, String> attributes = processorDeclaration.getAttributes();
+
+ // Load a URL artifact processor
+ String packageType = attributes.get("type");
+
+ // Create a processor wrapper and register it
+ PackageProcessor processor = new LazyPackageProcessor(packageType, processorDeclaration);
+ addPackageProcessor(processor);
+ }
+
+ loaded = true;
+ }
+
+ /**
+ * A facade for package processors.
+ */
+ private static class LazyPackageProcessor implements PackageProcessor {
+
+ private ServiceDeclaration processorDeclaration;
+ private String packageType;
+ private PackageProcessor processor;
+
+ private LazyPackageProcessor(String packageType, ServiceDeclaration processorDeclaration) {
+ this.processorDeclaration = processorDeclaration;
+ this.packageType = packageType;
+ }
+
+ public URL getArtifactURL(URL packageSourceURL, URI artifact) throws MalformedURLException {
+ return getProcessor().getArtifactURL(packageSourceURL, artifact);
+ }
+
+ public List<URI> getArtifacts(URL packageSourceURL, InputStream inputStream) throws ContributionException, IOException {
+ return getProcessor().getArtifacts(packageSourceURL, inputStream);
+ }
+
+ public String getPackageType() {
+ return packageType;
+ }
+
+ @SuppressWarnings("unchecked")
+ private PackageProcessor getProcessor() {
+ if (processor == null) {
+ try {
+ Class<PackageProcessor> processorClass = (Class<PackageProcessor>)processorDeclaration.loadClass();
+ Constructor<PackageProcessor> constructor = processorClass.getConstructor();
+ processor = constructor.newInstance();
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return processor;
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java
new file mode 100644
index 0000000000..f23ebc2c36
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java
@@ -0,0 +1,388 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.processor;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+
+/**
+ * The default implementation of an extension point for StAX artifact processors.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultStAXArtifactProcessorExtensionPoint extends
+ DefaultArtifactProcessorExtensionPoint<StAXArtifactProcessor> implements StAXArtifactProcessorExtensionPoint {
+
+ private ExtensionPointRegistry extensionPoints;
+ private ModelFactoryExtensionPoint modelFactories;
+ private MonitorFactory monitorFactory;
+ private boolean loaded;
+ private StAXArtifactProcessor<Object> extensibleStAXProcessor;
+ private StAXAttributeProcessor<Object> extensibleStAXAttributeProcessor;
+ private Monitor monitor = null;
+
+ /**
+ * Constructs a new extension point.
+ */
+ public DefaultStAXArtifactProcessorExtensionPoint(ExtensionPointRegistry extensionPoints) {
+ this.extensionPoints = extensionPoints;
+ this.modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class);
+ XMLOutputFactory outputFactory = modelFactories.getFactory(XMLOutputFactory.class);
+ UtilityExtensionPoint utilities = this.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
+ if (monitorFactory != null)
+ this.monitor = monitorFactory.createMonitor();
+ this.extensibleStAXProcessor = new ExtensibleStAXArtifactProcessor(this, inputFactory, outputFactory, this.monitor);
+
+ StAXAttributeProcessorExtensionPoint attributeExtensionPoint = extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class);
+ this.extensibleStAXAttributeProcessor = new ExtensibleStAXAttributeProcessor(attributeExtensionPoint ,inputFactory, outputFactory, this.monitor);
+ }
+
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
+ public void addArtifactProcessor(StAXArtifactProcessor artifactProcessor) {
+ if (artifactProcessor.getArtifactType() != null) {
+ processorsByArtifactType.put((Object)artifactProcessor.getArtifactType(), artifactProcessor);
+ }
+ if (artifactProcessor.getModelType() != null) {
+ processorsByModelType.put(artifactProcessor.getModelType(), artifactProcessor);
+ }
+ }
+
+ public void removeArtifactProcessor(StAXArtifactProcessor artifactProcessor) {
+ if (artifactProcessor.getArtifactType() != null) {
+ processorsByArtifactType.remove((Object)artifactProcessor.getArtifactType());
+ }
+ if (artifactProcessor.getModelType() != null) {
+ processorsByModelType.remove(artifactProcessor.getModelType());
+ }
+ }
+
+ @Override
+ public StAXArtifactProcessor getProcessor(Class<?> modelType) {
+ loadArtifactProcessors();
+ return super.getProcessor(modelType);
+ }
+
+ @Override
+ public StAXArtifactProcessor getProcessor(Object artifactType) {
+ loadArtifactProcessors();
+ return super.getProcessor(artifactType);
+ }
+
+ /**
+ * Returns a QName object from a QName expressed as {ns}name
+ * or ns#name.
+ *
+ * @param qname
+ * @return
+ */
+ private static QName getQName(String qname) {
+ if (qname == null) {
+ return null;
+ }
+ qname = qname.trim();
+ if (qname.startsWith("{")) {
+ int h = qname.indexOf('}');
+ if (h != -1) {
+ return new QName(qname.substring(1, h), qname.substring(h + 1));
+ }
+ } else {
+ int h = qname.indexOf('#');
+ if (h != -1) {
+ return new QName(qname.substring(0, h), qname.substring(h + 1));
+ }
+ }
+ throw new IllegalArgumentException("Invalid qname: "+qname);
+ }
+
+ /**
+ * Lazily load artifact processors registered in the extension point.
+ */
+ private void loadArtifactProcessors() {
+ if (loaded)
+ return;
+
+ // Get the processor service declarations
+ Set<ServiceDeclaration> processorDeclarations;
+ try {
+ processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(StAXArtifactProcessor.class);
+ } catch (IOException e) {
+ IllegalStateException ie = new IllegalStateException(e);
+ error("IllegalStateException", extensibleStAXProcessor, ie);
+ throw ie;
+ }
+
+ for (ServiceDeclaration processorDeclaration : processorDeclarations) {
+ Map<String, String> attributes = processorDeclaration.getAttributes();
+
+ // Load a StAX artifact processor
+
+ // Get the model QName
+ QName artifactType = getQName(attributes.get("qname"));
+
+ // Get the model class name
+ String modelTypeName = attributes.get("model");
+
+ // Get the model factory class name
+ String factoryName = attributes.get("factory");
+
+ // Create a processor wrapper and register it
+ StAXArtifactProcessor processor =
+ new LazyStAXArtifactProcessor(artifactType, modelTypeName, factoryName,
+ processorDeclaration, extensionPoints, modelFactories,
+ extensibleStAXProcessor,extensibleStAXAttributeProcessor, monitor);
+ addArtifactProcessor(processor);
+ }
+
+ loaded = true;
+ }
+
+ /**
+ * A wrapper around an Artifact processor class allowing lazy loading and
+ * initialization of artifact processors.
+ */
+ private static class LazyStAXArtifactProcessor implements StAXArtifactProcessor {
+
+ private ExtensionPointRegistry extensionPoints;
+ private QName artifactType;
+ private String modelTypeName;
+ private String factoryName;
+ private ServiceDeclaration processorDeclaration;
+ private StAXArtifactProcessor processor;
+ private Class<?> modelType;
+ private StAXArtifactProcessor<Object> extensionProcessor;
+ private StAXAttributeProcessor<Object> extensionAttributeProcessor;
+ private Monitor monitor;
+
+ LazyStAXArtifactProcessor(QName artifactType,
+ String modelTypeName,
+ String factoryName,
+ ServiceDeclaration processorDeclaration,
+ ExtensionPointRegistry extensionPoints,
+ ModelFactoryExtensionPoint modelFactories,
+ StAXArtifactProcessor<Object> extensionProcessor,
+ StAXAttributeProcessor<Object> extensionAttributeProcessor,
+ Monitor monitor) {
+
+ this.extensionPoints = extensionPoints;
+ this.artifactType = artifactType;
+ this.modelTypeName = modelTypeName;
+ this.factoryName = factoryName;
+ this.processorDeclaration = processorDeclaration;
+ this.extensionProcessor = extensionProcessor;
+ this.extensionAttributeProcessor = extensionAttributeProcessor;
+ this.monitor = monitor;
+ }
+
+ public QName getArtifactType() {
+ return artifactType;
+ }
+
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private StAXArtifactProcessor getProcessor() {
+ if (processor == null) {
+
+ if (processorDeclaration.getClassName()
+ .equals("org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor")) {
+
+ // Specific initialization for the DefaultBeanModelProcessor
+ ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ PolicyFactory policyFactory = modelFactories.getFactory(PolicyFactory.class);
+ try {
+ Class<StAXArtifactProcessor> processorClass =
+ (Class<StAXArtifactProcessor>)processorDeclaration.loadClass();
+ Object modelFactory;
+ if (factoryName != null) {
+ Class<?> factoryClass = (Class<?>)processorDeclaration.loadClass(factoryName);
+ modelFactory = modelFactories.getFactory(factoryClass);
+ } else {
+ modelFactory = null;
+ }
+ Constructor<StAXArtifactProcessor> constructor =
+ processorClass.getConstructor(AssemblyFactory.class,
+ PolicyFactory.class,
+ QName.class,
+ Class.class,
+ Object.class,
+ Monitor.class);
+ processor =
+ constructor.newInstance(assemblyFactory,
+ policyFactory,
+ artifactType,
+ getModelType(),
+ modelFactory,
+ monitor);
+ } catch (Exception e) {
+ IllegalStateException ie = new IllegalStateException(e);
+ error("IllegalStateException", processor, ie);
+ throw ie;
+ }
+ } else {
+ ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+
+ // Load and instantiate the processor class
+ try {
+ Class<StAXArtifactProcessor> processorClass =
+ (Class<StAXArtifactProcessor>)processorDeclaration.loadClass();
+ try {
+ Constructor<StAXArtifactProcessor> constructor =
+ processorClass.getConstructor(ModelFactoryExtensionPoint.class, Monitor.class);
+ processor = constructor.newInstance(modelFactories, monitor);
+ } catch (NoSuchMethodException e) {
+ try {
+ Constructor<StAXArtifactProcessor> constructor =
+ processorClass.getConstructor(ExtensionPointRegistry.class, Monitor.class);
+ processor = constructor.newInstance(extensionPoints, monitor);
+ } catch (NoSuchMethodException e1) {
+ try {
+ Constructor<StAXArtifactProcessor> constructor =
+ processorClass.getConstructor(ModelFactoryExtensionPoint.class, StAXArtifactProcessor.class, Monitor.class);
+ processor = constructor.newInstance(modelFactories, extensionProcessor, monitor);
+ } catch (NoSuchMethodException e2) {
+ try {
+ Constructor<StAXArtifactProcessor> constructor =
+ processorClass.getConstructor(ModelFactoryExtensionPoint.class, StAXArtifactProcessor.class, StAXAttributeProcessor.class, Monitor.class);
+ processor = constructor.newInstance(modelFactories, extensionProcessor, extensionAttributeProcessor, monitor);
+ } catch (NoSuchMethodException e2a) {
+ try {
+ Constructor<StAXArtifactProcessor> constructor =
+ processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class, Monitor.class);
+ processor = constructor.newInstance(extensionPoints, extensionProcessor, monitor);
+ } catch (NoSuchMethodException e3) {
+ try {
+ Constructor<StAXArtifactProcessor> constructor =
+ processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class, StAXAttributeProcessor.class, Monitor.class);
+ processor = constructor.newInstance(extensionPoints, extensionProcessor, extensionAttributeProcessor, monitor);
+ } catch (NoSuchMethodException e3a) {
+
+ try {
+ Constructor<StAXArtifactProcessor> constructor =
+ processorClass.getConstructor(ModelFactoryExtensionPoint.class);
+ processor = constructor.newInstance(modelFactories);
+ } catch (NoSuchMethodException e4) {
+ try {
+ Constructor<StAXArtifactProcessor> constructor =
+ processorClass.getConstructor(ExtensionPointRegistry.class);
+ processor = constructor.newInstance(extensionPoints);
+ } catch (NoSuchMethodException e4a) {
+ try {
+ Constructor<StAXArtifactProcessor> constructor =
+ processorClass.getConstructor(ModelFactoryExtensionPoint.class, StAXArtifactProcessor.class);
+ processor = constructor.newInstance(modelFactories, extensionProcessor);
+ } catch (NoSuchMethodException e5) {
+ Constructor<StAXArtifactProcessor> constructor =
+ processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class);
+ processor = constructor.newInstance(extensionPoints, extensionProcessor);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ IllegalStateException ie = new IllegalStateException(e);
+ error("IllegalStateException", processor, ie);
+ throw ie;
+ }
+ }
+ }
+ return processor;
+ }
+
+ public Object read(XMLStreamReader inputSource) throws ContributionReadException, XMLStreamException {
+ return getProcessor().read(inputSource);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException,
+ XMLStreamException {
+ getProcessor().write(model, outputSource);
+ }
+
+ public Class<?> getModelType() {
+ if (modelTypeName != null && modelType == null) {
+ try {
+ modelType = processorDeclaration.loadClass(modelTypeName);
+ } catch (Exception e) {
+ IllegalStateException ie = new IllegalStateException(e);
+ error("IllegalStateException", processorDeclaration, ie);
+ throw ie;
+ }
+ }
+ return modelType;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException {
+ getProcessor().resolve(model, resolver);
+ }
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java
new file mode 100644
index 0000000000..d81e236b40
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java
@@ -0,0 +1,327 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.processor;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ * The default implementation of an extension point for StAX artifact processors.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultStAXAttributeProcessorExtensionPoint extends
+ DefaultArtifactProcessorExtensionPoint<StAXAttributeProcessor> implements StAXAttributeProcessorExtensionPoint {
+
+ private ExtensionPointRegistry extensionPoints;
+ private ModelFactoryExtensionPoint modelFactories;
+ private StAXAttributeProcessor<Object> extensibleStAXAttributeProcessor;
+ private boolean loaded;
+ private Monitor monitor = null;
+
+ /**
+ * Constructs a new extension point.
+ */
+ public DefaultStAXAttributeProcessorExtensionPoint(ExtensionPointRegistry extensionPoints) {
+ this.extensionPoints = extensionPoints;
+ this.modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class);
+ XMLOutputFactory outputFactory = modelFactories.getFactory(XMLOutputFactory.class);
+ UtilityExtensionPoint utilities = this.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
+ if (monitorFactory != null) {
+ this.monitor = monitorFactory.createMonitor();
+ }
+ this.extensibleStAXAttributeProcessor = new ExtensibleStAXAttributeProcessor(this, inputFactory, outputFactory, this.monitor);
+ }
+
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
+ public void addArtifactProcessor(StAXAttributeProcessor artifactProcessor) {
+ if (artifactProcessor.getArtifactType() != null) {
+ processorsByArtifactType.put((Object)artifactProcessor.getArtifactType(), artifactProcessor);
+ }
+ if (artifactProcessor.getModelType() != null) {
+ processorsByModelType.put(artifactProcessor.getModelType(), artifactProcessor);
+ }
+ }
+
+ public void removeArtifactProcessor(StAXAttributeProcessor artifactProcessor) {
+ if (artifactProcessor.getArtifactType() != null) {
+ processorsByArtifactType.remove((Object)artifactProcessor.getArtifactType());
+ }
+ if (artifactProcessor.getModelType() != null) {
+ processorsByModelType.remove(artifactProcessor.getModelType());
+ }
+ }
+
+ @Override
+ public StAXAttributeProcessor getProcessor(Class<?> modelType) {
+ loadArtifactProcessors();
+ return super.getProcessor(modelType);
+ }
+
+ @Override
+ public StAXAttributeProcessor getProcessor(Object artifactType) {
+ loadArtifactProcessors();
+ return super.getProcessor(artifactType);
+ }
+
+ /**
+ * Returns a QName object from a QName expressed as {ns}name
+ * or ns#name.
+ *
+ * @param qname
+ * @return
+ */
+ private static QName getQName(String qname) {
+ if (qname == null) {
+ return null;
+ }
+ qname = qname.trim();
+ if (qname.startsWith("{")) {
+ int h = qname.indexOf('}');
+ if (h != -1) {
+ return new QName(qname.substring(1, h), qname.substring(h + 1));
+ }
+ } else {
+ int h = qname.indexOf('#');
+ if (h != -1) {
+ return new QName(qname.substring(0, h), qname.substring(h + 1));
+ }
+ }
+ throw new IllegalArgumentException("Invalid qname: "+qname);
+ }
+
+ /**
+ * Lazily load artifact processors registered in the extension point.
+ */
+ private void loadArtifactProcessors() {
+ if (loaded)
+ return;
+
+ // Get the processor service declarations
+ Set<ServiceDeclaration> processorDeclarations;
+ try {
+ processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(StAXAttributeProcessor.class);
+ } catch (IOException e) {
+ IllegalStateException ie = new IllegalStateException(e);
+ error("IllegalStateException", extensibleStAXAttributeProcessor, ie);
+ throw ie;
+ }
+
+ for (ServiceDeclaration processorDeclaration : processorDeclarations) {
+ Map<String, String> attributes = processorDeclaration.getAttributes();
+
+ // Load a StAX artifact processor
+
+ // Get the model QName
+ QName artifactType = getQName(attributes.get("qname"));
+
+ // Get the model class name
+ String modelTypeName = attributes.get("model");
+
+ // Get the model factory class name
+ String factoryName = attributes.get("factory");
+
+ // Create a processor wrapper and register it
+ StAXAttributeProcessor processor =
+ new LazyStAXAttributeProcessor(artifactType, modelTypeName, factoryName,
+ processorDeclaration, extensionPoints, modelFactories,
+ extensibleStAXAttributeProcessor, monitor);
+ addArtifactProcessor(processor);
+ }
+
+ loaded = true;
+ }
+
+ /**
+ * A wrapper around an Artifact processor class allowing lazy loading and
+ * initialization of artifact processors.
+ */
+ private static class LazyStAXAttributeProcessor implements StAXAttributeProcessor {
+
+ private ExtensionPointRegistry extensionPoints;
+ private QName artifactType;
+ private String modelTypeName;
+ private String factoryName;
+ private ServiceDeclaration processorDeclaration;
+ private StAXAttributeProcessor processor;
+ private Class<?> modelType;
+ private StAXAttributeProcessor<Object> extensionProcessor;
+ private Monitor monitor;
+
+ LazyStAXAttributeProcessor(QName artifactType,
+ String modelTypeName,
+ String factoryName,
+ ServiceDeclaration processorDeclaration,
+ ExtensionPointRegistry extensionPoints,
+ ModelFactoryExtensionPoint modelFactories,
+ StAXAttributeProcessor<Object> extensionProcessor,
+ Monitor monitor) {
+
+ this.extensionPoints = extensionPoints;
+ this.artifactType = artifactType;
+ this.modelTypeName = modelTypeName;
+ this.factoryName = factoryName;
+ this.processorDeclaration = processorDeclaration;
+ this.extensionProcessor = extensionProcessor;
+ this.monitor = monitor;
+ }
+
+ public QName getArtifactType() {
+ return artifactType;
+ }
+
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private StAXAttributeProcessor getProcessor() {
+ if (processor == null) {
+ ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+
+ // Load and instantiate the processor class
+ try {
+ Class<StAXAttributeProcessor> processorClass =
+ (Class<StAXAttributeProcessor>)processorDeclaration.loadClass();
+ try {
+ Constructor<StAXAttributeProcessor> constructor =
+ processorClass.getConstructor(ModelFactoryExtensionPoint.class, Monitor.class);
+ processor = constructor.newInstance(modelFactories, monitor);
+ } catch (NoSuchMethodException e) {
+ try {
+ Constructor<StAXAttributeProcessor> constructor =
+ processorClass.getConstructor(ExtensionPointRegistry.class, Monitor.class);
+ processor = constructor.newInstance(extensionPoints, monitor);
+ } catch (NoSuchMethodException e1) {
+ try {
+ Constructor<StAXAttributeProcessor> constructor =
+ processorClass.getConstructor(ModelFactoryExtensionPoint.class, StAXArtifactProcessor.class, Monitor.class);
+ processor = constructor.newInstance(modelFactories, extensionProcessor, monitor);
+ } catch (NoSuchMethodException e2) {
+ try {
+ Constructor<StAXAttributeProcessor> constructor =
+ processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class, Monitor.class);
+ processor = constructor.newInstance(extensionPoints, extensionProcessor, monitor);
+ } catch (NoSuchMethodException e3) {
+ try {
+ Constructor<StAXAttributeProcessor> constructor =
+ processorClass.getConstructor(ModelFactoryExtensionPoint.class);
+ processor = constructor.newInstance(modelFactories);
+ } catch (NoSuchMethodException e4) {
+ try {
+ Constructor<StAXAttributeProcessor> constructor =
+ processorClass.getConstructor(ExtensionPointRegistry.class);
+ processor = constructor.newInstance(extensionPoints);
+ } catch (NoSuchMethodException e4a) {
+ try {
+ Constructor<StAXAttributeProcessor> constructor =
+ processorClass.getConstructor(ModelFactoryExtensionPoint.class, StAXArtifactProcessor.class);
+ processor = constructor.newInstance(modelFactories, extensionProcessor);
+ } catch (NoSuchMethodException e5) {
+ Constructor<StAXAttributeProcessor> constructor =
+ processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class);
+ processor = constructor.newInstance(extensionPoints, extensionProcessor);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ IllegalStateException ie = new IllegalStateException(e);
+ error("IllegalStateException", processor, ie);
+ throw ie;
+ }
+
+ }
+ return processor;
+ }
+
+ public Object read(QName attributeName, XMLStreamReader inputSource) throws ContributionReadException, XMLStreamException {
+ return getProcessor().read(attributeName, inputSource);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException {
+ getProcessor().write(model, outputSource);
+ }
+
+ public Class<?> getModelType() {
+ if (modelTypeName != null && modelType == null) {
+ try {
+ modelType = processorDeclaration.loadClass(modelTypeName);
+ } catch (Exception e) {
+ IllegalStateException ie = new IllegalStateException(e);
+ error("IllegalStateException", processorDeclaration, ie);
+ throw ie;
+ }
+ }
+ return modelType;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException {
+ getProcessor().resolve(model, resolver);
+ }
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java
new file mode 100644
index 0000000000..045c201638
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java
@@ -0,0 +1,242 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.processor;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.net.URI;
+import java.net.URL;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+
+/**
+ * The default implementation of a URL artifact processor extension point.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultURLArtifactProcessorExtensionPoint
+ extends DefaultArtifactProcessorExtensionPoint<URLArtifactProcessor>
+ implements URLArtifactProcessorExtensionPoint {
+
+ private ExtensionPointRegistry extensionPoints;
+ private StAXArtifactProcessor<?> staxProcessor;
+ private boolean loaded;
+ private Monitor monitor = null;
+
+ /**
+ * Constructs a new extension point.
+ */
+ public DefaultURLArtifactProcessorExtensionPoint(ExtensionPointRegistry extensionPoints) {
+ this.extensionPoints = extensionPoints;
+ ModelFactoryExtensionPoint modelFactories = this.extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class);
+ XMLOutputFactory outputFactory = modelFactories.getFactory(XMLOutputFactory.class);
+ UtilityExtensionPoint utilities = this.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
+ if (monitorFactory != null)
+ this.monitor = monitorFactory.createMonitor();
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, this.monitor);
+ }
+
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
+ public void addArtifactProcessor(URLArtifactProcessor artifactProcessor) {
+ if (artifactProcessor.getArtifactType() != null) {
+ processorsByArtifactType.put((Object)artifactProcessor.getArtifactType(), artifactProcessor);
+ }
+ if (artifactProcessor.getModelType() != null) {
+ processorsByModelType.put(artifactProcessor.getModelType(), artifactProcessor);
+ }
+ }
+
+ public void removeArtifactProcessor(URLArtifactProcessor artifactProcessor) {
+ if (artifactProcessor.getArtifactType() != null) {
+ processorsByArtifactType.remove((Object)artifactProcessor.getArtifactType());
+ }
+ if (artifactProcessor.getModelType() != null) {
+ processorsByModelType.remove(artifactProcessor.getModelType());
+ }
+ }
+
+ @Override
+ public URLArtifactProcessor getProcessor(Class<?> modelType) {
+ loadProcessors();
+ return super.getProcessor(modelType);
+ }
+
+ @Override
+ public URLArtifactProcessor getProcessor(Object artifactType) {
+ loadProcessors();
+ return super.getProcessor(artifactType);
+ }
+
+ /**
+ * Lazily load artifact processors registered in the extension point.
+ */
+ private void loadProcessors() {
+ if (loaded)
+ return;
+
+ // Get the processor service declarations
+ Set<ServiceDeclaration> processorDeclarations;
+ try {
+ processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(URLArtifactProcessor.class);
+ } catch (IOException e) {
+ IllegalStateException ie = new IllegalStateException(e);
+ error("IllegalStateException", staxProcessor, ie);
+ throw ie;
+ }
+
+ for (ServiceDeclaration processorDeclaration: processorDeclarations) {
+ Map<String, String> attributes = processorDeclaration.getAttributes();
+ // Load a URL artifact processor
+ String artifactType = attributes.get("type");
+ String modelTypeName = attributes.get("model");
+
+ // Create a processor wrapper and register it
+ URLArtifactProcessor processor = new LazyURLArtifactProcessor(artifactType, modelTypeName,
+ processorDeclaration, extensionPoints, staxProcessor, monitor);
+ addArtifactProcessor(processor);
+ }
+
+ loaded = true;
+ }
+
+ /**
+ * A wrapper around an Artifact processor class allowing lazy loading and
+ * initialization of artifact processors.
+ */
+ private static class LazyURLArtifactProcessor implements URLArtifactProcessor {
+
+ private ExtensionPointRegistry extensionPoints;
+ private String artifactType;
+ private String modelTypeName;
+ private ServiceDeclaration processorDeclaration;
+ private URLArtifactProcessor processor;
+ private Class<?> modelType;
+ private StAXArtifactProcessor<?> staxProcessor;
+ private Monitor monitor;
+
+ LazyURLArtifactProcessor(String artifactType,
+ String modelTypeName,
+ ServiceDeclaration processorDeclaration,
+ ExtensionPointRegistry extensionPoints,
+ StAXArtifactProcessor<?> staxProcessor,
+ Monitor monitor) {
+ this.artifactType = artifactType;
+ this.modelTypeName = modelTypeName;
+ this.processorDeclaration = processorDeclaration;
+ this.extensionPoints = extensionPoints;
+ this.staxProcessor = staxProcessor;
+ this.monitor = monitor;
+ }
+
+ public String getArtifactType() {
+ return artifactType;
+ }
+
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private URLArtifactProcessor getProcessor() {
+ if (processor == null) {
+ try {
+ ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ Class<URLArtifactProcessor> processorClass = (Class<URLArtifactProcessor>)processorDeclaration.loadClass();
+ try {
+ Constructor<URLArtifactProcessor> constructor = processorClass.getConstructor(ModelFactoryExtensionPoint.class, Monitor.class);
+ processor = constructor.newInstance(modelFactories, monitor);
+ } catch (NoSuchMethodException e) {
+ try {
+ Constructor<URLArtifactProcessor> constructor = processorClass.getConstructor(ModelFactoryExtensionPoint.class, StAXArtifactProcessor.class, Monitor.class);
+ processor = constructor.newInstance(modelFactories, staxProcessor, monitor);
+ } catch (NoSuchMethodException e2) {
+ Constructor<URLArtifactProcessor> constructor = processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class, Monitor.class);
+ processor = constructor.newInstance(extensionPoints, staxProcessor, monitor);
+ }
+ }
+ } catch (Exception e) {
+ IllegalStateException ie = new IllegalStateException(e);
+ error("IllegalStateException", processor, ie);
+ throw ie;
+ }
+ }
+ return processor;
+ }
+
+ public Object read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException {
+ return getProcessor().read(contributionURL, artifactURI, artifactURL);
+ }
+
+ public Class<?> getModelType() {
+ if (modelTypeName != null && modelType == null) {
+ try {
+ modelType = processorDeclaration.loadClass(modelTypeName);
+ } catch (ClassNotFoundException e) {
+ IllegalStateException ie = new IllegalStateException(e);
+ error("IllegalStateException", processorDeclaration, ie);
+ throw ie;
+ }
+ }
+ return modelType;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException {
+ getProcessor().resolve(model, resolver);
+ }
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultUnknownElementProcessor.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultUnknownElementProcessor.java
new file mode 100644
index 0000000000..d52a110c05
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultUnknownElementProcessor.java
@@ -0,0 +1,272 @@
+package org.apache.tuscany.sca.contribution.processor;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import java.util.ArrayList;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.traversal.DocumentTraversal;
+import org.w3c.dom.traversal.NodeFilter;
+import org.w3c.dom.traversal.NodeIterator;
+import org.w3c.dom.traversal.TreeWalker;
+
+public class DefaultUnknownElementProcessor{
+
+ private Monitor monitor;
+ private static final Logger logger = Logger.getLogger(DefaultUnknownElementProcessor.class.getName());
+
+ public DefaultUnknownElementProcessor(Monitor monitor){
+ this.monitor = monitor;
+ }
+ private DocumentBuilderFactory documentBuilderFactory;
+ private Document document;
+
+ /**
+ * Reads the contetns of the unknown elements and generates the DOM
+ * @param reader
+ * @param name
+ * @return
+ * @throws XMLStreamException
+ */
+ public Object read(XMLStreamReader reader, QName name) throws XMLStreamException{
+
+ int event = reader.getEventType();
+ int level = 0;
+ ArrayList<String> elementList = new ArrayList<String>();
+ document = createDocument();
+ while(reader.hasNext()){
+ switch(event){
+ case START_ELEMENT:
+ elementList.add(reader.getName().getLocalPart());
+ if(level == 0){
+ generateDOM(reader,null);
+ level++;
+ }
+ else{
+ generateDOM(reader,elementList.get(elementList.size()-2).toString());
+ }
+
+ break;
+ case END_ELEMENT:
+ elementList.remove(reader.getName().getLocalPart());
+ }
+ if(reader.hasNext()){
+ event = reader.next();
+ }
+
+ if(event == START_ELEMENT || event == END_ELEMENT){
+ if(reader.getName().equals(name)){
+ break;
+ }
+ }
+ }
+ return document;
+ }
+
+ /**
+ * Writes unknown portions back to the writer
+ * @param model
+ * @param writer
+ */
+ public void write(Object model, XMLStreamWriter writer) {
+
+ if( ! (model instanceof Document)) {
+ return;
+ }
+
+ Document doc = (Document)model;
+ try{
+ DocumentTraversal traversal = (DocumentTraversal)doc;
+ TreeWalker walker = traversal.createTreeWalker(doc.getDocumentElement(),NodeFilter.SHOW_ALL, null, true);
+ writeDOM(walker,writer);
+ }
+ catch(Exception e){
+ if (logger.isLoggable(Level.SEVERE)) {
+ logger.log(Level.SEVERE, "Document not created ");
+ }
+ error("Document not created",document,e);
+ }
+ }
+
+ /**
+ * Method to generate the DOM
+ * @param reader
+ * @param parent
+ * @throws Exception
+ */
+ //private void generateDOM(String elementText, String parent) {
+ private void generateDOM(XMLStreamReader reader, String parent) {
+ try{
+ String elePrefix = reader.getPrefix();
+ String eleQName = reader.getLocalName();
+ if (elePrefix != null && elePrefix.length() != 0) {
+ eleQName = elePrefix + ":" + eleQName;
+ }
+
+ Element element = document.createElementNS(reader.getNamespaceURI(), eleQName);
+
+ int attributeCount = reader.getAttributeCount();
+ for(int i = 0;i < attributeCount;i++){
+ String ns = reader.getAttributeNamespace(i);
+ String prefix = reader.getAttributePrefix(i);
+ String qname = reader.getAttributeLocalName(i);
+ String value = reader.getAttributeValue(i);
+ if (prefix != null && prefix.length() != 0) {
+ qname = prefix + ":" + qname;
+ }
+ element.setAttributeNS(ns,qname,value);
+ }
+ if(parent == null){
+ if(document != null){
+ document.appendChild(element);
+ }
+ else{
+ if (logger.isLoggable(Level.SEVERE)) {
+ logger.log(Level.SEVERE, "Document not created ");
+ }
+ error("Document not created",document,element);
+ }
+ }
+ else{
+ Node parentNode = getParentNode(document,parent);
+ if(parentNode != null){
+ parentNode.appendChild(element);
+ }
+ else{
+ if (logger.isLoggable(Level.SEVERE)) {
+ logger.log(Level.SEVERE, "Parent node not found");
+ }
+ error("Parent node not found",document,parentNode.getNodeName());
+ }
+ }
+ }
+ catch(Exception e){
+ e.printStackTrace();
+ if (logger.isLoggable(Level.SEVERE)) {
+ logger.log(Level.SEVERE, "Document not created ");
+ }
+ error("Document not created",document,e);
+ }
+ }
+
+ /**
+ * Method to create an empty document
+ * @return
+ */
+ private Document createDocument() {
+ try {
+ if (documentBuilderFactory == null) {
+ documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ }
+ document = documentBuilderFactory.newDocumentBuilder().newDocument();
+ return document;
+ } catch (ParserConfigurationException e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+ /**
+ * Method to traverse the DOM structure and write the elements
+ * @param walker
+ * @param writer
+ * @throws XMLStreamException
+ */
+ private void writeDOM(TreeWalker walker,XMLStreamWriter writer) throws XMLStreamException {
+
+ Node parent = walker.getCurrentNode();
+
+ writer.writeStartElement(parent.getPrefix(), parent.getLocalName(), parent.getNamespaceURI());
+
+ NamedNodeMap attributes = parent.getAttributes();
+
+ for(int i = 0;i<attributes.getLength();i++){
+ writer.writeAttribute(attributes.item(i).getPrefix(), attributes.item(i).getNamespaceURI(), attributes.item(i).getLocalName(), attributes.item(i).getNodeValue());
+ }
+
+ for (Node n = walker.firstChild();n != null;n = walker.nextSibling()) {
+ writeDOM(walker,writer);
+ }
+ writer.writeEndElement();
+
+ walker.setCurrentNode(parent);
+ }
+
+ /**
+ * Method to get the Parent node out of the DOM structure
+ * @param doc
+ * @param parent
+ * @return
+ */
+ private Node getParentNode(Node doc,String parent) {
+ Node parentNode = null;
+ try{
+ DocumentTraversal traversal = (DocumentTraversal)doc;
+
+ CharSequence prefixChar = ":";
+ NodeIterator iterator = traversal.createNodeIterator(document.getDocumentElement(), NodeFilter.SHOW_ELEMENT, null, true);
+ for (Node n = iterator.nextNode(); n != null; n = iterator.nextNode()) {
+ String nodeName = n.getNodeName();
+ String[] str = null;
+ if(n.getNodeName().contains(prefixChar)){
+ str = nodeName.split(":");
+ nodeName = str[str.length-1];
+ }
+ if(parent.equalsIgnoreCase(nodeName)){
+ parentNode = n;
+ }
+ }
+ return parentNode;
+ }
+ catch(Exception e){
+ e.printStackTrace();
+ }
+ return parentNode;
+ }
+
+ /**
+ * Marshals exceptions into the monitor
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java
new file mode 100644
index 0000000000..7be5566113
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidatingXMLInputFactory.java
@@ -0,0 +1,313 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.processor;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.net.URL;
+import java.net.URLConnection;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.List;
+
+import javax.xml.XMLConstants;
+import javax.xml.stream.EventFilter;
+import javax.xml.stream.StreamFilter;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLReporter;
+import javax.xml.stream.XMLResolver;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.util.XMLEventAllocator;
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.validation.Schema;
+import javax.xml.validation.SchemaFactory;
+
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+
+/**
+ * Default implementation of an XMLInputFactory that creates validating
+ * XMLStreamReaders.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultValidatingXMLInputFactory extends ValidatingXMLInputFactory {
+
+ private XMLInputFactory inputFactory;
+ private ValidationSchemaExtensionPoint schemas;
+ private Monitor monitor;
+ private boolean initialized;
+ private boolean hasSchemas;
+ private Schema aggregatedSchema;
+
+ /**
+ * Constructs a new XMLInputFactory.
+ *
+ * @param inputFactory
+ * @param schemas
+ */
+ public DefaultValidatingXMLInputFactory(XMLInputFactory inputFactory, ValidationSchemaExtensionPoint schemas, Monitor monitor) {
+ this.inputFactory = inputFactory;
+ this.schemas = schemas;
+ this.monitor = monitor;
+ }
+
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Initialize the registered schemas and create an aggregated schema for
+ * validation.
+ */
+ private void initializeSchemas() {
+ if (initialized) {
+ return;
+ }
+ initialized = true;
+
+ // Load the XSDs registered in the validation schema extension point
+ try {
+ List<String> uris = schemas.getSchemas();
+ int n = uris.size();
+ if (n ==0) {
+ return;
+ } else {
+ hasSchemas = true;
+ }
+ final Source[] sources = new Source[n];
+ for (int i =0; i < n; i++) {
+ final String uri = uris.get(i);
+ // Allow privileged access to open URL stream. Requires FilePermission in security policy.
+ final URL url = new URL( uri );
+ InputStream urlStream;
+ try {
+ urlStream = AccessController.doPrivileged(new PrivilegedExceptionAction<InputStream>() {
+ public InputStream run() throws IOException {
+ URLConnection connection = url.openConnection();
+ connection.setUseCaches(false);
+ return connection.getInputStream();
+ }
+ });
+ } catch (PrivilegedActionException e) {
+ error("PrivilegedActionException", url, (IOException)e.getException());
+ throw (IOException)e.getException();
+ }
+ sources[i] = new StreamSource(urlStream, uri);
+ }
+
+ // Create an aggregated validation schemas from all the XSDs
+ final SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
+ // Allow privileged access to check files. Requires FilePermission
+ // in security policy.
+ try {
+ aggregatedSchema = AccessController.doPrivileged(new PrivilegedExceptionAction<Schema>() {
+ public Schema run() throws SAXException {
+ return schemaFactory.newSchema(sources);
+ }
+ });
+ } catch (PrivilegedActionException e) {
+ error("PrivilegedActionException", schemaFactory, (SAXException)e.getException());
+ throw (SAXException)e.getException();
+ }
+
+ } catch (Error e) {
+ // FIXME Log this, some old JDKs don't support XMLSchema validation
+ //e.printStackTrace();
+ } catch (SAXParseException e) {
+ IllegalStateException ie = new IllegalStateException(e);
+ error("IllegalStateException", schemas, ie);
+ throw ie;
+ } catch (Exception e) {
+ //FIXME Log this, some old JDKs don't support XMLSchema validation
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public XMLEventReader createFilteredReader(XMLEventReader arg0, EventFilter arg1) throws XMLStreamException {
+ return inputFactory.createFilteredReader(arg0, arg1);
+ }
+
+ @Override
+ public XMLStreamReader createFilteredReader(XMLStreamReader arg0, StreamFilter arg1) throws XMLStreamException {
+ return inputFactory.createFilteredReader(arg0, arg1);
+ }
+
+ @Override
+ public XMLEventReader createXMLEventReader(InputStream arg0, String arg1) throws XMLStreamException {
+ return inputFactory.createXMLEventReader(arg0, arg1);
+ }
+
+ @Override
+ public XMLEventReader createXMLEventReader(InputStream arg0) throws XMLStreamException {
+ return inputFactory.createXMLEventReader(arg0);
+ }
+
+ @Override
+ public XMLEventReader createXMLEventReader(Reader arg0) throws XMLStreamException {
+ return inputFactory.createXMLEventReader(arg0);
+ }
+
+ @Override
+ public XMLEventReader createXMLEventReader(Source arg0) throws XMLStreamException {
+ return inputFactory.createXMLEventReader(arg0);
+ }
+
+ @Override
+ public XMLEventReader createXMLEventReader(String arg0, InputStream arg1) throws XMLStreamException {
+ return inputFactory.createXMLEventReader(arg0, arg1);
+ }
+
+ @Override
+ public XMLEventReader createXMLEventReader(String arg0, Reader arg1) throws XMLStreamException {
+ return inputFactory.createXMLEventReader(arg0, arg1);
+ }
+
+ @Override
+ public XMLEventReader createXMLEventReader(XMLStreamReader arg0) throws XMLStreamException {
+ return inputFactory.createXMLEventReader(arg0);
+ }
+
+ @Override
+ public XMLStreamReader createXMLStreamReader(InputStream arg0, String arg1) throws XMLStreamException {
+ initializeSchemas();
+ if (hasSchemas) {
+ return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0, arg1), aggregatedSchema, monitor);
+ }else {
+ return inputFactory.createXMLStreamReader(arg0, arg1);
+ }
+ }
+
+ @Override
+ public XMLStreamReader createXMLStreamReader(InputStream arg0) throws XMLStreamException {
+ initializeSchemas();
+ if (hasSchemas) {
+ return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0), aggregatedSchema, monitor);
+ } else {
+ return inputFactory.createXMLStreamReader(arg0);
+ }
+ }
+
+ @Override
+ public XMLStreamReader createXMLStreamReader(Reader arg0) throws XMLStreamException {
+ initializeSchemas();
+ if (hasSchemas) {
+ return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0), aggregatedSchema, monitor);
+ } else {
+ return inputFactory.createXMLStreamReader(arg0);
+ }
+ }
+
+ @Override
+ public XMLStreamReader createXMLStreamReader(Source arg0) throws XMLStreamException {
+ initializeSchemas();
+ if (hasSchemas) {
+ return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0), aggregatedSchema, monitor);
+ } else {
+ return inputFactory.createXMLStreamReader(arg0);
+ }
+ }
+
+ @Override
+ public XMLStreamReader createXMLStreamReader(String arg0, InputStream arg1) throws XMLStreamException {
+ initializeSchemas();
+ if (hasSchemas) {
+ return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0, arg1), aggregatedSchema, monitor);
+ } else {
+ return inputFactory.createXMLStreamReader(arg0, arg1);
+ }
+ }
+
+ @Override
+ public XMLStreamReader createXMLStreamReader(String arg0, Reader arg1) throws XMLStreamException {
+ initializeSchemas();
+ if (hasSchemas) {
+ return new ValidatingXMLStreamReader(inputFactory.createXMLStreamReader(arg0, arg1), aggregatedSchema, monitor);
+ } else {
+ return inputFactory.createXMLStreamReader(arg0, arg1);
+ }
+ }
+
+ @Override
+ public XMLEventAllocator getEventAllocator() {
+ return inputFactory.getEventAllocator();
+ }
+
+ @Override
+ public Object getProperty(String arg0) throws IllegalArgumentException {
+ return inputFactory.getProperty(arg0);
+ }
+
+ @Override
+ public XMLReporter getXMLReporter() {
+ return inputFactory.getXMLReporter();
+ }
+
+ @Override
+ public XMLResolver getXMLResolver() {
+ return inputFactory.getXMLResolver();
+ }
+
+ @Override
+ public boolean isPropertySupported(String arg0) {
+ return inputFactory.isPropertySupported(arg0);
+ }
+
+ @Override
+ public void setEventAllocator(XMLEventAllocator arg0) {
+ inputFactory.setEventAllocator(arg0);
+ }
+
+ @Override
+ public void setProperty(String arg0, Object arg1) throws IllegalArgumentException {
+ inputFactory.setProperty(arg0, arg1);
+ }
+
+ @Override
+ public void setXMLReporter(XMLReporter arg0) {
+ inputFactory.setXMLReporter(arg0);
+ }
+
+ @Override
+ public void setXMLResolver(XMLResolver arg0) {
+ inputFactory.setXMLResolver(arg0);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidationSchemaExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidationSchemaExtensionPoint.java
new file mode 100644
index 0000000000..a6631f498e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultValidationSchemaExtensionPoint.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.processor;
+
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+
+/**
+ * Default implementation of an extension point for XML schemas.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultValidationSchemaExtensionPoint implements ValidationSchemaExtensionPoint {
+
+ private List<String> schemas = new ArrayList<String>();
+ private boolean loaded;
+
+ public void addSchema(String uri) {
+ schemas.add(uri);
+ }
+
+ public void removeSchema(String uri) {
+ schemas.remove(uri);
+ }
+
+ /**
+ * Load schema declarations from META-INF/services/
+ * org.apache.tuscany.sca.contribution.processor.ValidationSchema files
+ */
+ private void loadSchemas() {
+ if (loaded)
+ return;
+
+ // Get the schema declarations
+ Set<ServiceDeclaration> schemaDeclarations;
+ try {
+ schemaDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations("org.apache.tuscany.sca.contribution.processor.ValidationSchema");
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+
+ // TODO - temp fix to ensure that the schema tuscany-sca.xsd always comes first
+ String tuscanyScaXsd = null;
+
+ // Find each schema
+ for (ServiceDeclaration schemaDeclaration: schemaDeclarations) {
+ URL url = schemaDeclaration.getResource(schemaDeclaration.getClassName());
+ if (url == null) {
+ throw new IllegalArgumentException(new FileNotFoundException(schemaDeclaration.getClassName()));
+ }
+
+ if (url.toString().contains("tuscany-sca.xsd")){
+ tuscanyScaXsd = url.toString();
+ } else {
+ schemas.add(url.toString());
+ }
+ }
+
+ if (tuscanyScaXsd != null){
+ schemas.add(0, tuscanyScaXsd);
+ }
+
+ loaded = true;
+ }
+
+ public List<String> getSchemas() {
+ loadSchemas();
+ return schemas;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensiblePackageProcessor.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensiblePackageProcessor.java
new file mode 100644
index 0000000000..7ed2d45c2f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensiblePackageProcessor.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.processor;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.contribution.service.ContributionException;
+import org.apache.tuscany.sca.contribution.service.TypeDescriber;
+import org.apache.tuscany.sca.contribution.service.UnsupportedPackageTypeException;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ * Implementation of an extensible package processor.
+ *
+ * Takes a package processor extension point and delegates to the proper package
+ * processor from the extension point based on the package's content type.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ExtensiblePackageProcessor implements PackageProcessor {
+
+ private PackageProcessorExtensionPoint processors;
+ private TypeDescriber packageTypeDescriber;
+ private Monitor monitor;
+
+ public ExtensiblePackageProcessor(PackageProcessorExtensionPoint processors,
+ TypeDescriber packageTypeDescriber,
+ Monitor monitor) {
+ this.processors = processors;
+ this.packageTypeDescriber = packageTypeDescriber;
+ this.monitor = monitor;
+ }
+
+ /**
+ * Marshals errors into the monitor
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ protected void error(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ public List<URI> getArtifacts(URL packageSourceURL, InputStream inputStream)
+ throws ContributionException, IOException {
+ String packageType = this.packageTypeDescriber.getType(packageSourceURL, null);
+ if (packageType == null) {
+ error("UnsupportedPackageTypeException", packageTypeDescriber, packageSourceURL.toString());
+ throw new UnsupportedPackageTypeException("Unsupported contribution package type: " + packageSourceURL.toString());
+ }
+
+ PackageProcessor packageProcessor = this.processors.getPackageProcessor(packageType);
+ if (packageProcessor == null) {
+ error("UnsupportedPackageTypeException", packageTypeDescriber, packageType);
+ throw new UnsupportedPackageTypeException("Unsupported contribution package type: " + packageType);
+ }
+
+ return packageProcessor.getArtifacts(packageSourceURL, inputStream);
+ }
+
+ public URL getArtifactURL(URL packageSourceURL, URI artifact) throws MalformedURLException {
+ String contentType = this.packageTypeDescriber.getType(packageSourceURL, null);
+ PackageProcessor packageProcessor = this.processors.getPackageProcessor(contentType);
+ return packageProcessor.getArtifactURL(packageSourceURL, artifact);
+ }
+
+ public String getPackageType() {
+ return null;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java
new file mode 100644
index 0000000000..ca5c36fe98
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXArtifactProcessor.java
@@ -0,0 +1,256 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.processor;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.contribution.service.UnrecognizedElementException;
+import org.apache.tuscany.sca.contribution.processor.DefaultUnknownElementProcessor;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ * Implementation of an extensible StAX artifact processor.
+ *
+ * Takes a StAXArtifactProcessorExtensionPoint and delegates to the proper
+ * StAXArtifactProcessor by element QName
+ *
+ * @version $Rev$ $Date$
+ */
+public class ExtensibleStAXArtifactProcessor
+ implements StAXArtifactProcessor<Object> {
+
+ private static final Logger logger = Logger.getLogger(ExtensibleStAXArtifactProcessor.class.getName());
+ private XMLInputFactory inputFactory;
+ private XMLOutputFactory outputFactory;
+ private StAXArtifactProcessorExtensionPoint processors;
+ private Monitor monitor;
+
+ /**
+ * Constructs a new ExtensibleStAXArtifactProcessor.
+ * @param processors
+ * @param inputFactory
+ * @param outputFactory
+ */
+ public ExtensibleStAXArtifactProcessor(StAXArtifactProcessorExtensionPoint processors,
+ XMLInputFactory inputFactory,
+ XMLOutputFactory outputFactory,
+ Monitor monitor) {
+ super();
+ this.processors = processors;
+ this.inputFactory = inputFactory;
+ this.outputFactory = outputFactory;
+ if (this.outputFactory != null) {
+ this.outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.TRUE);
+ }
+ this.monitor = monitor;
+ }
+
+ /**
+ * Report a warning.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void warning(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
+
+ public Object read(XMLStreamReader source) throws ContributionReadException, XMLStreamException {
+
+ // Delegate to the processor associated with the element QName
+ int event = source.getEventType();
+ if (event == XMLStreamConstants.START_DOCUMENT) {
+ source.nextTag();
+ }
+ QName name = source.getName();
+ StAXArtifactProcessor<?> processor = (StAXArtifactProcessor<?>)processors.getProcessor(name);
+ if (processor == null) {
+ DefaultUnknownElementProcessor unknownElementProcessor = new DefaultUnknownElementProcessor(monitor);
+ Location location = source.getLocation();
+ if (logger.isLoggable(Level.WARNING)) {
+ logger.warning("Element " + name + " cannot be processed. (" + location + ")");
+ }
+ warning("ElementCannotBeProcessed", processors, name, location);
+ //return null;
+ return unknownElementProcessor.read(source,name);
+ }
+ return processor.read(source);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException {
+
+ // Delegate to the processor associated with the model type
+ if (model != null) {
+ StAXArtifactProcessor processor = processors.getProcessor(model.getClass());
+ if (processor != null) {
+ processor.write(model, outputSource);
+ } else {
+ DefaultUnknownElementProcessor unknownElementProcessor = new DefaultUnknownElementProcessor(monitor);
+ unknownElementProcessor.write(model,outputSource);
+ if (logger.isLoggable(Level.WARNING)) {
+ logger.warning("No StAX processor is configured to handle " + model.getClass());
+ }
+ warning("NoStaxProcessor", processors, model.getClass());
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException {
+
+ // Delegate to the processor associated with the model type
+ if (model != null) {
+ StAXArtifactProcessor processor = processors.getProcessor(model.getClass());
+ if (processor != null) {
+ processor.resolve(model, resolver);
+ }
+ }
+ }
+
+ /**
+ * Read a model from an InputStream.
+ * @param is The artifact InputStream
+ * @param type Model type
+ * @return The model
+ * @throws ContributionReadException
+ */
+ public <M> M read(InputStream is, Class<M> type) throws ContributionReadException {
+ try {
+ XMLStreamReader reader;
+ try {
+ reader = inputFactory.createXMLStreamReader(is);
+ try {
+ reader.nextTag();
+ QName name = reader.getName();
+ Object mo = read(reader);
+ if (type.isInstance(mo)) {
+ return type.cast(mo);
+ } else {
+ error("UnrecognizedElementException", reader, name);
+ UnrecognizedElementException e = new UnrecognizedElementException(name);
+ throw e;
+ }
+ } catch (ContributionReadException e) {
+ Location location = reader.getLocation();
+ e.setLine(location.getLineNumber());
+ e.setColumn(location.getColumnNumber());
+ error("ContributionReadException", reader, e);
+ throw e;
+ } finally {
+ try {
+ reader.close();
+ } catch (XMLStreamException e) {
+ // ignore
+ }
+ }
+ } finally {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ } catch (XMLStreamException e) {
+ ContributionReadException ce = new ContributionReadException(e);
+ error("ContributionReadException", inputFactory, ce);
+ throw ce;
+ }
+ }
+
+ /**
+ * Write a model to an OutputStream.
+ * @param model
+ * @param os
+ * @throws ContributionWriteException
+ */
+ public void write(Object model, OutputStream os) throws ContributionWriteException {
+ try {
+ XMLStreamWriter writer = outputFactory.createXMLStreamWriter(os);
+ write(model, writer);
+ writer.flush();
+ writer.close();
+ } catch (XMLStreamException e) {
+ ContributionWriteException cw = new ContributionWriteException(e);
+ error("ContributionWriteException", outputFactory, cw);
+ throw cw;
+ }
+ }
+
+ public QName getArtifactType() {
+ return null;
+ }
+
+ public Class<Object> getModelType() {
+ return null;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java
new file mode 100644
index 0000000000..3329f0bf1c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleStAXAttributeProcessor.java
@@ -0,0 +1,224 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.processor;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.contribution.Constants;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ * Implementation of an extensible StAX attribute processor.
+ *
+ * Takes a StAXAttributeProcessorExtensionPoint and delegates to the proper
+ * StAXAttributeProcessor by attribute QName
+ *
+ * @version $Rev$ $Date$
+ */
+public class ExtensibleStAXAttributeProcessor
+ implements StAXAttributeProcessor<Object> {
+
+ private static final Logger logger = Logger.getLogger(ExtensibleStAXAttributeProcessor.class.getName());
+
+ private static final QName UNKNOWN_ATTRIBUTE = new QName(Constants.SCA10_TUSCANY_NS, "unknown");
+
+ private XMLInputFactory inputFactory;
+ private XMLOutputFactory outputFactory;
+ private StAXAttributeProcessorExtensionPoint processors;
+ private Monitor monitor;
+
+ /**
+ * Constructs a new ExtensibleStAXArtifactProcessor.
+ * @param processors
+ * @param inputFactory
+ * @param outputFactory
+ */
+ public ExtensibleStAXAttributeProcessor(StAXAttributeProcessorExtensionPoint processors,
+ XMLInputFactory inputFactory,
+ XMLOutputFactory outputFactory,
+ Monitor monitor) {
+ super();
+ this.processors = processors;
+ this.inputFactory = inputFactory;
+ this.outputFactory = outputFactory;
+ if (this.outputFactory != null) {
+ this.outputFactory.setProperty("javax.xml.stream.isRepairingNamespaces", Boolean.TRUE);
+ }
+ this.monitor = monitor;
+ }
+
+ /**
+ * Report a warning.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void warning(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
+
+ public Object read(QName attributeName, XMLStreamReader source) throws ContributionReadException, XMLStreamException {
+
+ // Delegate to the processor associated with the attribute QName
+ int event = source.getEventType();
+ if (event == XMLStreamConstants.START_DOCUMENT) {
+ source.nextTag();
+ }
+
+ StAXAttributeProcessor<?> processor = null;
+
+ //lookup for registered attribute processors
+ processor = (StAXAttributeProcessor<?>)processors.getProcessor(attributeName);
+ if (processor == null) {
+ Location location = source.getLocation();
+ if (logger.isLoggable(Level.WARNING)) {
+ logger.warning("Attribute " + attributeName + " cannot be processed. (" + location + ")");
+ }
+ warning("AttributeCannotBeProcessed", processors, attributeName, location);
+ } else {
+ return processor.read(attributeName, source);
+ }
+
+ return processor == null ? null : processor.read(attributeName, source);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException {
+
+ if(model == null) {
+ return;
+ }
+
+ // Delegate to the processor associated with the model type
+ StAXAttributeProcessor processor = processors.getProcessor(model.getClass());
+ if(processor == null) {
+ if (logger.isLoggable(Level.WARNING)) {
+ logger.warning("No StAX processor is configured to handle " + model.getClass());
+ }
+ warning("NoStaxProcessor", processors, model.getClass());
+ } else {
+ processor.write(model, outputSource);
+ return;
+ }
+ }
+
+
+
+ @SuppressWarnings("unchecked")
+ public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException {
+
+ // Delegate to the processor associated with the model type
+ if (model != null) {
+ StAXAttributeProcessor processor = processors.getProcessor(model.getClass());
+ if (processor != null) {
+ processor.resolve(model, resolver);
+ }
+ }
+ }
+
+ /**
+ * Read a model from an InputStream.
+ * @param is The artifact InputStream
+ * @param type Model type
+ * @return The model
+ * @throws ContributionReadException
+ */
+ public <M> M read(InputStream is, Class<M> type) throws ContributionReadException {
+ return null;
+ }
+
+ /**
+ * Write a model to an OutputStream.
+ * @param model
+ * @param os
+ * @throws ContributionWriteException
+ */
+ public void write(Object model, OutputStream os) throws ContributionWriteException {
+ try {
+ XMLStreamWriter writer = outputFactory.createXMLStreamWriter(os);
+ write(model, writer);
+ writer.flush();
+ writer.close();
+ } catch (XMLStreamException e) {
+ ContributionWriteException cw = new ContributionWriteException(e);
+ error("ContributionWriteException", outputFactory, cw);
+ throw cw;
+ }
+ }
+
+ public QName getArtifactType() {
+ return null;
+ }
+
+ public Class<Object> getModelType() {
+ return null;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java
new file mode 100644
index 0000000000..2fa9469b93
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtensibleURLArtifactProcessor.java
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.processor;
+
+import java.net.URI;
+import java.net.URL;
+
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.UnrecognizedElementException;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ * Implementation of an extensible URL artifact processor.
+ *
+ * Takes a URLArtifactProcessorExtensionPoint and delegates to the proper URLArtifactProcessor
+ * by either fileName or fileExtention
+ *
+ * @version $Rev$ $Date$
+ */
+public class ExtensibleURLArtifactProcessor
+ implements URLArtifactProcessor<Object> {
+
+ private URLArtifactProcessorExtensionPoint processors;
+ private Monitor monitor;
+
+ /**
+ * Constructs a new ExtensibleURLArtifactProcessor.
+ *
+ * @param processors
+ */
+ public ExtensibleURLArtifactProcessor(URLArtifactProcessorExtensionPoint processors, Monitor monitor) {
+ this.processors = processors;
+ this.monitor = monitor;
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object read(URL contributionURL, URI sourceURI, URL sourceURL) throws ContributionReadException {
+ URLArtifactProcessor<Object> processor = null;
+
+ // Delegate to the processor associated with file extension
+ String fileName = getFileName(sourceURL);
+
+ //try to retrieve a processor for the specific filename
+ processor = (URLArtifactProcessor<Object>)processors.getProcessor(fileName);
+
+ if (processor == null) {
+ //try to find my file type (extension)
+ String extension = sourceURL.getPath();
+
+ int extensionStart = extension.lastIndexOf('.');
+ //handle files without extension (e.g NOTICE)
+ if (extensionStart > 0) {
+ extension = extension.substring(extensionStart);
+ processor = (URLArtifactProcessor<Object>)processors.getProcessor(extension);
+ }
+ }
+
+ if (processor == null) {
+ return null;
+ }
+ return processor.read(contributionURL, sourceURI, sourceURL);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException {
+
+ // Delegate to the processor associated with the model type
+ if (model != null) {
+ URLArtifactProcessor processor = processors.getProcessor(model.getClass());
+ if (processor != null) {
+ processor.resolve(model, resolver);
+ }
+ }
+ }
+
+ public <M> M read(URL contributionURL, URI artifactURI, URL artifactUrl, Class<M> type)
+ throws ContributionReadException {
+ Object mo = read(contributionURL, artifactURI, artifactUrl);
+ if (type.isInstance(mo)) {
+ return type.cast(mo);
+ } else {
+ UnrecognizedElementException e = new UnrecognizedElementException(null);
+ e.setResourceURI(artifactURI.toString());
+ error("UnrecognizedElementException", processors, artifactURI.toString());
+ throw e;
+ }
+ }
+
+ public String getArtifactType() {
+ return null;
+ }
+
+ public Class<Object> getModelType() {
+ return null;
+ }
+
+ /**
+ * Returns the file name from a URL.
+ * @param url
+ * @return
+ */
+ private static String getFileName(URL url){
+ String fileName = url.getPath();
+ int pos = fileName.lastIndexOf("/");
+
+ return fileName.substring(pos +1);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessor.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessor.java
new file mode 100644
index 0000000000..f17f31edb1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessor.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.processor;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.util.List;
+
+import org.apache.tuscany.sca.contribution.service.ContributionException;
+
+/**
+ * Interface for contribution package processors
+ *
+ * Package processors understand the format of the contribution and how to get the
+ * artifacts in the contribution.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface PackageProcessor {
+
+ /**
+ * Returns the type of package supported by this package processor.
+ *
+ * @return the package type
+ */
+ String getPackageType();
+
+ /**
+ * Returns a list of artifacts in the contribution.
+ *
+ * @param packageSourceURL Contribution package location URL
+ * @param inputStream Optional content of the package
+ * @return List of artifact URIs
+ * @throws ContributionException
+ * @throws IOException
+ */
+ List<URI> getArtifacts(URL packageSourceURL, InputStream inputStream) throws ContributionException, IOException;
+
+ /**
+ * Return the URL for an artifact in the package.
+ *
+ * This is needed for archives such as jar files that have specific URL schemes
+ * for the artifacts they contain.
+ *
+ * @param packageSourceURL Contribution package location URL
+ * @param artifact The relative URI for the artifact
+ * @return The artifact URL
+ */
+ URL getArtifactURL(URL packageSourceURL, URI artifact) throws MalformedURLException;
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessorExtensionPoint.java
new file mode 100644
index 0000000000..ed99239b19
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/PackageProcessorExtensionPoint.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.processor;
+
+/**
+ * An extension point for package processors
+ *
+ * @version $Rev$ $Date$
+ */
+public interface PackageProcessorExtensionPoint {
+
+ /**
+ * Register a PackageProcessor using the package type as the key.
+ *
+ * @param processor The package processor
+ */
+ void addPackageProcessor(PackageProcessor processor);
+
+ /**
+ * Unregister a PackageProcessor.
+ *
+ * @param processor The package processor
+ */
+ void removePackageProcessor(PackageProcessor processor);
+
+ /**
+ * Returns the PackageProcessor for the given package type.
+ *
+ * @param packageType The package type
+ * @return The package processor
+ */
+ PackageProcessor getPackageProcessor(String packageType);
+
+} \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java
new file mode 100644
index 0000000000..fcf9347564
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessor.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.processor;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+
+/**
+ * An artifact processor that can read models from a StAX XMLStreamReader.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface StAXArtifactProcessor<M> extends ArtifactProcessor<M> {
+
+ /**
+ * Reads a model from an XMLStreamReader.
+ *
+ * @param reader The XMLStreamReader
+ * @return A model representation of the input.
+ */
+ M read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException;
+
+ /**
+ * Writes a model to an XMLStreamWriter.
+ *
+ * @param model A model representing the source
+ * @param writer The XML stream writer
+ * @throws ContributionWriteException
+ * @throws XMLStreamException
+ */
+ void write(M model, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException;
+
+ /**
+ * Returns the type of artifact handled by this artifact processor.
+ *
+ * @return The type of artifact handled by this artifact processor
+ */
+ QName getArtifactType();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java
new file mode 100644
index 0000000000..9700e2bc60
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.processor;
+
+/**
+ * An extension point for StAX artifact processors.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface StAXArtifactProcessorExtensionPoint extends
+ ArtifactProcessorExtensionPoint<StAXArtifactProcessor> {
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessor.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessor.java
new file mode 100644
index 0000000000..e8edb743a4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessor.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.processor;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+
+
+/**
+ * An artifact processor that can read attributes from a StAX XMLStreamReader.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface StAXAttributeProcessor<M> extends ArtifactProcessor<M>{
+
+ /**
+ * Reads a model from an XMLStreamReader.
+ *
+ * @param reader The XMLStreamReader
+ * @return A model representation of the input.
+ */
+ M read(QName attributeName, XMLStreamReader reader) throws ContributionReadException, XMLStreamException;
+
+ /**
+ * Writes a model to an XMLStreamWriter.
+ *
+ * @param model A model representing the source
+ * @param writer The XML stream writer
+ * @throws ContributionWriteException
+ * @throws XMLStreamException
+ */
+ void write(M model, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException;
+
+ /**
+ * Returns the type of artifact handled by this artifact processor.
+ *
+ * @return The type of artifact handled by this artifact processor
+ */
+ QName getArtifactType();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessorExtensionPoint.java
new file mode 100644
index 0000000000..ebad243c1c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessorExtensionPoint.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.processor;
+
+/**
+ * An extension point for StAX artifact processors.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface StAXAttributeProcessorExtensionPoint extends
+ ArtifactProcessorExtensionPoint<StAXAttributeProcessor> {
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java
new file mode 100644
index 0000000000..2ecddf5465
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessor.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.processor;
+
+import java.net.URI;
+import java.net.URL;
+
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+
+/**
+ * An artifact processor that can read models from a URL.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface URLArtifactProcessor<M> extends ArtifactProcessor<M> {
+
+ /**
+ * Reads a model from a URL.
+ *
+ * @param contributionURL Contribution location URL
+ * @param artifactURI Artifact URI
+ * @param artifactURL Artifact location URL
+ * @return A model representation of the input.
+ */
+ M read(URL contributionURL, URI artifactURI, URL artifactURL) throws ContributionReadException;
+
+ /**
+ * Returns the type of artifact handled by this artifact processor.
+ *
+ * @return The type of artifact handled by this artifact processor
+ */
+ String getArtifactType();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessorExtensionPoint.java
new file mode 100644
index 0000000000..7714586951
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessorExtensionPoint.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.processor;
+
+/**
+ * An extension point for URL artifact processors.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface URLArtifactProcessorExtensionPoint extends
+ ArtifactProcessorExtensionPoint<URLArtifactProcessor> {
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLInputFactory.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLInputFactory.java
new file mode 100644
index 0000000000..da249a09e4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLInputFactory.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.processor;
+
+import javax.xml.stream.XMLInputFactory;
+
+/**
+ * Base marker class for validating XML input factories.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class ValidatingXMLInputFactory extends XMLInputFactory {
+
+ /**
+ * Create a new default validating XML input factory.
+ * @return
+ */
+ public static ValidatingXMLInputFactory newInstance() {
+ return new DefaultValidatingXMLInputFactory(
+ XMLInputFactory.newInstance(),
+ new DefaultValidationSchemaExtensionPoint(),
+ null);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLStreamReader.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLStreamReader.java
new file mode 100644
index 0000000000..c136c62d33
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidatingXMLStreamReader.java
@@ -0,0 +1,388 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.processor;
+
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.util.StreamReaderDelegate;
+import javax.xml.validation.Schema;
+import javax.xml.validation.ValidatorHandler;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.ErrorHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXParseException;
+import org.xml.sax.helpers.AttributesImpl;
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ *
+ * A validating XMLStreamReader that reports XMLSchema validation errors.
+ *
+ * @version $Rev$ $Date$
+ */
+class ValidatingXMLStreamReader extends StreamReaderDelegate implements XMLStreamReader {
+ private static final Logger logger = Logger.getLogger(ValidatingXMLStreamReader.class.getName());
+
+ private int level;
+ private ValidatorHandler handler;
+ private final Monitor monitor;
+
+ /**
+ * Constructs a new ValidatingXMLStreamReader.
+ *
+ * @param reader
+ * @param schema
+ * @throws XMLStreamException
+ */
+ ValidatingXMLStreamReader(XMLStreamReader reader, Schema schema, Monitor monitor) throws XMLStreamException {
+ super(reader);
+ this.monitor = monitor;
+ if (schema == null) {
+ return;
+ }
+
+ handler = schema.newValidatorHandler();
+ handler.setDocumentLocator(new LocatorAdapter());
+ try {
+ handler.setFeature("http://xml.org/sax/features/namespace-prefixes", true);
+ } catch (SAXException e) {
+ XMLStreamException xse = new XMLStreamException(e);
+ error("XMLStreamException", handler, xse);
+ throw xse;
+ }
+
+ // These validation errors are just warnings for us as we want to support
+ // running from an XML document with XSD validation errors, as long as we can
+ // get the metadata we need from the document
+ handler.setErrorHandler(new ErrorHandler() {
+ private String getMessage(SAXParseException e) {
+ return "XMLSchema validation problem in: " + e.getSystemId() + ", line: " + e.getLineNumber() + ", column: " + e.getColumnNumber() + "\n" + e.getMessage();
+ }
+
+ public void error(SAXParseException exception) throws SAXException {
+ if (ValidatingXMLStreamReader.this.monitor == null)
+ logger.warning(getMessage(exception));
+ else
+ ValidatingXMLStreamReader.this.error("SchemaError", ValidatingXMLStreamReader.this.getClass(), exception.getSystemId(),
+ exception.getLineNumber(), exception.getColumnNumber(), exception.getMessage());
+ }
+
+ public void fatalError(SAXParseException exception) throws SAXException {
+ if (ValidatingXMLStreamReader.this.monitor == null)
+ logger.warning(getMessage(exception));
+ else
+ ValidatingXMLStreamReader.this.error("SchemaFatalError", ValidatingXMLStreamReader.this.getClass(), exception.getSystemId(),
+ exception.getLineNumber(), exception.getColumnNumber(), exception.getMessage());
+ }
+
+ public void warning(SAXParseException exception) throws SAXException {
+ if (ValidatingXMLStreamReader.this.monitor == null)
+ logger.warning(getMessage(exception));
+ else
+ ValidatingXMLStreamReader.this.warning("SchemaWarning", ValidatingXMLStreamReader.this.getClass(), exception.getSystemId(),
+ exception.getLineNumber(), exception.getColumnNumber(), exception.getMessage());
+ }
+ });
+ }
+
+ /**
+ * Report a warning.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void warning(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.WARNING, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ @Override
+ public int next() throws XMLStreamException {
+ if (handler == null) {
+ return super.next();
+ }
+
+ int event = super.next();
+ try {
+ switch (event) {
+ case XMLStreamConstants.START_DOCUMENT:
+ level++;
+ handler.startDocument();
+ break;
+ case XMLStreamConstants.START_ELEMENT:
+ level++;
+ handleStartElement();
+ break;
+ case XMLStreamConstants.PROCESSING_INSTRUCTION:
+ handler.processingInstruction(super.getPITarget(), super.getPIData());
+ break;
+ case XMLStreamConstants.CHARACTERS:
+ case XMLStreamConstants.CDATA:
+ case XMLStreamConstants.SPACE:
+ case XMLStreamConstants.ENTITY_REFERENCE:
+ handler.characters(super.getTextCharacters(), super.getTextStart(), super.getTextLength());
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ handleEndElement();
+ level--;
+ break;
+ case XMLStreamConstants.END_DOCUMENT:
+ handler.endDocument();
+ break;
+ }
+ } catch (SAXException e) {
+ XMLStreamException xse = new XMLStreamException(e.getMessage(), e);
+ error("XMLStreamException", handler, xse);
+ throw xse;
+ }
+ return event;
+ }
+
+ @Override
+ public int nextTag() throws XMLStreamException {
+ if (handler == null) {
+ return super.nextTag();
+ }
+
+ for (;;) {
+ int event = super.getEventType();
+ try {
+ switch (event) {
+ case XMLStreamConstants.START_DOCUMENT:
+ level++;
+ handler.startDocument();
+ break;
+ case XMLStreamConstants.START_ELEMENT:
+ level++;
+ handleStartElement();
+ return event;
+ case XMLStreamConstants.PROCESSING_INSTRUCTION:
+ handler.processingInstruction(super.getPITarget(), super.getPIData());
+ break;
+ case XMLStreamConstants.CHARACTERS:
+ case XMLStreamConstants.CDATA:
+ case XMLStreamConstants.SPACE:
+ case XMLStreamConstants.ENTITY_REFERENCE:
+ handler.characters(super.getTextCharacters(), super.getTextStart(), super.getTextLength());
+ break;
+ case XMLStreamConstants.END_ELEMENT:
+ handleEndElement();
+ level--;
+ return event;
+ case XMLStreamConstants.END_DOCUMENT:
+ handler.endDocument();
+ return event;
+ }
+ } catch (SAXException e) {
+ XMLStreamException xse = new XMLStreamException(e);
+ error("XMLStreamException", handler, xse);
+ throw xse;
+ }
+ super.next();
+ }
+ }
+
+ @Override
+ public String getElementText() throws XMLStreamException {
+ if (handler == null) {
+ return super.getElementText();
+ }
+
+ if (getEventType() != XMLStreamConstants.START_ELEMENT) {
+ return super.getElementText();
+ }
+ StringBuffer text = new StringBuffer();
+
+ for (;;) {
+ int event = next();
+ switch (event) {
+ case XMLStreamConstants.END_ELEMENT:
+ return text.toString();
+
+ case XMLStreamConstants.COMMENT:
+ case XMLStreamConstants.PROCESSING_INSTRUCTION:
+ continue;
+
+ case CHARACTERS:
+ case CDATA:
+ case SPACE:
+ case ENTITY_REFERENCE:
+ text.append(getText());
+ break;
+
+ default:
+ break;
+ }
+ }
+ }
+
+ /**
+ * Handle a start element event.
+ *
+ * @throws SAXException
+ */
+ private void handleStartElement() throws SAXException {
+
+ // send startPrefixMapping events immediately before startElement event
+ int nsCount = super.getNamespaceCount();
+ for (int i = 0; i < nsCount; i++) {
+ String prefix = super.getNamespacePrefix(i);
+ if (prefix == null) { // true for default namespace
+ prefix = "";
+ }
+ handler.startPrefixMapping(prefix, super.getNamespaceURI(i));
+ }
+
+ // fire startElement
+ QName qname = super.getName();
+ String prefix = qname.getPrefix();
+ String rawname;
+ if (prefix == null || prefix.length() == 0) {
+ rawname = qname.getLocalPart();
+ } else {
+ rawname = prefix + ':' + qname.getLocalPart();
+ }
+ Attributes attrs = getAttributes();
+ handler.startElement(qname.getNamespaceURI(), qname.getLocalPart(), rawname, attrs);
+ }
+
+ /**
+ * Handle an endElement event.
+ *
+ * @throws SAXException
+ */
+ private void handleEndElement() throws SAXException {
+
+ // fire endElement
+ QName qname = super.getName();
+ handler.endElement(qname.getNamespaceURI(), qname.getLocalPart(), qname.toString());
+
+ // send endPrefixMapping events immediately after endElement event
+ // we send them in the opposite order to that returned but this is not
+ // actually required by SAX
+ int nsCount = super.getNamespaceCount();
+ for (int i = nsCount - 1; i >= 0; i--) {
+ String prefix = super.getNamespacePrefix(i);
+ if (prefix == null) { // true for default namespace
+ prefix = "";
+ }
+ handler.endPrefixMapping(prefix);
+ }
+ }
+
+ /**
+ * Get the attributes associated with the current START_ELEMENT event.
+ *
+ * @return the StAX attributes converted to org.xml.sax.Attributes
+ */
+ private Attributes getAttributes() {
+ AttributesImpl attrs = new AttributesImpl();
+
+ // add namespace declarations
+ for (int i = 0; i < super.getNamespaceCount(); i++) {
+ String prefix = super.getNamespacePrefix(i);
+ String uri = super.getNamespaceURI(i);
+ if (prefix == null) {
+ attrs.addAttribute("", "", "xmlns", "CDATA", uri);
+ } else {
+ attrs.addAttribute("", "", "xmlns:" + prefix, "CDATA", uri);
+ }
+ }
+
+ // Regular attributes
+ for (int i = 0; i < super.getAttributeCount(); i++) {
+ String uri = super.getAttributeNamespace(i);
+ if (uri == null) {
+ uri = "";
+ }
+ String localName = super.getAttributeLocalName(i);
+ String prefix = super.getAttributePrefix(i);
+ String qname;
+ if (prefix == null || prefix.length() == 0) {
+ qname = localName;
+ } else {
+ qname = prefix + ':' + localName;
+ }
+ String type = super.getAttributeType(i);
+ String value = super.getAttributeValue(i);
+
+ attrs.addAttribute(uri, localName, qname, type, value);
+ }
+
+ return attrs;
+ }
+
+ /**
+ * Adapter for mapping Locator information.
+ */
+ private final class LocatorAdapter implements Locator {
+
+ private LocatorAdapter() {
+ }
+
+ public int getColumnNumber() {
+ Location location = getLocation();
+ return location == null ? 0 : location.getColumnNumber();
+ }
+
+ public int getLineNumber() {
+ Location location = getLocation();
+ return location == null ? 0 : location.getLineNumber();
+ }
+
+ public String getPublicId() {
+ Location location = getLocation();
+ return location == null ? "" : location.getPublicId();
+ }
+
+ public String getSystemId() {
+ Location location = getLocation();
+ return location == null ? "" : location.getSystemId();
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidationSchemaExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidationSchemaExtensionPoint.java
new file mode 100644
index 0000000000..cc3bb59a5b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ValidationSchemaExtensionPoint.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.processor;
+
+import java.util.List;
+
+
+/**
+ * An extension point for XML schemas used for validation.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ValidationSchemaExtensionPoint {
+
+ /**
+ * Add a schema.
+ *
+ * @param uri the URI of the schema
+ */
+ void addSchema(String uri);
+
+ /**
+ * Remove a schema.
+ *
+ * @param uri the URI of the schema
+ */
+ void removeSchema(String uri);
+
+ /**
+ * Returns the list of schemas registered in the extension point.
+ * @return the list of schemas
+ */
+ List<String> getSchemas();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ClassReference.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ClassReference.java
new file mode 100644
index 0000000000..f3555ee71e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ClassReference.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.resolver;
+
+import java.lang.ref.WeakReference;
+
+import org.apache.tuscany.sca.assembly.Base;
+
+/**
+ * A weak reference to a class, which should be used to register classes
+ * with an ArtifactResolver and resolve these classes later.
+ *
+ * FIXME The core contribution model should not have dependencies on classes
+ * and ClassLoaders. This should move to the Java import support module.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ClassReference implements Base {
+
+ private WeakReference<Class<?>> clazz;
+ private String className;
+
+ /**
+ * Constructs a new ClassReference.
+ *
+ * @param clazz The class reference
+ */
+ public ClassReference(Class<?> clazz) {
+ this.clazz = new WeakReference<Class<?>>(clazz);
+ this.className = clazz.getName();
+ }
+
+ /**
+ * Constructs a new ClassReference.
+ *
+ * @param className The class name
+ */
+ public ClassReference(String className) {
+ this.className = className;
+ }
+
+ /**
+ * Get the referenced class.
+ *
+ * @return The referenced class
+ */
+ public Class<?> getJavaClass() {
+ if (clazz != null) {
+ return clazz.get();
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Get the referenced class name.
+ *
+ * @return The class name
+ */
+ public String getClassName() {
+ return className;
+ }
+
+ public boolean isUnresolved() {
+ return clazz == null;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ throw new IllegalStateException();
+ }
+
+ @Override
+ public int hashCode() {
+ return className.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ } else {
+ if (obj instanceof ClassReference) {
+ return className.equals(((ClassReference)obj).className);
+ } else {
+ return false;
+ }
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultDelegatingModelResolver.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultDelegatingModelResolver.java
new file mode 100644
index 0000000000..13c622adf0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultDelegatingModelResolver.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.resolver;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Base;
+
+/**
+ * A model resolver implementation that delegates to a list of model resolvers.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultDelegatingModelResolver implements ModelResolver {
+
+ private List<ModelResolver> resolvers;
+
+ public DefaultDelegatingModelResolver(List<ModelResolver> resolvers) {
+ this.resolvers = resolvers;
+ }
+
+ public void addModel(Object resolved) {
+ throw new IllegalStateException();
+ }
+
+ public Object removeModel(Object resolved) {
+ throw new IllegalStateException();
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+
+ //TODO optimize and cache results of the resolution later
+
+ // Go over all resolvers
+ for (ModelResolver resolver: resolvers) {
+
+ Object resolved = resolver.resolveModel(modelClass, unresolved);
+
+ // Return the resolved model object
+ if (resolved instanceof Base) {
+ if (!((Base)resolved).isUnresolved()) {
+ return modelClass.cast(resolved);
+ }
+ }
+ }
+
+ // Model object was not resolved
+ return unresolved;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportAllModelResolver.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportAllModelResolver.java
new file mode 100644
index 0000000000..c6facd2b02
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportAllModelResolver.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.resolver;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Base;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.Export;
+import org.apache.tuscany.sca.contribution.Import;
+
+/**
+ * A model resolver implementation that considers Exports in a list of contributions.
+ *
+ * @version $Rev: 560435 $ $Date: 2007-07-27 18:26:55 -0700 (Fri, 27 Jul 2007) $
+ */
+public class DefaultImportAllModelResolver implements ModelResolver {
+
+ private Import import_;
+ private List<Contribution> contributions;
+
+ public DefaultImportAllModelResolver(Import import_, List<Contribution> contributions) {
+ this.import_ = import_;
+ this.contributions = contributions;
+ }
+
+ public void addModel(Object resolved) {
+ throw new IllegalStateException();
+ }
+
+ public Object removeModel(Object resolved) {
+ throw new IllegalStateException();
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+
+ //TODO optimize and cache results of the resolution later
+
+ // Go over all available contributions
+ for (Contribution contribution : contributions) {
+
+ // Go over all exports in the contribution
+ for (Export export : contribution.getExports()) {
+
+ // If the export matches the export, try to resolve the model object
+ if (import_.match(export)) {
+ Object resolved = export.getModelResolver().resolveModel(modelClass, unresolved);
+
+ // Return the resolved model object
+ if (resolved instanceof Base) {
+ if (!((Base)resolved).isUnresolved()) {
+ return modelClass.cast(resolved);
+ }
+ }
+ }
+ }
+ }
+
+ // Model object was not resolved
+ return unresolved;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportModelResolver.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportModelResolver.java
new file mode 100644
index 0000000000..9ae57c41d0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultImportModelResolver.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.resolver;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Base;
+import org.apache.tuscany.sca.contribution.Export;
+
+/**
+ * A model resolver implementation that delegates to a list of exports.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultImportModelResolver implements ModelResolver {
+
+ private List<Export> exports;
+
+ public DefaultImportModelResolver(List<Export> exports) {
+ this.exports = exports;
+ }
+
+ public void addModel(Object resolved) {
+ throw new IllegalStateException();
+ }
+
+ public Object removeModel(Object resolved) {
+ throw new IllegalStateException();
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+
+ //TODO optimize and cache results of the resolution later
+
+ // Go over all exports
+ for (Export export: exports) {
+
+ Object resolved = export.getModelResolver().resolveModel(modelClass, unresolved);
+
+ // Return the resolved model object
+ if (resolved instanceof Base) {
+ if (!((Base)resolved).isUnresolved()) {
+ return modelClass.cast(resolved);
+ }
+ }
+ }
+
+ // Model object was not resolved
+ return unresolved;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java
new file mode 100644
index 0000000000..bf175813f3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolver.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.resolver;
+
+import java.util.HashMap;
+import java.util.Map;
+
+
+/**
+ * A default implementation of a model resolver based on a map.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultModelResolver implements ModelResolver {
+
+ private Map<Object, Object> map = new HashMap<Object, Object>();
+
+ public DefaultModelResolver() {
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ Object resolved = map.get(unresolved);
+ if (resolved != null) {
+
+ // Return the resolved object
+ return modelClass.cast(resolved);
+
+ } else {
+
+ // Return the unresolved object
+ return unresolved;
+ }
+ }
+
+ public void addModel(Object resolved) {
+ map.put(resolved, resolved);
+ }
+
+ public Object removeModel(Object resolved) {
+ return map.remove(resolved);
+ }
+
+ // FIXME: TUSCANY-2499: temporarily give access to the models to get the jms binding
+ // use of definitions.xml working while the definitions.xml processing is being refactored
+ public Map getModels() {
+ return map;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java
new file mode 100644
index 0000000000..77570aa13d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/DefaultModelResolverExtensionPoint.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.resolver;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+
+
+/**
+ * The default implementation of a model resolver extension point.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultModelResolverExtensionPoint implements ModelResolverExtensionPoint {
+
+ private final Map<Class<?>, Class<? extends ModelResolver>> resolvers = new HashMap<Class<?>, Class<? extends ModelResolver>>();
+ private Map<String, ServiceDeclaration> loadedResolvers;
+
+ /**
+ * Constructs a new DefaultModelResolverExtensionPoint.
+ */
+ public DefaultModelResolverExtensionPoint() {
+ }
+
+ public void addResolver(Class<?> modelType, Class<? extends ModelResolver> resolver) {
+ resolvers.put(modelType, resolver);
+ }
+
+ public void removeResolver(Class<?> modelType) {
+ resolvers.remove(modelType);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Class<? extends ModelResolver> getResolver(Class<?> modelType) {
+ loadModelResolvers();
+
+ Class<?>[] classes = modelType.getInterfaces();
+ for (Class<?> c : classes) {
+ Class<? extends ModelResolver> resolver = resolvers.get(c);
+ if (resolver == null) {
+ ServiceDeclaration resolverClass = loadedResolvers.get(c.getName());
+ if (resolverClass != null) {
+ try {
+ return (Class<? extends ModelResolver>)resolverClass.loadClass();
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+ } else {
+ return resolver;
+ }
+ }
+
+ Class<? extends ModelResolver > resolver = resolvers.get(modelType);
+ if (resolver == null) {
+ ServiceDeclaration resolverClass = loadedResolvers.get(modelType.getName());
+ if (resolverClass != null) {
+ try {
+ return (Class<? extends ModelResolver>)resolverClass.loadClass();
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+ }
+ return resolver;
+ }
+
+ /**
+ * Dynamically load model resolvers declared under META-INF/services
+ */
+ private void loadModelResolvers() {
+ if (loadedResolvers != null)
+ return;
+ loadedResolvers = new HashMap<String, ServiceDeclaration>();
+
+ // Get the model resolver service declarations
+ Set<ServiceDeclaration> modelResolverDeclarations;
+ try {
+ modelResolverDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(ModelResolver.class);
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+
+ // Load model resolvers
+ for (ServiceDeclaration modelResolverDeclaration: modelResolverDeclarations) {
+ Map<String, String> attributes = modelResolverDeclaration.getAttributes();
+ String model = attributes.get("model");
+
+ loadedResolvers.put(model, modelResolverDeclaration);
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java
new file mode 100644
index 0000000000..de54d54f94
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ExtensibleModelResolver.java
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.resolver;
+
+import java.lang.reflect.Constructor;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.assembly.Base;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+
+/**
+ * An implementation of an extensible model resolver which delegates to the
+ * proper resolver extension based on the class of the model to resolve.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ExtensibleModelResolver implements ModelResolver {
+ private final ModelResolverExtensionPoint resolverExtensions;
+ private final ModelFactoryExtensionPoint modelFactories;
+ private final Contribution contribution;
+ private ModelResolver defaultResolver;
+ private final Map<Class<?>, ModelResolver> resolversByModelType = new HashMap<Class<?>, ModelResolver>();
+ private final Map<Class<?>, ModelResolver> resolversByImplementationClass = new HashMap<Class<?>, ModelResolver>();
+ private Map<Object, Object> map = new HashMap<Object, Object>();
+ private Object lastUnresolved;
+
+ /**
+ * Constructs an extensible model resolver
+ *
+ * @param contribution
+ * @param resolverExtensions
+ * @param modelFactories
+ * @param defaultResolver
+ */
+ @Deprecated
+ public ExtensibleModelResolver(Contribution contribution,
+ ModelResolverExtensionPoint resolverExtensions,
+ ModelFactoryExtensionPoint modelFactories,
+ ModelResolver defaultResolver) {
+ this.contribution = contribution;
+ this.resolverExtensions = resolverExtensions;
+ this.modelFactories = modelFactories;
+ //FIXME Remove this default resolver, this is currently used to resolve policy declarations
+ // but they should be handled by the contribution import/export mechanism instead of this
+ // defaultResolver hack.
+ this.defaultResolver = defaultResolver;
+ }
+
+ /**
+ * Constructs an extensible model resolver
+ *
+ * @param resolverExtensions
+ * @param contribution
+ * @param modelFactories
+ */
+ public ExtensibleModelResolver(Contribution contribution,
+ ModelResolverExtensionPoint resolverExtensions,
+ ModelFactoryExtensionPoint modelFactories) {
+ this.contribution = contribution;
+ this.resolverExtensions = resolverExtensions;
+ this.modelFactories = modelFactories;
+ }
+
+ /**
+ * Returns the proper resolver instance based on the interfaces of the model
+ * If one is not available on the registry, instantiate on demand
+ *
+ * @param modelType
+ * @return
+ */
+ private ModelResolver getModelResolverInstance(Class<?> modelType) {
+ // Look up a model resolver instance for the model class or
+ // each implemented interface
+ Class<?>[] interfaces = modelType.getInterfaces();
+ Class<?>[] classes = new Class<?>[interfaces.length + 1];
+ classes[0] = modelType;
+ if (interfaces.length != 0) {
+ System.arraycopy(interfaces, 0, classes, 1, interfaces.length);
+ }
+ for (Class<?> c : classes) {
+
+ // Look up an existing model resolver instance
+ ModelResolver resolverInstance = resolversByModelType.get(c);
+ if (resolverInstance != null) {
+ return resolverInstance;
+ }
+
+ // We don't have an instance, lookup a model resolver class
+ // and instantiate it
+ Class<? extends ModelResolver> resolverClass = resolverExtensions.getResolver(c);
+ if (resolverClass != null) {
+
+ // Construct the model resolver instance and cache it
+ resolverInstance = resolversByImplementationClass.get(resolverClass);
+ if (resolverInstance != null) {
+ resolversByModelType.put(c, resolverInstance);
+ return resolverInstance;
+ }
+ try {
+ Constructor<? extends ModelResolver> constructor =
+ resolverClass
+ .getConstructor(new Class[] {Contribution.class, ModelFactoryExtensionPoint.class});
+ if (constructor != null) {
+
+ resolverInstance = constructor.newInstance(contribution, modelFactories);
+ resolversByImplementationClass.put(resolverClass, resolverInstance);
+ resolversByModelType.put(c, resolverInstance);
+ return resolverInstance;
+ }
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ }
+
+ return null;
+ }
+
+ public void addModel(Object resolved) {
+ ModelResolver resolver = getModelResolverInstance(resolved.getClass());
+ if (resolver != null) {
+ resolver.addModel(resolved);
+ } else {
+ map.put(resolved, resolved);
+ }
+ }
+
+ public Object removeModel(Object resolved) {
+ ModelResolver resolver = getModelResolverInstance(resolved.getClass());
+ if (resolver != null) {
+ return resolver.removeModel(resolved);
+ } else {
+ return map.remove(resolved);
+ }
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ // Protect against dependency cycles causing infinite recursion
+ // Save the current unresolved object and check later if we are trying
+ // to resolve the same object again
+ if (unresolved == lastUnresolved) {
+ return unresolved;
+ }
+ lastUnresolved = unresolved;
+
+ ModelResolver resolver = getModelResolverInstance(unresolved.getClass());
+ if (resolver != null) {
+ Object resolved = resolver.resolveModel(modelClass, unresolved);
+ if (resolved != null && resolved != unresolved) {
+ lastUnresolved = null;
+ return modelClass.cast(resolved);
+ }
+ } else {
+ //FIXME Remove this default resolver, this is currently used to resolve policy declarations
+ // but they should be handled by the contribution import/export mechanism instead of this
+ // defaultResolver hack.
+ if (defaultResolver != null) {
+ Object resolved = defaultResolver.resolveModel(modelClass, unresolved);
+ if (resolved != null && resolved != unresolved) {
+ lastUnresolved = null;
+ return modelClass.cast(resolved);
+ }
+ }
+
+ Object resolved = map.get(unresolved);
+ if (resolved != null) {
+ // Return the resolved object
+ lastUnresolved = null;
+ return modelClass.cast(resolved);
+ }
+ }
+
+ return unresolved;
+ }
+
+ // FIXME: TUSCANY-2499: temporarily give access to the defaultResolver to get the jms binding
+ // use of definitions.xml working while the definitions.xml processing is being refactored
+ public ModelResolver getDefaultModelResolver() {
+ return defaultResolver;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.java
new file mode 100644
index 0000000000..2831bebbc4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolver.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.resolver;
+
+/**
+ * A model resolver, responsible for resolving models in the scope of an
+ * SCA contribution.
+ *
+ * SCA Assemblies reference artifacts of a wide variety of types. These
+ * include:
+ * <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 logical URIs. Model resolvers are used to resolve these references
+ * and get the in-memory models representing the referenced artifacts.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ModelResolver {
+
+ /**
+ * Resolve the model representing an artifact.
+ *
+ * @param modelClass the type of artifact
+ * @param unresolved the unresolved model
+ * @return the resolved model
+ */
+ <T> T resolveModel(Class<T> modelClass, T unresolved);
+
+ /**
+ * Add a resolved model.
+ *
+ * @param resolved The model
+ */
+ void addModel(Object resolved);
+
+ /**
+ * Remove a resolved model.
+ *
+ * @param resolved
+ * @return The removed model, or null if the model was not removed
+ */
+ Object removeModel(Object resolved);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolverExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolverExtensionPoint.java
new file mode 100644
index 0000000000..4a25059792
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ModelResolverExtensionPoint.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.resolver;
+
+
+/**
+ * An extension point for model resolvers
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ModelResolverExtensionPoint {
+
+ /**
+ * Register a model resolver class using the model type as the key
+ *
+ * @param modelType The model type
+ * @param resolver The model resolver Class
+ */
+ void addResolver(Class<?> modelType, Class <? extends ModelResolver> resolver);
+
+ /**
+ * Remove the model resolver class for a specific model type
+ *
+ * @param modelType The model type
+ */
+ void removeResolver(Class<?> modelType);
+
+ /**
+ * Retrieve a model resolver class for a specific model type
+ *
+ * @param modelType The model artifact type
+ * @return The model resolver Class
+ */
+ Class <? extends ModelResolver> getResolver(Class<?> modelType);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ResolverExtension.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ResolverExtension.java
new file mode 100644
index 0000000000..74f0f2d71d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ResolverExtension.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.resolver;
+
+/**
+ * Extension to assembly model implementations to provide a model resolver.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ResolverExtension {
+
+ /**
+ * Returns the model resolver for the models representing the artifacts
+ * visible in the scope of this contribution.
+ *
+ * @return The model resolver
+ */
+ ModelResolver getModelResolver();
+
+ /**
+ * Sets the model resolver for the models representing the artifacts
+ * visible in the scope of this contribution.
+ *
+ * @param modelResolver The model resolver
+ */
+ void setModelResolver(ModelResolver modelResolver);
+
+} \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ResourceReference.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ResourceReference.java
new file mode 100644
index 0000000000..2394f4510b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/resolver/ResourceReference.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.resolver;
+
+import java.net.URL;
+
+/**
+ * A resource URL, which should be used to register resources
+ * with an ArtifactResolver and resolve these resources later.
+ *
+ * FIXME Don't use as its deprecated, use Artifact instead.
+ *
+ * @version $Rev$ $Date$
+ */
+@Deprecated
+public class ResourceReference {
+
+ private URL resourceURL;
+ private String resourceName;
+
+ /**
+ * Constructs a new ResourceReference.
+ *
+ * @param resourceName Name of resource
+ * @param resourceURL The resource URL
+ */
+ public ResourceReference(String resourceName, URL resourceURL) {
+ this.resourceURL = resourceURL;
+ this.resourceName = resourceName;
+ }
+
+ /**
+ * Constructs a new ResourceReference.
+ *
+ * @param resourceName Name of resource
+ */
+ public ResourceReference(String resourceName) {
+ this.resourceName = resourceName;
+ }
+
+ /**
+ * Get the resource URL.
+ *
+ * @return The resource URL
+ */
+ public URL getResource() {
+ return resourceURL;
+ }
+
+ /**
+ * Get the resource name.
+ *
+ * @return The resource name
+ */
+ public String getResourceName() {
+ return resourceName;
+ }
+
+ /**
+ * Returns true if the resource reference is unresolved.
+ *
+ * @return Whether or not the resource has been resolved
+ */
+ public boolean isUnresolved() {
+ return resourceURL == null;
+ }
+
+ @Override
+ public int hashCode() {
+ return resourceName.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ } else {
+ if (obj instanceof ResourceReference) {
+ return resourceName.equals(((ResourceReference)obj).resourceName);
+ } else {
+ return false;
+ }
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScanner.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScanner.java
new file mode 100644
index 0000000000..2d03381c8a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScanner.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.scanner;
+
+import java.net.URL;
+import java.util.List;
+
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+
+/**
+ * Interface for contribution package scanners
+ *
+ * Contribution scanners understand the format of the contribution and how to get the
+ * artifacts in the contribution.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ContributionScanner {
+
+ /**
+ * Returns the type of package supported by this package scanner.
+ *
+ * @return the package type
+ */
+ String getContributionType();
+
+ /**
+ * Returns a list of artifacts in the contribution.
+ *
+ * @param contributionURL Contribution URL
+ * @return List of artifact URIs
+ * @throws ContributionException
+ * @throws IOException
+ */
+ List<String> getArtifacts(URL contributionURL) throws ContributionReadException;
+
+ /**
+ * Return the URL for an artifact in the contribution.
+ *
+ * This is needed for archives such as jar files that have specific URL schemes
+ * for the artifacts they contain.
+ *
+ * @param contributionURL Contribution URL
+ * @param artifact The relative URI for the artifact
+ * @return The artifact URL
+ */
+ URL getArtifactURL(URL contributionURL, String artifact) throws ContributionReadException;
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScannerExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScannerExtensionPoint.java
new file mode 100644
index 0000000000..1ca9def4ea
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/ContributionScannerExtensionPoint.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.scanner;
+
+/**
+ * An extension point for contribution scanners
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ContributionScannerExtensionPoint {
+
+ /**
+ * Add a ContributionScanner using the contribution type as the key.
+ *
+ * @param scanner The contribution scanner
+ */
+ void addContributionScanner(ContributionScanner scanner);
+
+ /**
+ * Remove a ContributionScanner.
+ *
+ * @param scanner The contribution scanner
+ */
+ void removeContributionScanner(ContributionScanner scanner);
+
+ /**
+ * Returns the ContributionScanner for the given contribution type.
+ *
+ * @param contributionType The contribution type
+ * @return The contribution scanner
+ */
+ ContributionScanner getContributionScanner(String contributionType);
+
+} \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/DefaultContributionScannerExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/DefaultContributionScannerExtensionPoint.java
new file mode 100644
index 0000000000..24aae45b59
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/scanner/DefaultContributionScannerExtensionPoint.java
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.scanner;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+
+/**
+ * Default implementation of a contribution scanner extension point.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultContributionScannerExtensionPoint implements ContributionScannerExtensionPoint {
+
+ private Map<String, ContributionScanner> scanners = new HashMap<String, ContributionScanner>();
+ private boolean loaded;
+
+ public DefaultContributionScannerExtensionPoint() {
+ }
+
+ public void addContributionScanner(ContributionScanner scanner) {
+ scanners.put(scanner.getContributionType(), scanner);
+ }
+
+ public void removeContributionScanner(ContributionScanner scanner) {
+ scanners.remove(scanner.getContributionType());
+ }
+
+ public ContributionScanner getContributionScanner(String contentType) {
+ loadScanners();
+ return scanners.get(contentType);
+ }
+
+ private void loadScanners() {
+ if (loaded)
+ return;
+
+ // Get the scanner service declarations
+ Set<ServiceDeclaration> scannerDeclarations;
+ try {
+ scannerDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(ContributionScanner.class);
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+
+ for (ServiceDeclaration scannerDeclaration: scannerDeclarations) {
+ Map<String, String> attributes = scannerDeclaration.getAttributes();
+
+ // Load a URL artifact scanner
+ String contributionType = attributes.get("type");
+
+ // Create a scanner wrapper and register it
+ ContributionScanner scanner = new LazyContributionScanner(contributionType, scannerDeclaration);
+ addContributionScanner(scanner);
+ }
+
+ loaded = true;
+ }
+
+ /**
+ * A facade for contribution scanners.
+ */
+ private static class LazyContributionScanner implements ContributionScanner {
+
+ private ServiceDeclaration scannerDeclaration;
+ private String contributionType;
+ private ContributionScanner scanner;
+
+ private LazyContributionScanner(String contributionType, ServiceDeclaration scannerDeclaration) {
+ this.scannerDeclaration = scannerDeclaration;
+ this.contributionType = contributionType;
+ }
+
+ public URL getArtifactURL(URL contributionSourceURL, String artifact) throws ContributionReadException {
+ return getScanner().getArtifactURL(contributionSourceURL, artifact);
+ }
+
+ public List<String> getArtifacts(URL contributionSourceURL) throws ContributionReadException {
+ return getScanner().getArtifacts(contributionSourceURL);
+ }
+
+ public String getContributionType() {
+ return contributionType;
+ }
+
+ private ContributionScanner getScanner() {
+ if (scanner == null) {
+ try {
+ Class<ContributionScanner> scannerClass = (Class<ContributionScanner>)scannerDeclaration.loadClass();
+ Constructor<ContributionScanner> constructor = scannerClass.getConstructor();
+ scanner = constructor.newInstance();
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return scanner;
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionException.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionException.java
new file mode 100644
index 0000000000..e183206894
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionException.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.service;
+
+/**
+ * Base class for exceptions raised by contribution services.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ContributionException extends Exception {
+
+ private static final long serialVersionUID = 4432880414927652578L;
+
+ protected ContributionException() {
+ super();
+ }
+
+ protected ContributionException(String message) {
+ super(message);
+ }
+
+ protected ContributionException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ContributionException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionListener.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionListener.java
new file mode 100644
index 0000000000..5158eaf85c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionListener.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.service;
+
+import java.util.EventListener;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+
+/**
+ * A listener interface used to listen to contribution repository events.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ContributionListener extends EventListener {
+
+ /**
+ * Notifies the listener that a contribution has been added.
+ *
+ * @param repository The contribution repository
+ * @param contribution The new contribution
+ */
+ void contributionAdded(ContributionRepository repository, Contribution contribution);
+
+ /**
+ * Notifies the listener that a contribution has been removed.
+ *
+ * @param repository The contribution repository
+ * @param contribution The removed contribution.
+ */
+ void contributionRemoved(ContributionRepository repository, Contribution contribution);
+
+ /**
+ * Notifies the listener that a contribution has been updated.
+ *
+ * @param repository The contribution repository
+ * @param oldContribution The old contribution
+ * @param contribution The new contribution
+ */
+ void contributionUpdated(ContributionRepository repository, Contribution oldContribution, Contribution contribution);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionListenerExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionListenerExtensionPoint.java
new file mode 100644
index 0000000000..ce2b4b13c3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionListenerExtensionPoint.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.service;
+
+import java.util.List;
+
+public interface ContributionListenerExtensionPoint {
+
+ /**
+ * Adds a contribution repository listener extension.
+ * @param listener The listener to add
+ */
+ void addContributionListener(ContributionListener listener);
+
+ /**
+ * Removes a contribution repository listener extension.
+ * @param listener The listener to remove
+ */
+ void removeContributionListener(ContributionListener listener);
+
+ /**
+ * Returns the contribution repository listeners.
+ * @return
+ */
+ List<ContributionListener> getContributionListeners();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionReadException.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionReadException.java
new file mode 100644
index 0000000000..33399dcc2f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionReadException.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.service;
+
+/**
+ * Denotes an exception while reading artifacts inside an SCA contribution.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ContributionReadException extends ContributionException {
+ public static final int UNDEFINED = -1;
+ private static final long serialVersionUID = -7459051598906813461L;
+ private String resourceURI;
+ private int line = UNDEFINED;
+ private int column = UNDEFINED;
+
+ public ContributionReadException(String message) {
+ super(message);
+ }
+
+ public ContributionReadException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ContributionReadException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Returns the location of the resource that was being read.
+ *
+ * @return the location of the resource that was being read
+ */
+ public String getResourceURI() {
+ return resourceURI;
+ }
+
+ /**
+ * Sets the location of the resource that was being read.
+ *
+ * @param resourceURI the location of the resource that was being read
+ */
+ public void setResourceURI(String resourceURI) {
+ this.resourceURI = resourceURI;
+ }
+
+ /**
+ * Returns the line inside the resource that was being read.
+ * @return the line inside the resource that was being read
+ */
+ public int getLine() {
+ return line;
+ }
+
+ /**
+ * Sets the line inside the resource that was being read.
+ * @param line the line inside the resource that was being read
+ */
+ public void setLine(int line) {
+ this.line = line;
+ }
+
+ /**
+ * Returns the column inside the resource that was being read.
+ * @return the column inside the resource that was being read
+ */
+ public int getColumn() {
+ return column;
+ }
+
+ /**
+ * Sets the column inside the resource that was being read.
+ * @param column the column inside the resource that was being read
+ */
+ public void setColumn(int column) {
+ this.column = column;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRepository.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRepository.java
new file mode 100644
index 0000000000..d7d8216f66
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRepository.java
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.service;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+import java.util.List;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+
+/**
+ * Contribution repository
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ContributionRepository {
+
+ /**
+ * Get the URI of the SCA domain
+ *
+ * @return The domain URI
+ */
+ URI getDomain();
+
+ /**
+ * Copies a contribution to the repository.
+ *
+ * @param contribution A URl pointing to the contribution being copied to
+ * the repository
+ * @param sourceURL URL of the source. this would be used to calculate the right
+ * filename to be stored on the repository when a inputStream is being
+ * provided
+ * @param contributionStream InputStream with the content of the
+ * distribution
+ * @return A URL pointing to the content of the contribution in the
+ * repository
+ * @throws IOException
+ */
+ URL store(String contribution, URL sourceURL, InputStream contributionStream) throws IOException;
+ /**
+ * Copy a contribution from the source URL to the repository
+ *
+ * @param contribution A URl pointing to the contribution being copied to
+ * the repository
+ * @param sourceURL URL of the source. this would be used to calculate the right
+ * filename to be stored on the repository when a inputStream is being
+ * provided
+ * @return A URL pointing to the content of the contribution in the
+ * repository
+ * @throws IOException
+ */
+ URL store(String contribution, URL sourceURL) throws IOException;
+
+ /**
+ * Look up the contribution by URI
+ *
+ * @param contribution The URI of the contribution
+ * @return A URL pointing to the content of the contribution in the
+ * repository, it will be null if the contribution cannot be found
+ * in the repository
+ */
+ URL find(String contribution);
+
+ /**
+ * Remove a contribution from the repository
+ *
+ * @param contribution The URI of the contribution to be removed
+ */
+ void remove(String contribution);
+
+ /**
+ * Get list of URIs for all the contributions in the repository
+ *
+ * @return A list of contribution URIs
+ */
+ List<String> list();
+
+ /**
+ * Returns the contributions available in the repository.
+ * @return The list of contributions.
+ */
+ List<Contribution> getContributions();
+
+ /**
+ * Adds a contribution to the repository.
+ * @param contribution The new contribution.
+ */
+ void addContribution(Contribution contribution);
+
+ /**
+ * Removes a contribution from the repository.
+ * @param contribution The contribution to remove
+ */
+ void removeContribution(Contribution contribution);
+
+ /**
+ * Updates a contribution in the repository
+ * @param contribution The contribution to update
+ */
+ void updateContribution(Contribution contribution);
+
+ /**
+ * Returns the contribution with the given URI.
+ * @param uri the URI of the contribution
+ * @return The contribution
+ */
+ Contribution getContribution(String uri);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionResolveException.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionResolveException.java
new file mode 100644
index 0000000000..ecb774ac0c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionResolveException.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.service;
+
+/**
+ * Denotes a problem while resolving models inside an SCA contribution.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ContributionResolveException extends ContributionException {
+ private static final long serialVersionUID = -7459051598906813461L;
+
+ public ContributionResolveException(String message) {
+ super(message);
+ }
+
+ public ContributionResolveException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ContributionResolveException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRuntimeException.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRuntimeException.java
new file mode 100644
index 0000000000..4bf29a3993
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionRuntimeException.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.service;
+
+/**
+ * Base class for runtime exceptions raised by contribution services.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ContributionRuntimeException extends RuntimeException {
+ private static final long serialVersionUID = 7711215366287498896L;
+
+ protected ContributionRuntimeException() {
+ super();
+ }
+
+ protected ContributionRuntimeException(String message) {
+ super(message);
+ }
+
+ protected ContributionRuntimeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ContributionRuntimeException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionService.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionService.java
new file mode 100644
index 0000000000..dcdb8733b8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionService.java
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.service;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+/**
+ * Service interface that manages artifacts contributed to a Tuscany runtime.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ContributionService {
+ /**
+ * Contribute an artifact to the SCA Domain. The type of the contribution is
+ * determined by the Content-Type of the resource or, if that is undefined,
+ * by some implementation-specific means (such as mapping an extension in
+ * the URL's path).
+ *
+ * @param contributionURI The URI that is used as the contribution unique ID.
+ * @param sourceURL The location of the resource containing the artifact
+ * @param storeInRepository Flag that identifies if you want to copy the
+ * contribution to the repository
+ * @return The contribution model representing the contribution
+ * @throws ContributionException if there was a problem with the contribution
+ * @throws IOException if there was a problem reading the resource
+ */
+ Contribution contribute(String contributionURI, URL sourceURL, boolean storeInRepository) throws ContributionException,
+ IOException;
+
+ /**
+ * Contribute an artifact to the SCA Domain. The type of the contribution is
+ * determined by the Content-Type of the resource or, if that is undefined,
+ * by some implementation-specific means (such as mapping an extension in
+ * the URL's path).
+ *
+ * @param contributionURI The URI that is used as the contribution unique ID.
+ * @param sourceURL The location of the resource containing the artifact
+ * @param modelResolver The model resolver to use to resolve models in the
+ * scope of this contribution
+ * @param storeInRepository Flag that identifies if you want to copy the
+ * contribution to the repository
+ * @return The contribution model representing the contribution
+ * @throws ContributionException if there was a problem with the contribution
+ * @throws IOException if there was a problem reading the resource
+ */
+ Contribution contribute(String contributionURI, URL sourceURL, ModelResolver modelResolver, boolean storeInRepository) throws ContributionException,
+ IOException;
+
+ /**
+ * Contribute an artifact to the SCA Domain.
+ *
+ * @param contributionURI The URI that is used as the contribution unique ID.
+ * @param sourceURL The location of the resource containing the artifact.
+ * This is used to identify what name should be used when storing
+ * the contribution on the repository
+ * @param contributionContent A stream containing the resource being
+ * contributed; the stream will not be closed but the read
+ * position after the call is undefined
+ * @return The contribution model representing the contribution
+ * @throws ContributionException if there was a problem with the contribution
+ * @throws IOException if there was a problem reading the stream
+ */
+ Contribution contribute(String contributionURI, URL sourceURL, InputStream contributionContent)
+ throws ContributionException, IOException;
+
+ /**
+ * Contribute an artifact to the SCA Domain.
+ *
+ * @param contributionURI The URI that is used as the contribution unique ID.
+ * @param sourceURL The location of the resource containing the artifact.
+ * This is used to identify what name should be used when storing
+ * the contribution on the repository
+ * @param modelResolver The model resolver to use to resolve models in the
+ * scope of this contribution
+ * @param contributionContent A stream containing the resource being
+ * contributed; the stream will not be closed but the read
+ * position after the call is undefined
+ * @return The contribution model representing the contribution
+ * @throws ContributionException if there was a problem with the contribution
+ * @throws IOException if there was a problem reading the stream
+ */
+ Contribution contribute(String contributionURI, URL sourceURL, InputStream contributionContent, ModelResolver modelResolver)
+ throws ContributionException, IOException;
+
+ /**
+ * Get the model for an installed contribution
+ *
+ * @param contribution The URI of an installed contribution
+ * @return The model for the contribution or null if there is no such
+ * contribution
+ */
+ Contribution getContribution(String contribution);
+
+ /**
+ * Adds or updates a deployment composite using a supplied composite
+ * ("composite by value" - a data structure, not an existing resource in the
+ * domain) to the contribution identified by a supplied contribution URI.
+ * The added or updated deployment composite is given a relative URI that
+ * matches the "name" attribute of the composite, with a ".composite"
+ * suffix.
+ *
+ * @param contribution The contribution to where
+ * @param composite
+ * @throws ContributionException
+ */
+ void addDeploymentComposite(Contribution contribution, Composite composite) throws ContributionException;
+
+ /**
+ * Remove a contribution from the SCA domain
+ *
+ * @param contribution The URI of the contribution
+ * @throws DeploymentException
+ */
+ void remove(String contribution) throws ContributionException;
+} \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionWriteException.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionWriteException.java
new file mode 100644
index 0000000000..8bfdedf180
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ContributionWriteException.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.service;
+
+
+/**
+ * Denotes an exception while writing artifacts inside an SCA contribution.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ContributionWriteException extends ContributionException {
+ private static final long serialVersionUID = -7459051598906813461L;
+ private String resourceURI;
+
+ public ContributionWriteException(String message) {
+ super(message);
+ }
+
+ public ContributionWriteException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ContributionWriteException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Returns the location of the resource that was being written.
+ *
+ * @return the location of the resource that was being written
+ */
+ public String getResourceURI() {
+ return resourceURI;
+ }
+
+ /**
+ * Sets the location of the resource that was being written.
+ *
+ * @param resourceURI the location of the resource that was being written
+ */
+ public void setResourceURI(String resourceURI) {
+ this.resourceURI = resourceURI;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/DefaultContributionListenerExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/DefaultContributionListenerExtensionPoint.java
new file mode 100644
index 0000000000..1ab80e344b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/DefaultContributionListenerExtensionPoint.java
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.service;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+
+/**
+ * Default implementation of a contribution listener extension point.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultContributionListenerExtensionPoint implements ContributionListenerExtensionPoint {
+
+ private List<ContributionListener> listeners = new CopyOnWriteArrayList<ContributionListener>();
+ private boolean loadedListeners;
+ private ModelFactoryExtensionPoint modelFactories;
+
+ /**
+ * Constructs a new DefaultContributionListenerExtensionPoint.
+ *
+ */
+ public DefaultContributionListenerExtensionPoint(ModelFactoryExtensionPoint modelFactories) {
+ this.modelFactories = modelFactories;
+ }
+
+ /**
+ * Constructs a new DefaultContributionListenerExtensionPoint.
+ *
+ */
+ public DefaultContributionListenerExtensionPoint(ExtensionPointRegistry extensionPoints) {
+ this.modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ }
+
+ public void addContributionListener(ContributionListener listener) {
+ listeners.add(listener);
+ }
+
+ public List<ContributionListener> getContributionListeners() {
+ loadListeners();
+ return listeners;
+ }
+
+ public void removeContributionListener(ContributionListener listener) {
+ listeners.remove(listener);
+ }
+
+ /**
+ * Dynamically load listeners declared under META-INF/services
+ */
+ @SuppressWarnings("unchecked")
+ private synchronized void loadListeners() {
+ if (loadedListeners)
+ return;
+
+ // Get the listener service declarations
+ Set<ServiceDeclaration> listenerDeclarations;
+ try {
+ listenerDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(ContributionListener.class);
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+
+ // Load and instantiate the listeners
+ for (ServiceDeclaration listenerDeclaration: listenerDeclarations) {
+ ContributionListener listener;
+ try {
+ Class<ContributionListener> listenerClass = (Class<ContributionListener>)listenerDeclaration.loadClass();
+ try {
+ Constructor<ContributionListener> constructor = listenerClass.getConstructor(ModelFactoryExtensionPoint.class);
+ try {
+ listener = constructor.newInstance(modelFactories);
+ } catch (InvocationTargetException e) {
+ throw new IllegalArgumentException(e);
+ }
+ } catch (NoSuchMethodException e) {
+ listener = listenerClass.newInstance();
+ }
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException(e);
+ } catch (InstantiationException e) {
+ throw new IllegalArgumentException(e);
+ } catch (IllegalAccessException e) {
+ throw new IllegalArgumentException(e);
+ }
+ addContributionListener(listener);
+ }
+
+ loadedListeners = true;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ExtensibleContributionListener.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ExtensibleContributionListener.java
new file mode 100644
index 0000000000..fc0dc3aa99
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/ExtensibleContributionListener.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.service;
+
+import org.apache.tuscany.sca.contribution.Contribution;
+
+public class ExtensibleContributionListener implements ContributionListener {
+ private final ContributionListenerExtensionPoint listeners;
+
+ /**
+ * Default constructor receiving the listener extension point
+ *
+ * @param listeners
+ */
+ public ExtensibleContributionListener(ContributionListenerExtensionPoint listeners) {
+ this.listeners = listeners;
+ }
+
+ /**
+ * Process "contributionAdded" event to all registered listeners
+ */
+ public void contributionAdded(ContributionRepository repository, Contribution contribution) {
+ for (ContributionListener listener : listeners.getContributionListeners()) {
+ try {
+ listener.contributionAdded(repository, contribution);
+ } catch (Exception e) {
+ // ignore, continue to the next listener
+ }
+ }
+ }
+
+ /**
+ * Process "contributionRemoved" event to all registered listeners
+ */
+ public void contributionRemoved(ContributionRepository repository, Contribution contribution) {
+ for (ContributionListener listener : listeners.getContributionListeners()) {
+ try {
+ listener.contributionRemoved(repository, contribution);
+ } catch (Exception e) {
+ // ignore, continue to the next listener
+ }
+
+ }
+ }
+
+ /**
+ * Process "contributionUpdated" event to all registered listeners
+ */
+ public void contributionUpdated(ContributionRepository repository, Contribution oldContribution, Contribution contribution) {
+ for (ContributionListener listener : listeners.getContributionListeners()) {
+ try {
+ listener.contributionUpdated(repository, oldContribution, contribution);
+ } catch (Exception e) {
+ // ignore, continue to the next listener
+ }
+
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/TypeDescriber.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/TypeDescriber.java
new file mode 100644
index 0000000000..74f303a5a5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/TypeDescriber.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.contribution.service;
+
+import java.net.URL;
+
+/**
+ * Provide content type for a given resource
+ *
+ * @version $Rev$ $Date$
+ */
+public interface TypeDescriber {
+ /**
+ * Get the content type for the specified resource
+ *
+ * @param resourceURL The resource URL
+ * @param defaultType The default content type
+ * @return The content type
+ */
+ String getType(URL resourceURL, String defaultType);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnrecognizedElementException.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnrecognizedElementException.java
new file mode 100644
index 0000000000..ff21c894de
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnrecognizedElementException.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.service;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Exception that indicates an element was encountered that could not be handled.
+ *
+ * @version $Rev$ $Date$
+ */
+public class UnrecognizedElementException extends ContributionReadException {
+ private static final long serialVersionUID = 2549543622209829032L;
+ private final QName element;
+
+ /**
+ * Constructor that indicates which element could not be handled.
+ * @param element the element that could not be handled
+ */
+ public UnrecognizedElementException(QName element) {
+ super("Unrecognized element: " + element);
+ this.element = element;
+ }
+
+ /**
+ * Returns the element that could not be handled.
+ * @return the element that could not be handled.
+ */
+ public QName getElement() {
+ return element;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedContentTypeException.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedContentTypeException.java
new file mode 100644
index 0000000000..0660d69897
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedContentTypeException.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.service;
+
+/**
+ * Exception thrown to indicate that a Content-Type is not supported by this SCA Domain.
+ * The Content-Type value supplied will be returned as the message text for this exception.
+ *
+ * FIXME Don't use as it's deprecated and replaced by UnsupportedPackageTypeException.
+ *
+ * @version $Rev$ $Date$
+ */
+@Deprecated
+public class UnsupportedContentTypeException extends ContributionException {
+ private static final long serialVersionUID = -1831797280021355672L;
+
+ /**
+ * Constructs a new UnsupportedContentTypeException.
+ *
+ * @param message
+ */
+ public UnsupportedContentTypeException(String message) {
+ super(message);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedPackageTypeException.java b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedPackageTypeException.java
new file mode 100644
index 0000000000..33c847a049
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/service/UnsupportedPackageTypeException.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.contribution.service;
+
+/**
+ * Exception thrown to indicate that a Content-Type is not supported by this SCA Domain.
+ * The Content-Type value supplied will be returned as the message text for this exception.
+ *
+ * @version $Rev$ $Date$
+ */
+public class UnsupportedPackageTypeException extends ContributionException {
+ private static final long serialVersionUID = -1831797280021355672L;
+
+ /**
+ * Constructs a new UnsupportedPackageTypeException.
+ *
+ * @param message
+ */
+ public UnsupportedPackageTypeException(String message) {
+ super(message);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.ContributionFactory b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.ContributionFactory
new file mode 100644
index 0000000000..bcc346d9f8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.ContributionFactory
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.contribution.DefaultContributionFactory \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint
new file mode 100644
index 0000000000..6b4d2ebdeb
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.contribution.DefaultModelFactoryExtensionPoint
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ContributionPostProcessorExtensionPoint b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ContributionPostProcessorExtensionPoint
new file mode 100644
index 0000000000..9e6433ba6c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ContributionPostProcessorExtensionPoint
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.contribution.processor.DefaultContributionPostProcessorExtensionPoint
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessorExtensionPoint b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessorExtensionPoint
new file mode 100644
index 0000000000..7609eda0d1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.PackageProcessorExtensionPoint
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.contribution.processor.DefaultPackageProcessorExtensionPoint
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint
new file mode 100644
index 0000000000..8ea5fc0a7e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint
new file mode 100644
index 0000000000..607725bcfe
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessorExtensionPoint
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.contribution.processor.DefaultStAXAttributeProcessorExtensionPoint
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint
new file mode 100644
index 0000000000..9d78ca93d0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.contribution.processor.DefaultURLArtifactProcessorExtensionPoint
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint
new file mode 100644
index 0000000000..ae6e876df6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.contribution.processor.DefaultValidationSchemaExtensionPoint
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint
new file mode 100644
index 0000000000..4bb65e55e7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.contribution.resolver.DefaultModelResolverExtensionPoint
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.scanner.ContributionScannerExtensionPoint b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.scanner.ContributionScannerExtensionPoint
new file mode 100644
index 0000000000..727f8f6ce7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.scanner.ContributionScannerExtensionPoint
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.contribution.scanner.DefaultContributionScannerExtensionPoint
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListenerExtensionPoint b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListenerExtensionPoint
new file mode 100644
index 0000000000..6e61bebf79
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.service.ContributionListenerExtensionPoint
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.contribution.service.DefaultContributionListenerExtensionPoint
diff --git a/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/contribution-validation-messages.properties b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/contribution-validation-messages.properties
new file mode 100644
index 0000000000..bd650fe457
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/contribution/src/main/resources/contribution-validation-messages.properties
@@ -0,0 +1,31 @@
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+SchemaError = XMLSchema validation error occured in: {0} ,line = {1}, column = {2}, Message = {3}
+SchemaFatalError = XMLSchema validation fatal error occured in: {0} ,line = {1}, column = {2}, Message = {3}
+SchemaWarning = XMLSchema validation warning occured in: {0} ,line = {1}, column = {2}, Message = {3}
+UnsupportedPackageTypeException = Unsupported contribution package type: {0}
+ElementCannotBeProcessed = Element {0} cannot be processed. ({1})
+NoStaxProcessor = No StAX processor is configured to handle {0}
+ContributionWriteException = ContributionWriteException occured due to :
+ContributionReadException = ContributionReadException occured due to :
+UnrecognizedElementException = Unrecognized Element : {0}
+IllegalArgumentException = Invalid qname: {0}
+PrivilegedActionException = PrivilegedActionException occured due to :
diff --git a/sca-java-1.x/branches/sca-android/modules/core-databinding/LICENSE b/sca-java-1.x/branches/sca-android/modules/core-databinding/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-databinding/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/core-databinding/META-INF/README b/sca-java-1.x/branches/sca-android/modules/core-databinding/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-databinding/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/core-databinding/NOTICE b/sca-java-1.x/branches/sca-android/modules/core-databinding/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-databinding/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/core-databinding/pom.xml b/sca-java-1.x/branches/sca-android/modules/core-databinding/pom.xml
new file mode 100644
index 0000000000..cb88bcd176
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-databinding/pom.xml
@@ -0,0 +1,108 @@
+<?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>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core-databinding</artifactId>
+ <packaging>jar</packaging>
+ <name>Apache Tuscany SCA Core/DataBinding Integration</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-databinding</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-databinding-jaxb</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core-spi</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-interface-java-xml</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-interface-java-jaxws</artifactId>
+ <version>${project.version}</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ <scope>runtime</scope>
+ <version>3.2.1</version>
+ <exclusions>
+ <exclusion>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.core.databinding</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.core.databinding*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java
new file mode 100644
index 0000000000..2056789089
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/module/DataBindingModuleActivator.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.databinding.module;
+
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ModuleActivator;
+import org.apache.tuscany.sca.core.databinding.processor.DataBindingJavaInterfaceProcessor;
+import org.apache.tuscany.sca.core.databinding.transformers.Array2ArrayTransformer;
+import org.apache.tuscany.sca.core.databinding.transformers.CallableReference2XMLStreamReader;
+import org.apache.tuscany.sca.core.databinding.transformers.CallableReferenceDataBinding;
+import org.apache.tuscany.sca.core.databinding.transformers.CallableReferenceXMLAdapter;
+import org.apache.tuscany.sca.core.databinding.transformers.Exception2ExceptionTransformer;
+import org.apache.tuscany.sca.core.databinding.transformers.Input2InputTransformer;
+import org.apache.tuscany.sca.core.databinding.transformers.Output2OutputTransformer;
+import org.apache.tuscany.sca.core.databinding.transformers.XMLStreamReader2CallableReference;
+import org.apache.tuscany.sca.core.databinding.wire.DataBindingRuntimeWireProcessor;
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.databinding.TransformerExtensionPoint;
+import org.apache.tuscany.sca.databinding.impl.Group2GroupTransformer;
+import org.apache.tuscany.sca.databinding.impl.MediatorImpl;
+import org.apache.tuscany.sca.databinding.jaxb.XMLAdapterExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSFaultExceptionMapper;
+import org.apache.tuscany.sca.interfacedef.java.jaxws.JAXWSJavaInterfaceProcessor;
+import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint;
+import org.osoa.sca.CallableReference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DataBindingModuleActivator implements ModuleActivator {
+
+ public void start(ExtensionPointRegistry registry) {
+ DataBindingExtensionPoint dataBindings = registry.getExtensionPoint(DataBindingExtensionPoint.class);
+ TransformerExtensionPoint transformers = registry.getExtensionPoint(TransformerExtensionPoint.class);
+
+ XMLAdapterExtensionPoint xmlAdapterExtensionPoint = registry.getExtensionPoint(XMLAdapterExtensionPoint.class);
+ xmlAdapterExtensionPoint.addAdapter(CallableReference.class, CallableReferenceXMLAdapter.class);
+ FaultExceptionMapper faultExceptionMapper = new JAXWSFaultExceptionMapper(dataBindings, xmlAdapterExtensionPoint);
+
+ MediatorImpl mediator = new MediatorImpl(dataBindings, transformers);
+ Input2InputTransformer input2InputTransformer = new Input2InputTransformer();
+ input2InputTransformer.setMediator(mediator);
+ transformers.addTransformer(input2InputTransformer, true);
+
+ Output2OutputTransformer output2OutputTransformer = new Output2OutputTransformer();
+ output2OutputTransformer.setMediator(mediator);
+ transformers.addTransformer(output2OutputTransformer, true);
+
+ Exception2ExceptionTransformer exception2ExceptionTransformer = new Exception2ExceptionTransformer(mediator, faultExceptionMapper);
+ transformers.addTransformer(exception2ExceptionTransformer, false);
+
+ Array2ArrayTransformer array2ArrayTransformer = new Array2ArrayTransformer();
+ array2ArrayTransformer.setMediator(mediator);
+ transformers.addTransformer(array2ArrayTransformer, true);
+
+ Group2GroupTransformer group2GroupTransformer = new Group2GroupTransformer();
+ group2GroupTransformer.setMediator(mediator);
+ transformers.addTransformer(group2GroupTransformer, true);
+
+ dataBindings.addDataBinding(new CallableReferenceDataBinding());
+ transformers.addTransformer(new CallableReference2XMLStreamReader(), true);
+ transformers.addTransformer(new XMLStreamReader2CallableReference(), false);
+
+ ModelFactoryExtensionPoint modelFactories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ JavaInterfaceFactory javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class);
+
+ // [rfeng] The JAX-WS processor should come before the Databinding processor to make sure @WebService
+ // is honored as Remoteable
+ javaFactory.addInterfaceVisitor(new JAXWSJavaInterfaceProcessor(dataBindings, faultExceptionMapper, xmlAdapterExtensionPoint));
+
+ javaFactory.addInterfaceVisitor(new DataBindingJavaInterfaceProcessor(dataBindings));
+
+ RuntimeWireProcessorExtensionPoint wireProcessorExtensionPoint = registry.getExtensionPoint(RuntimeWireProcessorExtensionPoint.class);
+ if (wireProcessorExtensionPoint != null) {
+ wireProcessorExtensionPoint.addWireProcessor(new DataBindingRuntimeWireProcessor(mediator, dataBindings, faultExceptionMapper));
+ }
+
+ }
+
+ public void stop(ExtensionPointRegistry registry) {
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java
new file mode 100644
index 0000000000..e182b472d4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessor.java
@@ -0,0 +1,210 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.databinding.processor;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.databinding.WrapperHandler;
+import org.apache.tuscany.sca.databinding.annotation.DataBinding;
+import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding;
+import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaOperation;
+import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor;
+import org.apache.tuscany.sca.interfacedef.util.WrapperInfo;
+
+/**
+ * The databinding annotation processor for java interfaces
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataBindingJavaInterfaceProcessor implements JavaInterfaceVisitor {
+ private static final String JAXB_DATABINDING = "javax.xml.bind.JAXBElement";
+ private DataBindingExtensionPoint dataBindingRegistry;
+
+ public DataBindingJavaInterfaceProcessor(DataBindingExtensionPoint dataBindingRegistry) {
+ super();
+ this.dataBindingRegistry = dataBindingRegistry;
+ }
+
+ public void visitInterface(JavaInterface javaInterface) throws InvalidInterfaceException {
+ if (!javaInterface.isRemotable()) {
+ return;
+ }
+ List<Operation> operations = javaInterface.getOperations();
+ processInterface(javaInterface, operations);
+ }
+
+ private void processInterface(JavaInterface javaInterface, List<Operation> operations) {
+ Class<?> clazz = javaInterface.getJavaClass();
+ DataBinding dataBinding = clazz.getAnnotation(DataBinding.class);
+ String dataBindingId = null;
+ boolean wrapperStyle = false;
+ if (dataBinding != null) {
+ dataBindingId = dataBinding.value();
+ wrapperStyle = dataBinding.wrapped();
+ }
+
+ Map<String, Operation> opMap = new HashMap<String, Operation>();
+ for (Operation op : javaInterface.getOperations()) {
+ opMap.put(op.getName(), op);
+ // In the case of @WebMethod, the method name can be different from the operation name
+ if (op instanceof JavaOperation) {
+ opMap.put(((JavaOperation)op).getJavaMethod().getName(), op);
+ }
+ if (dataBindingId != null) {
+ op.setDataBinding(dataBindingId);
+ op.setWrapperStyle(wrapperStyle);
+ }
+ }
+ for (Method method : clazz.getMethods()) {
+ if (method.getDeclaringClass() == Object.class) {
+ continue;
+ }
+ Operation operation = opMap.get(method.getName());
+ if (operation == null) { // @WebMethod exclude=true
+ continue;
+ }
+ DataBinding methodDataBinding = clazz.getAnnotation(DataBinding.class);
+ if (methodDataBinding == null) {
+ methodDataBinding = dataBinding;
+ }
+ dataBindingId = null;
+ wrapperStyle = false;
+ if (dataBinding != null) {
+ dataBindingId = dataBinding.value();
+ wrapperStyle = dataBinding.wrapped();
+ operation.setDataBinding(dataBindingId);
+ operation.setWrapperStyle(wrapperStyle);
+ }
+
+ // FIXME: We need a better way to identify simple java types
+ int i = 0;
+ for (org.apache.tuscany.sca.interfacedef.DataType<?> d : operation.getInputType().getLogical()) {
+ if (d.getDataBinding() == null) {
+ d.setDataBinding(dataBindingId);
+ }
+ for (Annotation a : method.getParameterAnnotations()[i]) {
+ if (a.annotationType() == org.apache.tuscany.sca.databinding.annotation.DataType.class) {
+ String value = ((org.apache.tuscany.sca.databinding.annotation.DataType)a).value();
+ d.setDataBinding(value);
+ }
+ }
+ dataBindingRegistry.introspectType(d, operation);
+ i++;
+ }
+ if (operation.getOutputType() != null) {
+ DataType<?> d = operation.getOutputType();
+ if (d.getDataBinding() == null) {
+ d.setDataBinding(dataBindingId);
+ }
+ org.apache.tuscany.sca.databinding.annotation.DataType dt =
+ method.getAnnotation(org.apache.tuscany.sca.databinding.annotation.DataType.class);
+ if (dt != null) {
+ d.setDataBinding(dt.value());
+ }
+ dataBindingRegistry.introspectType(d, operation);
+ }
+ for (org.apache.tuscany.sca.interfacedef.DataType<?> d : operation.getFaultTypes()) {
+ if (d.getDataBinding() == null) {
+ d.setDataBinding(dataBindingId);
+ }
+ // TODO: Handle exceptions
+ dataBindingRegistry.introspectType(d, operation);
+ }
+
+ // JIRA: TUSCANY-842
+ String db = operation.getDataBinding();
+ if (db == null || JAXB_DATABINDING.equals(db)) {
+ assignOperationDataBinding(operation);
+ db = operation.getDataBinding();
+ }
+
+ // Introspect the wrapper data type
+ if (operation.getWrapper() != null) {
+ org.apache.tuscany.sca.databinding.DataBinding dbObj =
+ dataBindingRegistry.getDataBinding(db);
+ WrapperHandler handler = dbObj == null ? null : dbObj.getWrapperHandler();
+ if (handler != null) {
+ WrapperInfo wrapper = operation.getWrapper();
+ wrapper.setInputWrapperType(handler.getWrapperType(operation, true));
+ wrapper.setOutputWrapperType(handler.getWrapperType(operation, false));
+ }
+ if (dbObj != null && handler == null) {
+ // To avoid JAXB wrapper bean generation
+ WrapperInfo wrapper = operation.getWrapper();
+ wrapper.setInputWrapperType(null);
+ wrapper.setOutputWrapperType(null);
+ }
+ }
+ }
+ }
+
+ /*
+ * Assigns an operation DB if one of the input types, output type, fault types has a non-default DB.
+ * However, if two of the input types, output type, fault types have two different non-default DBs
+ * ( e.g. SDO and JAXB), then we do nothing to the operation DB.
+ *
+ * The method logic assumes the JavaBeans DataBinding is the default
+ */
+ private void assignOperationDataBinding(Operation operation) {
+
+ Set<String> dbs = new HashSet<String>();
+
+ // Can't use DataType<?> since operation.getInputType() returns: DataType<List<DataType>>
+ List<DataType> opDataTypes = new LinkedList<DataType>();
+
+ opDataTypes.addAll(operation.getInputType().getLogical());
+ opDataTypes.add(operation.getOutputType());
+ for (DataType<DataType> ft : operation.getFaultTypes()) {
+ opDataTypes.add(ft.getLogical());
+ }
+
+ for (DataType<?> d : opDataTypes) {
+ if (d != null) {
+ String dataBinding = d.getDataBinding();
+ if ("java:array".equals(dataBinding)) {
+ dataBinding = ((DataType)d.getLogical()).getDataBinding();
+ }
+ if (dataBinding != null) {
+ dbs.add(dataBinding);
+ }
+ }
+ }
+
+ dbs.remove(JavaBeansDataBinding.NAME);
+ dbs.remove(SimpleJavaDataBinding.NAME);
+
+ if (dbs.size() == 1) {
+ operation.setDataBinding(dbs.iterator().next());
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Array2ArrayTransformer.java b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Array2ArrayTransformer.java
new file mode 100644
index 0000000000..38ca2cd10c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Array2ArrayTransformer.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.databinding.transformers;
+
+import java.lang.reflect.Array;
+
+import org.apache.tuscany.sca.databinding.Mediator;
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * This is a special transformer to transform the output from one IDL to the
+ * other one
+ *
+ * @version $Rev$ $Date$
+ */
+public class Array2ArrayTransformer extends BaseTransformer<Object, Object> implements PullTransformer<Object, Object> {
+
+ protected Mediator mediator;
+
+ public Array2ArrayTransformer() {
+ super();
+ }
+
+ /**
+ * @param mediator the mediator to set
+ */
+ @Reference
+ public void setMediator(Mediator mediator) {
+ this.mediator = mediator;
+ }
+
+ @Override
+ public String getSourceDataBinding() {
+ return "java:array";
+ }
+
+ @Override
+ public String getTargetDataBinding() {
+ return "java:array";
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType()
+ */
+ @Override
+ protected Class<Object> getSourceType() {
+ return Object.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType()
+ */
+ @Override
+ protected Class<Object> getTargetType() {
+ return Object.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.Transformer#getWeight()
+ */
+ @Override
+ public int getWeight() {
+ return 10;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object transform(Object array, TransformationContext context) {
+ try {
+ if (array == null) {
+ return null;
+ }
+ DataType<DataType> sourceType = context.getSourceDataType();
+ DataType<DataType> targetType = context.getTargetDataType();
+ int length = Array.getLength(array);
+ Object targetArray = Array.newInstance(targetType.getPhysical().getComponentType(), length);
+ for (int i = 0; i < length; i++) {
+ Object sourceItem = Array.get(array, i);
+ Object targetItem =
+ mediator.mediate(sourceItem, sourceType.getLogical(), targetType.getLogical(), context
+ .getMetadata());
+ Array.set(targetArray, i, targetItem);
+ }
+ return targetArray;
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReference2XMLStreamReader.java b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReference2XMLStreamReader.java
new file mode 100644
index 0000000000..124928db24
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReference2XMLStreamReader.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.databinding.transformers;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.core.context.CallableReferenceImpl;
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.apache.tuscany.sca.databinding.xml.StAXHelper;
+import org.osoa.sca.CallableReference;
+
+public class CallableReference2XMLStreamReader extends BaseTransformer<CallableReference, XMLStreamReader> implements
+ PullTransformer<CallableReference, XMLStreamReader> {
+
+ @Override
+ protected Class<CallableReference> getSourceType() {
+ return CallableReference.class;
+ }
+
+ @Override
+ protected Class<XMLStreamReader> getTargetType() {
+ return XMLStreamReader.class;
+ }
+
+ public XMLStreamReader transform(CallableReference source, TransformationContext context) {
+ try {
+ if (source != null) {
+ if (source instanceof CallableReferenceImpl) {
+ XMLStreamReader xmlReader = ((CallableReferenceImpl)source).getXMLReader();
+ if (xmlReader != null) {
+ return xmlReader;
+ } else {
+ String xmlString = ((CallableReferenceImpl)source).toXMLString();
+
+ // remove "<?xml...?>" processing instruction and wrap with a top-level element
+ return StAXHelper.createXMLStreamReader("<reference xmlns=\"http://callable\">"
+ + xmlString.substring(xmlString.indexOf("?>") + 2)
+ + "</reference>");
+ }
+ } else {
+ throw new TransformationException("Unrecognized transformation source object");
+ }
+ } else {
+ return null;
+ }
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ @Override
+ public int getWeight() {
+ return 10;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceDataBinding.java b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceDataBinding.java
new file mode 100644
index 0000000000..012950e215
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceDataBinding.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.databinding.transformers;
+
+import org.apache.tuscany.sca.databinding.XMLTypeHelper;
+import org.apache.tuscany.sca.databinding.impl.BaseDataBinding;
+import org.osoa.sca.CallableReference;
+
+public class CallableReferenceDataBinding extends BaseDataBinding {
+
+ public static final String NAME = CallableReference.class.getName();
+ public static final String[] ALIASES = new String[] {"callablereference"};
+
+ private CallableReferenceTypeHelper xmlTypeHelper;
+
+ public CallableReferenceDataBinding() {
+ super(NAME, ALIASES, CallableReference.class);
+ this.xmlTypeHelper = new CallableReferenceTypeHelper();
+ }
+
+ @Override
+ public XMLTypeHelper getXMLTypeHelper() {
+ return xmlTypeHelper;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceTypeHelper.java b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceTypeHelper.java
new file mode 100644
index 0000000000..97629ea7b5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceTypeHelper.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.databinding.transformers;
+
+import java.beans.Introspector;
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.databinding.XMLTypeHelper;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper;
+import org.apache.tuscany.sca.interfacedef.util.TypeInfo;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.apache.tuscany.sca.xsd.XSDFactory;
+import org.apache.tuscany.sca.xsd.XSDefinition;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class CallableReferenceTypeHelper implements XMLTypeHelper {
+ private static final String SCHEMA_NS = "http://www.w3.org/2001/XMLSchema";
+ private static final String ANYTYPE_NAME = "anyType";
+ private static final QName ANYTYPE_QNAME = new QName(SCHEMA_NS, ANYTYPE_NAME);
+
+ public CallableReferenceTypeHelper() {
+ super();
+ }
+
+ public TypeInfo getTypeInfo(Class javaType, Object logical) {
+ QName xmlType = JavaXMLMapper.getXMLType(javaType);
+ if (xmlType != null) {
+ return new TypeInfo(xmlType, true, null);
+ } else if (javaType.isInterface()) {
+ return new TypeInfo(ANYTYPE_QNAME, true, null);
+ } else {
+ if (logical instanceof XMLType) {
+ xmlType = ((XMLType)logical).getTypeName();
+ }
+ if (xmlType == null) {
+ xmlType = new QName(Introspector.decapitalize(javaType.getSimpleName()));
+ }
+ return new TypeInfo(xmlType, false, null);
+ }
+ }
+
+ public List<XSDefinition> getSchemaDefinitions(XSDFactory factory, ModelResolver resolver, Interface intf) {
+ return new ArrayList<XSDefinition>();
+ }
+
+ public List<XSDefinition> getSchemaDefinitions(XSDFactory factory, ModelResolver resolver, List<DataType> dataTypes) {
+ return new ArrayList<XSDefinition>();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceXMLAdapter.java b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceXMLAdapter.java
new file mode 100644
index 0000000000..ff6e444dcd
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/CallableReferenceXMLAdapter.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.databinding.transformers;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.tuscany.sca.databinding.xml.XMLStreamReader2String;
+import org.osoa.sca.CallableReference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CallableReferenceXMLAdapter extends XmlAdapter<Source, CallableReference> {
+ private TransformerFactory transformerFactory = TransformerFactory.newInstance();
+ private XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+
+ @Override
+ public CallableReference unmarshal(Source v) throws Exception {
+ StringWriter sw = new StringWriter();
+ StreamResult result = new StreamResult(sw);
+ transformerFactory.newTransformer().transform(v, result);
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(sw.toString()));
+ XMLStreamReader2CallableReference t2 = new XMLStreamReader2CallableReference();
+ return t2.transform(reader, null);
+ }
+
+ @Override
+ public Source marshal(CallableReference v) throws Exception {
+ CallableReference2XMLStreamReader t = new CallableReference2XMLStreamReader();
+ XMLStreamReader reader = t.transform(v, null);
+ XMLStreamReader2String t2 = new XMLStreamReader2String();
+ String xml = t2.transform(reader, null);
+ return new StreamSource(new StringReader(xml));
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java
new file mode 100644
index 0000000000..6e2e714bdb
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Exception2ExceptionTransformer.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.databinding.transformers;
+
+import org.apache.tuscany.sca.databinding.DataBinding;
+import org.apache.tuscany.sca.databinding.Mediator;
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper;
+
+/**
+ * This is a special transformer to transform the exception from one IDL to the
+ * other one
+ *
+ * @version $Rev$ $Date$
+ */
+public class Exception2ExceptionTransformer extends BaseTransformer<Throwable, Throwable> implements
+ PullTransformer<Throwable, Throwable> {
+
+ protected Mediator mediator;
+ protected FaultExceptionMapper faultExceptionMapper;
+
+ public Exception2ExceptionTransformer(Mediator mediator, FaultExceptionMapper faultExceptionMapper) {
+ super();
+ this.mediator = mediator;
+ this.faultExceptionMapper = faultExceptionMapper;
+ }
+
+ public Exception2ExceptionTransformer() {
+ super();
+ }
+
+ @Override
+ public String getSourceDataBinding() {
+ return DataBinding.IDL_FAULT;
+ }
+
+ @Override
+ public String getTargetDataBinding() {
+ return DataBinding.IDL_FAULT;
+ }
+
+ /**
+ * @param mediator the mediator to set
+ */
+ public void setMediator(Mediator mediator) {
+ this.mediator = mediator;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType()
+ */
+ @Override
+ protected Class<Throwable> getSourceType() {
+ return Throwable.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType()
+ */
+ @Override
+ protected Class<Throwable> getTargetType() {
+ return Throwable.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.Transformer#getWeight()
+ */
+ @Override
+ public int getWeight() {
+ return 10000;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Throwable transform(Throwable source, TransformationContext context) {
+ DataType<DataType> sourceType = context.getSourceDataType();
+
+ DataType<DataType> targetType = context.getTargetDataType();
+
+ Object sourceFaultInfo = faultExceptionMapper.getFaultInfo(source, sourceType.getLogical().getPhysical(), context.getSourceOperation());
+ Object targetFaultInfo =
+ mediator.mediate(sourceFaultInfo, sourceType.getLogical(), targetType.getLogical(), context.getMetadata());
+
+ Throwable targetException =
+ faultExceptionMapper.wrapFaultInfo(targetType, source.getMessage(), targetFaultInfo, source.getCause(), context.getTargetOperation());
+
+ // FIXME
+ return targetException == null ? source : targetException;
+
+ }
+
+ public void setFaultExceptionMapper(FaultExceptionMapper faultExceptionMapper) {
+ this.faultExceptionMapper = faultExceptionMapper;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java
new file mode 100644
index 0000000000..fb5f939edb
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Input2InputTransformer.java
@@ -0,0 +1,279 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.databinding.transformers;
+
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.apache.tuscany.sca.databinding.DataBinding;
+import org.apache.tuscany.sca.databinding.Mediator;
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.WrapperHandler;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.ElementInfo;
+import org.apache.tuscany.sca.interfacedef.util.WrapperInfo;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * This is a special transformer to transform the input from one IDL to the
+ * other one
+ *
+ * @version $Rev$ $Date$
+ */
+public class Input2InputTransformer extends BaseTransformer<Object[], Object[]> implements
+ PullTransformer<Object[], Object[]> {
+ private static final Logger logger = Logger.getLogger(Input2InputTransformer.class.getName());
+
+ protected Mediator mediator;
+
+ public Input2InputTransformer() {
+ super();
+ }
+
+ @Override
+ public String getSourceDataBinding() {
+ return DataBinding.IDL_INPUT;
+ }
+
+ @Override
+ public String getTargetDataBinding() {
+ return DataBinding.IDL_INPUT;
+ }
+
+ /**
+ * @param mediator the mediator to set
+ */
+ @Reference
+ public void setMediator(Mediator mediator) {
+ this.mediator = mediator;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType()
+ */
+ @Override
+ protected Class<Object[]> getSourceType() {
+ return Object[].class;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType()
+ */
+ @Override
+ protected Class<Object[]> getTargetType() {
+ return Object[].class;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.Transformer#getWeight()
+ */
+ @Override
+ public int getWeight() {
+ return 10000;
+ }
+
+ /**
+ * Match the structure of the wrapper element. If it matches, then we can do
+ * wrapper to wrapper transformation. Otherwise, we do child to child.
+ * @param w1
+ * @param w2
+ * @return
+ */
+ private boolean matches(WrapperInfo w1, WrapperInfo w2) {
+ if (w1 == null || w2 == null) {
+ return false;
+ }
+ if (!w1.getInputWrapperElement().equals(w2.getInputWrapperElement())) {
+ return false;
+ }
+
+ // Compare the child elements
+ List<ElementInfo> list1 = w1.getInputChildElements();
+ List<ElementInfo> list2 = w2.getInputChildElements();
+ if (list1.size() != list2.size()) {
+ return false;
+ }
+ // FXIME: [rfeng] At this point, the J2W generates local elments under the namespace
+ // of the interface instead of "". We only compare the local parts only to work around
+ // the namespace mismatch
+ for (int i = 0; i < list1.size(); i++) {
+ String n1 = list1.get(i).getQName().getLocalPart();
+ String n2 = list2.get(i).getQName().getLocalPart();
+ if (!n1.equals(n2)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object[] transform(Object[] source, TransformationContext context) {
+ // Check if the source operation is wrapped
+ DataType<List<DataType>> sourceType = context.getSourceDataType();
+ Operation sourceOp = context.getSourceOperation();
+ boolean sourceWrapped = sourceOp != null && sourceOp.isWrapperStyle() && sourceOp.getWrapper() != null;
+ boolean sourceBare = sourceOp != null && !sourceOp.isWrapperStyle() && sourceOp.getWrapper() == null;
+
+ // Find the wrapper handler for source data
+ WrapperHandler sourceWrapperHandler = null;
+ String sourceDataBinding = getDataBinding(sourceOp);
+ sourceWrapperHandler = getWrapperHandler(sourceDataBinding, sourceWrapped);
+
+ // Check if the target operation is wrapped
+ DataType<List<DataType>> targetType = context.getTargetDataType();
+ Operation targetOp = (Operation)context.getTargetOperation();
+ boolean targetWrapped = targetOp != null && targetOp.isWrapperStyle() && targetOp.getWrapper() != null;
+ boolean targetBare = targetOp != null && !targetOp.isWrapperStyle() && targetOp.getWrapper() == null;
+
+ // Find the wrapper handler for target data
+ WrapperHandler targetWrapperHandler = null;
+ String targetDataBinding = getDataBinding(targetOp);
+ targetWrapperHandler = getWrapperHandler(targetDataBinding, targetWrapped);
+
+ if ((!sourceWrapped && !sourceBare) && targetWrapped) {
+ // Unwrapped --> Wrapped
+ WrapperInfo wrapper = targetOp.getWrapper();
+ // ElementInfo wrapperElement = wrapper.getInputWrapperElement();
+
+ // Class<?> targetWrapperClass = wrapper != null ? wrapper.getInputWrapperClass() : null;
+
+ if (source == null) {
+ // Empty child elements
+ Object targetWrapper = targetWrapperHandler.create(targetOp, true);
+ return new Object[] {targetWrapper};
+ }
+
+ // If the source can be wrapped, wrapped it first
+ if (sourceWrapperHandler != null) {
+ WrapperInfo sourceWrapperInfo = sourceOp.getWrapper();
+ DataType sourceWrapperType = sourceWrapperInfo != null ? sourceWrapperInfo.getInputWrapperType() : null;
+
+ // We only do wrapper to wrapper transformation if the source has a wrapper and both sides
+ // match by XML structure
+ if (sourceWrapperType != null && matches(sourceOp.getWrapper(), targetOp.getWrapper())) {
+ Class<?> sourceWrapperClass = sourceWrapperType.getPhysical();
+
+ // Create the source wrapper
+ Object sourceWrapper = sourceWrapperHandler.create(sourceOp, true);
+
+ // Populate the source wrapper
+ if (sourceWrapper != null) {
+ sourceWrapperHandler.setChildren(sourceWrapper,
+ source,
+ sourceOp,
+ true);
+
+ // Transform the data from source wrapper to target wrapper
+ Object targetWrapper =
+ mediator.mediate(sourceWrapper, sourceWrapperType, targetType.getLogical().get(0), context
+ .getMetadata());
+ return new Object[] {targetWrapper};
+ }
+ }
+ }
+ // Fall back to child by child transformation
+ Object targetWrapper = targetWrapperHandler.create(targetOp, true);
+ List<DataType> argTypes = wrapper.getUnwrappedInputType().getLogical();
+ Object[] targetChildren = new Object[source.length];
+ for (int i = 0; i < source.length; i++) {
+ // ElementInfo argElement = wrapper.getInputChildElements().get(i);
+ DataType<XMLType> argType = argTypes.get(i);
+ targetChildren[i] =
+ mediator.mediate(source[i], sourceType.getLogical().get(i), argType, context.getMetadata());
+ }
+ targetWrapperHandler.setChildren(targetWrapper,
+ targetChildren,
+ targetOp,
+ true);
+ return new Object[] {targetWrapper};
+
+ } else if (sourceWrapped && (!targetWrapped && !targetBare)) {
+ // Wrapped to Unwrapped
+ Object sourceWrapper = source[0];
+ Object[] target = null;
+
+ // List<ElementInfo> childElements = sourceOp.getWrapper().getInputChildElements();
+ if (targetWrapperHandler != null) {
+ // ElementInfo wrapperElement = sourceOp.getWrapper().getInputWrapperElement();
+ // FIXME: This is a workaround for the wsdless support as it passes in child elements
+ // under the wrapper that only matches by position
+ if (sourceWrapperHandler.isInstance(sourceWrapper, sourceOp, true)) {
+
+ WrapperInfo targetWrapperInfo = targetOp.getWrapper();
+ DataType targetWrapperType =
+ targetWrapperInfo != null ? targetWrapperInfo.getInputWrapperType() : null;
+ if (targetWrapperType != null && matches(sourceOp.getWrapper(), targetOp.getWrapper())) {
+ Object targetWrapper =
+ mediator.mediate(sourceWrapper, sourceType.getLogical().get(0), targetWrapperType, context
+ .getMetadata());
+ target = targetWrapperHandler.getChildren(targetWrapper, targetOp, true).toArray();
+ return target;
+ }
+ }
+ }
+ Object[] sourceChildren = sourceWrapperHandler.getChildren(sourceWrapper, sourceOp, true).toArray();
+ target = new Object[sourceChildren.length];
+ for (int i = 0; i < sourceChildren.length; i++) {
+ DataType<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 getWrapperHandler(String dataBindingId, boolean required) {
+ WrapperHandler wrapperHandler = null;
+ if (dataBindingId != null) {
+ DataBinding dataBinding = mediator.getDataBindings().getDataBinding(dataBindingId);
+ wrapperHandler = dataBinding == null ? null : dataBinding.getWrapperHandler();
+ }
+ if (wrapperHandler == null && required) {
+ throw new TransformationException("No wrapper handler is provided for databinding: " + dataBindingId);
+ }
+ return wrapperHandler;
+ }
+
+ private String getDataBinding(Operation operation) {
+ WrapperInfo wrapper = operation.getWrapper();
+ if (wrapper != null) {
+ return wrapper.getDataBinding();
+ } else {
+ return null;
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java
new file mode 100644
index 0000000000..8d586905c4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/Output2OutputTransformer.java
@@ -0,0 +1,257 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.databinding.transformers;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.databinding.DataBinding;
+import org.apache.tuscany.sca.databinding.Mediator;
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.WrapperHandler;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.ElementInfo;
+import org.apache.tuscany.sca.interfacedef.util.WrapperInfo;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * This is a special transformer to transform the output from one IDL to the
+ * other one
+ *
+ * @version $Rev$ $Date$
+ */
+public class Output2OutputTransformer extends BaseTransformer<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.sca.databinding.impl.BaseTransformer#getSourceType()
+ */
+ @Override
+ protected Class<Object> getSourceType() {
+ return Object.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType()
+ */
+ @Override
+ protected Class<Object> getTargetType() {
+ return Object.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.Transformer#getWeight()
+ */
+ @Override
+ public int getWeight() {
+ return 10;
+ }
+
+ private String getDataBinding(Operation operation) {
+ WrapperInfo wrapper = operation.getWrapper();
+ if (wrapper != null) {
+ return wrapper.getDataBinding();
+ } else {
+ return null;
+ }
+ }
+
+ private WrapperHandler getWrapperHandler(String dataBindingId, boolean required) {
+ WrapperHandler wrapperHandler = null;
+ if (dataBindingId != null) {
+ DataBinding dataBinding = mediator.getDataBindings().getDataBinding(dataBindingId);
+ wrapperHandler = dataBinding == null ? null : dataBinding.getWrapperHandler();
+ }
+ if (wrapperHandler == null && required) {
+ throw new TransformationException("No wrapper handler is provided for databinding: " + dataBindingId);
+ }
+ return wrapperHandler;
+ }
+
+ /**
+ * Match the structure of the wrapper element. If it matches, then we can do
+ * wrapper to wrapper transformation. Otherwise, we do child to child.
+ * @param w1
+ * @param w2
+ * @return
+ */
+ private boolean matches(WrapperInfo w1, WrapperInfo w2) {
+ if (w1 == null || w2 == null) {
+ return false;
+ }
+ if (!w1.getOutputWrapperElement().equals(w2.getOutputWrapperElement())) {
+ return false;
+ }
+
+ // Compare the child elements
+ List<ElementInfo> list1 = w1.getOutputChildElements();
+ List<ElementInfo> list2 = w2.getOutputChildElements();
+ if (list1.size() != list2.size()) {
+ return false;
+ }
+ // FXIME: [rfeng] At this point, the J2W generates local elments under the namespace
+ // of the interface instead of "". We only compare the local parts only to work around
+ // the namespace mismatch
+ for (int i = 0; i < list1.size(); i++) {
+ String n1 = list1.get(i).getQName().getLocalPart();
+ String n2 = list2.get(i).getQName().getLocalPart();
+ if (!n1.equals(n2)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object transform(Object response, TransformationContext context) {
+ try {
+ DataType<DataType> sourceType = context.getSourceDataType();
+ Operation sourceOp = context.getSourceOperation();
+ boolean sourceWrapped = sourceOp != null && sourceOp.isWrapperStyle() && sourceOp.getWrapper() != null;
+ boolean sourceBare = sourceOp != null && !sourceOp.isWrapperStyle() && sourceOp.getWrapper() == null;
+
+ WrapperHandler sourceWrapperHandler = null;
+ String sourceDataBinding = getDataBinding(sourceOp);
+ sourceWrapperHandler = getWrapperHandler(sourceDataBinding, sourceWrapped);
+
+ DataType<DataType> targetType = context.getTargetDataType();
+ Operation targetOp = (Operation)context.getTargetOperation();
+ boolean targetWrapped = targetOp != null && targetOp.isWrapperStyle() && targetOp.getWrapper() != null;
+ boolean targetBare = targetOp != null && !targetOp.isWrapperStyle() && targetOp.getWrapper() == null;
+
+ WrapperHandler targetWrapperHandler = null;
+ String targetDataBinding = getDataBinding(targetOp);
+ targetWrapperHandler = getWrapperHandler(targetDataBinding, targetWrapped);
+
+ if ((!sourceWrapped &&!sourceBare) && targetWrapped) {
+ // Unwrapped --> Wrapped
+ WrapperInfo wrapper = targetOp.getWrapper();
+ ElementInfo wrapperElement = wrapper.getOutputWrapperElement();
+ List<ElementInfo> childElements = wrapper.getOutputChildElements();
+ Class<?> targetWrapperClass = wrapper != null ? wrapper.getOutputWrapperClass() : null;
+
+ // If the source can be wrapped, wrapped it first
+ if (sourceWrapperHandler != null) {
+ WrapperInfo sourceWrapperInfo = sourceOp.getWrapper();
+ DataType sourceWrapperType =
+ sourceWrapperInfo != null ? sourceWrapperInfo.getOutputWrapperType() : null;
+
+ if (sourceWrapperType != null && matches(sourceOp.getWrapper(), targetOp.getWrapper())) {
+ Class<?> sourceWrapperClass = sourceWrapperType.getPhysical();
+
+ Object sourceWrapper = sourceWrapperHandler.create(sourceOp, false);
+ if (sourceWrapper != null) {
+ if (!childElements.isEmpty()) {
+ // Set the return value
+ sourceWrapperHandler.setChildren(sourceWrapper,
+ new Object[] {response},
+ sourceOp,
+ false);
+ }
+ Object targetWrapper =
+ mediator.mediate(sourceWrapper, sourceWrapperType, targetType.getLogical(), context
+ .getMetadata());
+ return targetWrapper;
+ }
+ }
+ }
+ Object targetWrapper = targetWrapperHandler.create(targetOp, false);
+
+ if (childElements.isEmpty()) {
+ // void output
+ return targetWrapper;
+ }
+
+ DataType<XMLType> argType = wrapper.getUnwrappedOutputType();
+ Object child = response;
+ child = mediator.mediate(response, sourceType.getLogical(), argType, context.getMetadata());
+ targetWrapperHandler.setChildren(targetWrapper, new Object[] {child}, targetOp, false);
+ return targetWrapper;
+ } else if (sourceWrapped && (!targetWrapped && !targetBare)) {
+ // Wrapped to Unwrapped
+ Object sourceWrapper = response;
+ List<ElementInfo> childElements = sourceOp.getWrapper().getOutputChildElements();
+ if (childElements.isEmpty()) {
+ // The void output
+ return null;
+ }
+ if (targetWrapperHandler != null) {
+ ElementInfo wrapperElement = sourceOp.getWrapper().getOutputWrapperElement();
+
+ // FIXME: This is a workaround for the wsdless support as it passes in child elements
+ // under the wrapper that only matches by position
+ if (sourceWrapperHandler.isInstance(sourceWrapper, sourceOp, false)) {
+
+ WrapperInfo targetWrapperInfo = targetOp.getWrapper();
+ DataType targetWrapperType =
+ targetWrapperInfo != null ? targetWrapperInfo.getOutputWrapperType() : null;
+
+ if (targetWrapperType != null && matches(sourceOp.getWrapper(), targetOp.getWrapper())) {
+ Object targetWrapper =
+ mediator.mediate(sourceWrapper, sourceType.getLogical(), targetWrapperType, context
+ .getMetadata());
+ return targetWrapperHandler.getChildren(targetWrapper, targetOp, false).get(0);
+ }
+ }
+ }
+ Object child = sourceWrapperHandler.getChildren(sourceWrapper, sourceOp, false).get(0);
+ DataType<?> childType = sourceOp.getWrapper().getUnwrappedOutputType();
+ return mediator.mediate(child, childType, targetType.getLogical(), context.getMetadata());
+ } else {
+ // FIXME: Do we want to handle wrapped to wrapped?
+ return mediator.mediate(response, sourceType.getLogical(), targetType.getLogical(), context
+ .getMetadata());
+ }
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/XMLStreamReader2CallableReference.java b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/XMLStreamReader2CallableReference.java
new file mode 100644
index 0000000000..841efa9398
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/transformers/XMLStreamReader2CallableReference.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.databinding.transformers;
+
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import java.lang.reflect.Constructor;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.core.context.CallableReferenceImpl;
+import org.apache.tuscany.sca.core.context.ServiceReferenceImpl;
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.osoa.sca.CallableReference;
+
+@SuppressWarnings("unchecked")
+public class XMLStreamReader2CallableReference extends BaseTransformer<XMLStreamReader, CallableReference>
+ implements PullTransformer<XMLStreamReader, CallableReference> {
+
+ private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0";
+ private static final String COMPOSITE = "composite";
+ public static final QName COMPOSITE_QNAME = new QName(SCA10_NS, COMPOSITE);
+
+ public CallableReference transform(XMLStreamReader source, TransformationContext context) {
+ try {
+ if (source != null) {
+ skipTopLevelElement(source);
+ Class refType = context.getTargetDataType().getPhysical();
+ Class implType;
+ if (refType.isAssignableFrom(CallableReferenceImpl.class)) {
+ implType = CallableReferenceImpl.class;
+ } else if (refType.isAssignableFrom(ServiceReferenceImpl.class)) {
+ implType = ServiceReferenceImpl.class;
+ } else {
+ throw new TransformationException("Unrecognized transformation target type");
+ }
+ Constructor constructor = implType.getConstructor(new Class[] {XMLStreamReader.class});
+ return (CallableReference)constructor.newInstance(new Object[] {source});
+ } else {
+ return null;
+ }
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ /*
+ * Step over top-level element added by CallableReference2XMLStreamReader
+ */
+ private void skipTopLevelElement(XMLStreamReader source) throws XMLStreamException {
+ while (source.hasNext()) {
+ int event = source.getEventType();
+ if (event == START_ELEMENT) {
+ QName name = source.getName();
+ if (COMPOSITE_QNAME.equals(name)) {
+ return;
+ }
+ }
+ source.next();
+ }
+ throw new TransformationException("<composite> element not found");
+ }
+
+ @Override
+ protected Class<XMLStreamReader> getSourceType() {
+ return XMLStreamReader.class;
+ }
+
+ @Override
+ protected Class<CallableReference> getTargetType() {
+ return CallableReference.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 10;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java
new file mode 100644
index 0000000000..b41c7fb012
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataBindingRuntimeWireProcessor.java
@@ -0,0 +1,195 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.databinding.wire;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.databinding.Mediator;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.apache.tuscany.sca.runtime.RuntimeWireProcessor;
+
+/**
+ * This processor is responsible to add an interceptor to invocation chain if
+ * the source and target operations have different databinding requirements
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataBindingRuntimeWireProcessor implements RuntimeWireProcessor {
+ private Mediator mediator;
+ private DataBindingExtensionPoint dataBindings;
+ private FaultExceptionMapper faultExceptionMapper;
+
+ public DataBindingRuntimeWireProcessor(Mediator mediator,
+ DataBindingExtensionPoint dataBindings,
+ FaultExceptionMapper faultExceptionMapper) {
+ super();
+ this.mediator = mediator;
+ this.dataBindings = dataBindings;
+ this.faultExceptionMapper = faultExceptionMapper;
+ }
+
+ public boolean isTransformationRequired(DataType source, DataType target) {
+ if (source == null || target == null) { // void return type
+ return false;
+ }
+ if (source == target) {
+ return false;
+ }
+
+ // Output type can be null
+ if (source == null && target == null) {
+ return false;
+ } else if (source == null || target == null) {
+ return true;
+ }
+ String sourceDataBinding = source.getDataBinding();
+ String targetDataBinding = target.getDataBinding();
+ if (sourceDataBinding == targetDataBinding) {
+ return false;
+ }
+ if (sourceDataBinding == null || targetDataBinding == null) {
+ // TODO: If any of the databinding is null, then no transformation
+ return false;
+ }
+ return !sourceDataBinding.equals(targetDataBinding);
+ }
+
+ public boolean isTransformationRequired(Operation source, Operation target) {
+ if (source == target) {
+ return false;
+ }
+
+ if (source.isWrapperStyle() != target.isWrapperStyle()) {
+ return true;
+ }
+
+ // Check output type
+ DataType sourceOutputType = source.getOutputType();
+ DataType targetOutputType = target.getOutputType();
+
+ // Note the target output type is now the source for checking
+ // compatibility
+ if (isTransformationRequired(targetOutputType, sourceOutputType)) {
+ return true;
+ }
+
+ List<DataType> sourceInputType = source.getInputType().getLogical();
+ List<DataType> targetInputType = target.getInputType().getLogical();
+
+ int size = sourceInputType.size();
+ if (size != targetInputType.size()) {
+ // TUSCANY-1682: The wrapper style may have different arguments
+ return true;
+ }
+ for (int i = 0; i < size; i++) {
+ if (isTransformationRequired(sourceInputType.get(i), targetInputType.get(i))) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ private boolean isTransformationRequired(InterfaceContract sourceContract,
+ Operation sourceOperation,
+ InterfaceContract targetContract,
+ Operation targetOperation) {
+ if (targetContract == null) {
+ targetContract = sourceContract;
+ }
+ if (sourceContract == targetContract) {
+ return false;
+ }
+ return isTransformationRequired(sourceOperation, targetOperation);
+ }
+
+ public void process(RuntimeWire wire) {
+ InterfaceContract sourceContract = wire.getSource().getInterfaceContract();
+ InterfaceContract targetContract = wire.getTarget().getInterfaceContract();
+ if (targetContract == null) {
+ targetContract = sourceContract;
+ }
+
+ if (!sourceContract.getInterface().isRemotable()) {
+ return;
+ }
+ List<InvocationChain> chains = wire.getInvocationChains();
+ for (InvocationChain chain : chains) {
+ Operation sourceOperation = chain.getSourceOperation();
+ Operation targetOperation = chain.getTargetOperation();
+
+ Interceptor interceptor = null;
+ if (isTransformationRequired(sourceContract, sourceOperation, targetContract, targetOperation)) {
+ // Add the interceptor to the source side because multiple
+ // references can be wired to the same service
+ interceptor =
+ new DataTransformationInterceptor(wire, sourceOperation, targetOperation, mediator,
+ faultExceptionMapper);
+ } else {
+ // assume pass-by-values copies are required if interfaces are remotable and there is no data binding
+ // transformation, i.e. a transformation will result in a copy so another pass-by-value copy is unnecessary
+ if (!isOnMessage(targetOperation) && isRemotable(chain, sourceOperation, targetOperation)) {
+ interceptor =
+ new PassByValueInterceptor(dataBindings, faultExceptionMapper, chain, targetOperation);
+ }
+ }
+ if (interceptor != null) {
+ String phase =
+ (wire.getSource().getContract() instanceof ComponentReference) ? Phase.REFERENCE_INTERFACE
+ : Phase.SERVICE_INTERFACE;
+ chain.addInterceptor(phase, interceptor);
+ }
+ }
+
+ }
+
+ /**
+ * FIXME: TUSCANY-2586, temporary work around till the JIRA is fixed to prevent
+ * the PassByValueInterceptor being used for services when the binding protocol
+ * doesn't need the copies done.
+ */
+ protected boolean isOnMessage(Operation op) {
+ return "onMessage".equals(op.getName());
+ }
+
+ /**
+ * Pass-by-value copies are required if the interfaces are remotable unless the
+ * implementation uses the @AllowsPassByReference annotation.
+ */
+ protected boolean isRemotable(InvocationChain chain, Operation sourceOperation, Operation targetOperation) {
+ if (!sourceOperation.getInterface().isRemotable()) {
+ return false;
+ }
+ if (!targetOperation.getInterface().isRemotable()) {
+ return false;
+ }
+ return true;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java
new file mode 100644
index 0000000000..5814f3d215
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/DataTransformationInterceptor.java
@@ -0,0 +1,264 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.databinding.wire;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.databinding.DataBinding;
+import org.apache.tuscany.sca.databinding.Mediator;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
+import org.apache.tuscany.sca.interfacedef.util.FaultException;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.apache.tuscany.sca.invocation.DataExchangeSemantics;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * An interceptor to transform data across databindings on the wire
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataTransformationInterceptor implements Interceptor, DataExchangeSemantics {
+ private Invoker next;
+
+ private Operation sourceOperation;
+
+ private Operation targetOperation;
+ private RuntimeWire wire;
+ private Mediator mediator;
+ private FaultExceptionMapper faultExceptionMapper;
+
+ public DataTransformationInterceptor(RuntimeWire wire,
+ Operation sourceOperation,
+ Operation targetOperation,
+ Mediator mediator,
+ FaultExceptionMapper faultExceptionMapper) {
+ super();
+ this.sourceOperation = sourceOperation;
+ this.targetOperation = targetOperation;
+ this.mediator = mediator;
+ this.wire = wire;
+ this.faultExceptionMapper = faultExceptionMapper;
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public Message invoke(Message msg) {
+ Object input = transform(msg.getBody(), sourceOperation.getInputType(), targetOperation.getInputType(), false);
+ msg.setBody(input);
+ Message resultMsg = next.invoke(msg);
+ Object result = resultMsg.getBody();
+ if (sourceOperation.isNonBlocking()) {
+ // Not to reset the message body
+ return resultMsg;
+ }
+
+ // FIXME: Should we fix the Operation model so that getOutputType
+ // returns DataType<DataType<T>>?
+ DataType<DataType> targetType =
+ new DataTypeImpl<DataType>(DataBinding.IDL_OUTPUT, Object.class, targetOperation.getOutputType());
+
+ DataType<DataType> sourceType =
+ new DataTypeImpl<DataType>(DataBinding.IDL_OUTPUT, Object.class, sourceOperation.getOutputType());
+
+ if (resultMsg.isFault()) {
+
+ // FIXME: We need to figure out what fault type it is and then
+ // transform it
+ // back the source fault type
+ // throw new InvocationRuntimeException((Throwable) result);
+
+ if ((result instanceof Exception) && !(result instanceof RuntimeException)) {
+ // FIXME: How to match fault data to a fault type for the
+ // operation?
+
+ // If the result is from an InvocationTargetException look at
+ // the actual cause.
+ if (result instanceof InvocationTargetException) {
+ result = ((InvocationTargetException)result).getCause();
+ }
+ DataType targetDataType = null;
+ for (DataType exType : targetOperation.getFaultTypes()) {
+ if (((Class)exType.getPhysical()).isInstance(result)) {
+ if (result instanceof FaultException) {
+ DataType faultType = (DataType)exType.getLogical();
+ if (((FaultException)result).isMatchingType(faultType.getLogical())) {
+ targetDataType = exType;
+ break;
+ }
+ } else {
+ targetDataType = exType;
+ break;
+ }
+ }
+ }
+
+ /*
+ if (targetDataType == null) {
+ // Not a business exception
+ return resultMsg;
+ }
+ */
+
+ DataType targetFaultType = getFaultType(targetDataType);
+ if (targetFaultType == null) {
+ // No matching fault type, it's a system exception
+ Throwable cause = (Throwable) result;
+ throw new ServiceRuntimeException(cause);
+ }
+
+ // FIXME: How to match a source fault type to a target fault
+ // type?
+ DataType sourceDataType = null;
+ DataType sourceFaultType = null;
+ for (DataType exType : sourceOperation.getFaultTypes()) {
+ DataType faultType = getFaultType(exType);
+ // Match by the QName (XSD element) of the fault type
+ if (faultType != null && typesMatch(targetFaultType.getLogical(), faultType.getLogical())) {
+ sourceDataType = exType;
+ sourceFaultType = faultType;
+ break;
+ }
+ }
+
+ if (sourceFaultType == null) {
+ // No matching fault type, it's a system exception
+ Throwable cause = (Throwable) result;
+ throw new ServiceRuntimeException(cause);
+ }
+
+ Object newResult =
+ transformException(result, targetDataType, sourceDataType, targetFaultType, sourceFaultType);
+ if (newResult != result) {
+ resultMsg.setFaultBody(newResult);
+ }
+ }
+
+ } else {
+ assert !(result instanceof Throwable) : "Expected messages that are not throwable " + result;
+
+ Object newResult = transform(result, targetType, sourceType, true);
+ if (newResult != result) {
+ resultMsg.setBody(newResult);
+ }
+ }
+
+ return resultMsg;
+ }
+
+ private Object transform(Object source, DataType sourceType, DataType targetType, boolean isResponse) {
+ if (sourceType == targetType || (sourceType != null && sourceType.equals(targetType))) {
+ return source;
+ }
+ Map<String, Object> metadata = new HashMap<String, Object>();
+ metadata.put("source.operation", isResponse ? targetOperation : sourceOperation);
+ metadata.put("target.operation", isResponse ? sourceOperation : targetOperation);
+ metadata.put("wire", wire);
+ return mediator.mediate(source, sourceType, targetType, metadata);
+ }
+
+ private DataType getFaultType(DataType exceptionType) {
+ return exceptionType == null ? null : (DataType)exceptionType.getLogical();
+ }
+
+ private boolean typesMatch(Object first, Object second) {
+ if (first.equals(second)) {
+ return true;
+ }
+ if (first instanceof XMLType && second instanceof XMLType) {
+ XMLType t1 = (XMLType)first;
+ XMLType t2 = (XMLType)second;
+ // TUSCANY-2113, we should compare element names only
+ return matches(t1.getElementName(), t2.getElementName());
+ }
+ return false;
+ }
+
+ /**
+ * @param qn1
+ * @param qn2
+ */
+ private boolean matches(QName qn1, QName qn2) {
+ if (qn1 == qn2) {
+ return true;
+ }
+ if (qn1 == null || qn2 == null) {
+ return false;
+ }
+ String ns1 = qn1.getNamespaceURI();
+ String ns2 = qn2.getNamespaceURI();
+ String e1 = qn1.getLocalPart();
+ String e2 = qn2.getLocalPart();
+ if (e1.equals(e2) && (ns1.equals(ns2) || ns1.equals(ns2 + "/") || ns2.equals(ns1 + "/"))) {
+ // Tolerating the trailing / which is required by JAX-WS java package --> xml ns mapping
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * @param source The source exception
+ * @param sourceExType The data type for the source exception
+ * @param targetExType The data type for the target exception
+ * @param sourceType The fault type for the source
+ * @param targetType The fault type for the target
+ * @return
+ */
+ private Object transformException(Object source,
+ DataType sourceExType,
+ DataType targetExType,
+ DataType sourceType,
+ DataType targetType) {
+ if (sourceType == targetType || (sourceType != null && sourceType.equals(targetType))) {
+ return source;
+ }
+ Map<String, Object> metadata = new HashMap<String, Object>();
+ metadata.put("source.operation", targetOperation);
+ metadata.put("target.operation", sourceOperation);
+ metadata.put("wire", wire);
+ DataType<DataType> eSourceDataType =
+ new DataTypeImpl<DataType>("idl:fault", sourceExType.getPhysical(), sourceType);
+ DataType<DataType> eTargetDataType =
+ new DataTypeImpl<DataType>("idl:fault", targetExType.getPhysical(), targetType);
+
+ return mediator.mediate(source, eSourceDataType, eTargetDataType, metadata);
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public boolean allowsPassByReference() {
+ return true;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.java b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.java
new file mode 100644
index 0000000000..3586f54d71
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/java/org/apache/tuscany/sca/core/databinding/wire/PassByValueInterceptor.java
@@ -0,0 +1,268 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.databinding.wire;
+
+import java.io.Serializable;
+import java.lang.reflect.Array;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.util.IdentityHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.databinding.DataBinding;
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding;
+import org.apache.tuscany.sca.databinding.jaxb.JAXBDataBinding;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.FaultExceptionMapper;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * Implementation of an interceptor that enforces pass-by-value semantics
+ * on operation invocations by copying the operation input and output data.
+ *
+ * @version $Rev$ $Date$
+ */
+public class PassByValueInterceptor implements Interceptor {
+
+ private DataBindingExtensionPoint dataBindings;
+ private FaultExceptionMapper faultExceptionMapper;
+
+ private DataBinding[] inputDataBindings;
+ private DataBinding outputDataBinding;
+ private DataBinding javaBeanDataBinding;
+ private DataBinding jaxbDataBinding;
+ private Operation operation;
+ private Invoker nextInvoker;
+ private InvocationChain chain;
+
+ /**
+ * Constructs a new PassByValueInterceptor.
+ * @param dataBindings databinding extension point
+ * @param operation the intercepted operation
+ */
+ public PassByValueInterceptor(DataBindingExtensionPoint dataBindings,
+ FaultExceptionMapper faultExceptionMapper,
+ InvocationChain chain,
+ Operation operation) {
+ this.chain = chain;
+ this.operation = operation;
+
+ // Cache data bindings to use
+ this.dataBindings = dataBindings;
+ this.faultExceptionMapper = faultExceptionMapper;
+
+ jaxbDataBinding = dataBindings.getDataBinding(JAXBDataBinding.NAME);
+ javaBeanDataBinding = dataBindings.getDataBinding(JavaBeansDataBinding.NAME);
+
+ // Determine the input databindings
+ if (operation.getInputType() != null) {
+ List<DataType> inputTypes = operation.getInputType().getLogical();
+ inputDataBindings = new DataBinding[inputTypes.size()];
+ int i = 0;
+ for (DataType inputType : inputTypes) {
+ String id = inputType.getDataBinding();
+ inputDataBindings[i++] = dataBindings.getDataBinding(id);
+ }
+ }
+
+ // Determine the output databinding
+ if (operation.getOutputType() != null) {
+ String id = operation.getOutputType().getDataBinding();
+ outputDataBinding = dataBindings.getDataBinding(id);
+ }
+ }
+
+ public Message invoke(Message msg) {
+ if (chain.allowsPassByReference()) {
+ return nextInvoker.invoke(msg);
+ }
+
+ msg.setBody(copy((Object[])msg.getBody(), inputDataBindings, operation.getInputType().getLogical()));
+
+ Message resultMsg = nextInvoker.invoke(msg);
+
+ if (!msg.isFault() && operation.getOutputType() != null) {
+ resultMsg.setBody(copy(resultMsg.getBody(), outputDataBinding, operation.getOutputType()));
+ }
+
+ if (msg.isFault()) {
+ msg.setFaultBody(copyFault(msg.getBody()));
+ }
+ return resultMsg;
+ }
+
+ private Object copyFault(Object fault) {
+ if (faultExceptionMapper == null) {
+ return fault;
+ }
+ for (DataType et : operation.getFaultTypes()) {
+ if (et.getPhysical().isInstance(fault)) {
+ Throwable ex = (Throwable)fault;
+ DataType<DataType> exType =
+ new DataTypeImpl<DataType>(ex.getClass(), new DataTypeImpl<XMLType>(ex.getClass(), XMLType.UNKNOWN));
+ faultExceptionMapper.introspectFaultDataType(exType, operation, false);
+ DataType faultType = exType.getLogical();
+ Object faultInfo = faultExceptionMapper.getFaultInfo(ex, faultType.getPhysical(), operation);
+ faultInfo = copy(faultInfo, dataBindings.getDataBinding(faultType.getDataBinding()), faultType);
+ fault = faultExceptionMapper.wrapFaultInfo(exType, ex.getMessage(), faultInfo, ex.getCause(), operation);
+ return fault;
+ }
+ }
+ return fault;
+ }
+
+ /**
+ * Copy an array of data objects passed to an operation
+ * @param data array of objects to copy
+ * @return the copy
+ */
+ private Object[] copy(Object[] data, DataBinding[] dataBindings, List<DataType> dataTypes) {
+ if (data == null) {
+ return null;
+ }
+ Object[] copy = new Object[data.length];
+ Map<Object, Object> map = new IdentityHashMap<Object, Object>();
+ for (int i = 0; i < data.length; i++) {
+ Object arg = data[i];
+ if (arg == null) {
+ copy[i] = null;
+ } else {
+ Object copiedArg = map.get(arg);
+ if (copiedArg != null) {
+ copy[i] = copiedArg;
+ } else {
+ copiedArg = copy(arg, dataBindings[i], dataTypes.get(i));
+ map.put(arg, copiedArg);
+ copy[i] = copiedArg;
+ }
+ }
+ }
+ return copy;
+ }
+
+ /**
+ * Copy data using the specified databinding.
+ * @param data input data
+ * @param dataBinding databinding to use
+ * @param dataType TODO
+ * @return a copy of the data
+ */
+ private Object copy(Object data, DataBinding dataBinding, DataType dataType) {
+ if (data == null) {
+ return null;
+ }
+ Class<?> clazz = data.getClass();
+ if (String.class == clazz || clazz.isPrimitive()
+ || Number.class.isAssignableFrom(clazz)
+ || Boolean.class.isAssignableFrom(clazz)
+ || Character.class.isAssignableFrom(clazz)
+ || Byte.class.isAssignableFrom(clazz)
+ || URI.class == clazz
+ || UUID.class == clazz
+ || QName.class == clazz) {
+ // Immutable classes
+ return data;
+ }
+ // If no databinding was specified, introspect the given arg to
+ // determine its databinding
+ if (dataBinding == null) {
+ dataType = dataBindings.introspectType(data, operation);
+ if (dataType != null) {
+ String db = dataType.getDataBinding();
+ dataBinding = dataBindings.getDataBinding(db);
+ if (dataBinding == null && db != null) {
+ return data;
+ }
+ }
+ if (dataBinding == null) {
+
+ // Default to the JavaBean databinding
+ dataBinding = javaBeanDataBinding;
+ }
+ }
+
+ // Use the JAXB databinding to copy non-Serializable data
+ if (dataBinding == javaBeanDataBinding) {
+
+ // If the input data is an array containing non Serializable elements
+ // use JAXB
+ clazz = data.getClass();
+ if (clazz.isArray()) {
+ if (Array.getLength(data) != 0) {
+ Object element = Array.get(data, 0);
+ if (element != null && !(element instanceof Serializable)) {
+ dataBinding = jaxbDataBinding;
+ }
+ }
+ } else {
+
+ // If the input data is not Serializable use JAXB
+ if (!(data instanceof Serializable)) {
+ dataBinding = jaxbDataBinding;
+ }
+
+ if (data instanceof Cloneable) {
+ Method clone;
+ try {
+ clone = data.getClass().getMethod("clone", (Class[])null);
+ try {
+ return clone.invoke(data, (Object[])null);
+ } catch (InvocationTargetException e) {
+ if (e.getTargetException() instanceof CloneNotSupportedException) {
+ // Ignore
+ } else {
+ throw new ServiceRuntimeException(e);
+ }
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ } catch (NoSuchMethodException e) {
+ // Ignore it
+ }
+ }
+ }
+ }
+
+ Object copy = dataBinding.copy(data, dataType, operation);
+ return copy;
+ }
+
+ public Invoker getNext() {
+ return nextInvoker;
+ }
+
+ public void setNext(Invoker next) {
+ this.nextInvoker = next;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator
new file mode 100644
index 0000000000..baba638c9b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# Implementation class for the ExtensionActivator
+org.apache.tuscany.sca.core.databinding.module.DataBindingModuleActivator
diff --git a/sca-java-1.x/branches/sca-android/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java
new file mode 100644
index 0000000000..b0c39e18ef
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/processor/DataBindingJavaInterfaceProcessorTestCase.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.databinding.processor;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.databinding.DefaultDataBindingExtensionPoint;
+import org.apache.tuscany.sca.databinding.annotation.DataBinding;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.impl.OperationImpl;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.osoa.sca.annotations.Remotable;
+import org.w3c.dom.Node;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataBindingJavaInterfaceProcessorTestCase extends TestCase {
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ }
+
+ /**
+ * @throws InvalidServiceContractException
+ */
+ public final void testVisitInterface() throws InvalidInterfaceException {
+ DataBindingExtensionPoint registry = new DefaultDataBindingExtensionPoint();
+ DataBindingJavaInterfaceProcessor processor = new DataBindingJavaInterfaceProcessor(registry);
+ JavaInterfaceFactory javaFactory = new DefaultJavaInterfaceFactory();
+
+ JavaInterface contract = javaFactory.createJavaInterface();
+ contract.setJavaClass(MockInterface.class);
+ JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract();
+ interfaceContract.setInterface(contract);
+ Operation operation = newOperation("call");
+ Operation operation1 = newOperation("call1");
+ contract.getOperations().add(operation);
+ contract.getOperations().add(operation1);
+ contract.setRemotable(true);
+ processor.visitInterface(contract);
+ // Assert.assertEquals("org.w3c.dom.Node", contract.getDataBinding());
+ // Assert.assertEquals("org.w3c.dom.Node",
+ // contract.getOperations().get("call").getDataBinding());
+ // Assert.assertEquals("xml:string",
+ // contract.getOperations().get("call1").getDataBinding());
+ }
+
+ @DataBinding("org.w3c.dom.Node")
+ @Remotable
+ public static interface MockInterface {
+ Node call(Node msg);
+
+ @DataBinding("xml:string")
+ String call1(String msg);
+ }
+
+ private static Operation newOperation(String name) {
+ Operation operation = new OperationImpl();
+ operation.setName(name);
+ return operation;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/transformers/IDLTransformerTestCaseFIXME.java b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/transformers/IDLTransformerTestCaseFIXME.java
new file mode 100644
index 0000000000..7d49fb7112
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-databinding/src/test/java/org/apache/tuscany/sca/core/databinding/transformers/IDLTransformerTestCaseFIXME.java
@@ -0,0 +1,229 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.databinding.transformers;
+
+//import static org.apache.tuscany.spi.databinding.DataBinding.IDL_INPUT;
+//import static org.apache.tuscany.spi.databinding.DataBinding.IDL_OUTPUT;
+//
+//import java.util.ArrayList;
+//import java.util.List;
+//
+//import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+//import org.apache.tuscany.databinding.impl.DataBindingRegistryImpl;
+//import org.apache.tuscany.databinding.impl.MediatorImpl;
+//import org.apache.tuscany.databinding.impl.TransformationContextImpl;
+//import org.apache.tuscany.databinding.impl.TransformerRegistryImpl;
+//import org.apache.tuscany.databinding.javabeans.DOMNode2JavaBeanTransformer;
+//import org.apache.tuscany.databinding.javabeans.JavaBean2DOMNodeTransformer;
+//import org.apache.tuscany.databinding.xml.DOMDataBinding;
+//import org.apache.tuscany.databinding.xml.Node2String;
+//import org.apache.tuscany.databinding.xml.String2Node;
+//import org.apache.tuscany.interfacedef.DataType;
+//import org.apache.tuscany.interfacedef.Operation;
+//import org.apache.tuscany.interfacedef.impl.DataTypeImpl;
+//import org.apache.tuscany.interfacedef.impl.OperationImpl;
+//import org.apache.tuscany.interfacedef.util.ElementInfo;
+//import org.apache.tuscany.interfacedef.util.TypeInfo;
+//import org.apache.tuscany.interfacedef.util.WrapperInfo;
+//import org.apache.tuscany.interfacedef.util.XMLType;
+//import org.apache.tuscany.spi.databinding.DataBindingRegistry;
+//import org.apache.tuscany.spi.databinding.TransformationContext;
+//import org.apache.tuscany.spi.databinding.extension.DOMHelper;
+//import org.apache.tuscany.spi.databinding.extension.SimpleTypeMapperExtension;
+//import org.w3c.dom.Document;
+//import org.w3c.dom.Element;
+
+public class IDLTransformerTestCaseFIXME extends TestCase {
+// private static final String IPO_XML = "<?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> types0 = new ArrayList<DataType>();
+// DataType<XMLType> wrapperType = new DataTypeImpl<XMLType>(null, Object.class,
+// new XMLType(new QName(URI_ORDER_XSD,
+// "checkOrderStatus"), null));
+// types0.add(wrapperType);
+// DataType<List<DataType>> inputType0 = new DataTypeImpl<List<DataType>>(IDL_INPUT,
+// Object[].class, types0);
+//
+// List<DataType> types1 = new ArrayList<DataType>();
+// DataType<XMLType> customerIdType = new DataTypeImpl<XMLType>(
+// null,
+// Object.class,
+// new XMLType(
+// new QName(URI_ORDER_XSD, "customerId"),
+// null));
+// DataType<XMLType> orderType = new DataTypeImpl<XMLType>(null, Object.class,
+// new XMLType(new QName(URI_ORDER_XSD, "order"), null));
+// DataType<XMLType> flagType = new DataTypeImpl<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 DataTypeImpl<XMLType>(null, Object.class,
+// new XMLType(new QName(URI_ORDER_XSD, "status"), null));
+// DataType<XMLType> responseType = new DataTypeImpl<XMLType>(null, Object.class,
+// new XMLType(new QName(URI_ORDER_XSD,
+// "checkOrderStatusResponse"),
+// null));
+//
+// Operation op = new OperationImpl("checkOrderStatus");
+// op.setInputType(inputType0);
+// op.setOutputType(responseType);
+//// op.setDataBinding(DOMDataBinding.NAME);
+////
+//// inputType0.setOperation(op);
+// op.setWrapperStyle(true);
+// ElementInfo inputElement = new ElementInfo(new QName(URI_ORDER_XSD, "checkOrderStatus"), new TypeInfo(null,
+// false,
+// null));
+//// wrapperType.setMetadata(ElementInfo.class.getName(), inputElement);
+//
+// ElementInfo customerId = new ElementInfo(new QName("", "customerId"),
+// SimpleTypeMapperExtension.XSD_SIMPLE_TYPES.get("string"));
+// ElementInfo order = new ElementInfo(new QName("", "order"), new TypeInfo(new QName(URI_ORDER_XSD), false, null));
+// ElementInfo flag = new ElementInfo(new QName("", "flag"), SimpleTypeMapperExtension.XSD_SIMPLE_TYPES.get("int"));
+//
+//// customerIdType.setMetadata(ElementInfo.class.getName(), customerId);
+//// orderType.setMetadata(ElementInfo.class.getName(), order);
+//// flagType.setMetadata(ElementInfo.class.getName(), flag);
+////
+//// customerIdType.setOperation(op);
+//// orderType.setOperation(op);
+//// flagType.setOperation(op);
+//
+// List<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();
+// context.setSourceOperation(op);
+// List<DataType<Class>> types = new ArrayList<DataType<Class>>();
+// types.add(new DataTypeImpl<Class>(Object.class.getName(), String.class, String.class));
+// types.add(new DataTypeImpl<Class>("java.lang.String", String.class, String.class));
+// types.add(new DataTypeImpl<Class>(Object.class.getName(), int.class, int.class));
+// DataType<List<DataType<Class>>> inputType1 = new DataTypeImpl<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 DataTypeImpl<DataType>(IDL_OUTPUT, Object.class, op.getOutputType());
+//
+// context1.setSourceDataType(sourceType);
+// DataType<DataType> targetType = new DataTypeImpl<DataType>(IDL_OUTPUT, Object.class,
+// new DataTypeImpl<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/sca-java-1.x/branches/sca-android/modules/core-spi/LICENSE b/sca-java-1.x/branches/sca-android/modules/core-spi/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/META-INF/README b/sca-java-1.x/branches/sca-android/modules/core-spi/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/NOTICE b/sca-java-1.x/branches/sca-android/modules/core-spi/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/pom.xml b/sca-java-1.x/branches/sca-android/modules/core-spi/pom.xml
new file mode 100644
index 0000000000..6246686d08
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/pom.xml
@@ -0,0 +1,116 @@
+<?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.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-core-spi</artifactId>
+ <name>Apache Tuscany SCA Core SPI</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-extensibility</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-sca-api</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-definitions</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-policy</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-interface</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>compile</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.5</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ <version>3.2.1</version>
+ <scope>runtime</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ </dependencies>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.core.spi</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/doc/Context Model.emx b/sca-java-1.x/branches/sca-android/modules/core-spi/src/doc/Context Model.emx
new file mode 100644
index 0000000000..0445ea5a6b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-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/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ComponentContextFactory.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ComponentContextFactory.java
new file mode 100644
index 0000000000..ed4b57639c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ComponentContextFactory.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.context;
+
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.osoa.sca.ComponentContext;
+
+/**
+ * Interface implemented by the provider of the ComponentContext.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ComponentContextFactory {
+ /**
+ * Create an instance of ComponentContext
+ *
+ * @param component The runtime component
+ * @param requestContextFactory The factory to create RequestContext
+ * @return An instance of ComponentContext for the component
+ */
+ ComponentContext createComponentContext(RuntimeComponent component, RequestContextFactory requestContextFactory);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ContextFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ContextFactoryExtensionPoint.java
new file mode 100644
index 0000000000..e92a8f2844
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ContextFactoryExtensionPoint.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.context;
+
+/**
+ * An extension point for context factories.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ContextFactoryExtensionPoint {
+
+ /**
+ * Add a context factory extension.
+ *
+ * @param factory The factory to add
+ */
+ void addFactory(Object factory);
+
+ /**
+ * Remove a context factory extension.
+ *
+ * @param factory The factory to remove
+ */
+ void removeFactory(Object factory);
+
+ /**
+ * Get a factory implementing the given interface.
+ * @param factoryInterface the lookup key (factory interface)
+ * @return The factory
+ */
+ <T> T getFactory(Class<T> factoryInterface);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPoint.java
new file mode 100644
index 0000000000..5a0aefe55d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPoint.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.context;
+
+import java.lang.reflect.Constructor;
+import java.util.HashMap;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+
+/**
+ * Default implementation of a model factory extension point.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultContextFactoryExtensionPoint implements ContextFactoryExtensionPoint {
+
+ /**
+ * The Map of Factories that have been registered.
+ */
+ private HashMap<Class<?>, Object> factories = new HashMap<Class<?>, Object>();
+
+ private ExtensionPointRegistry registry;
+
+ public DefaultContextFactoryExtensionPoint(ExtensionPointRegistry registry) {
+ this.registry = registry;
+ }
+
+ /**
+ * Add a model factory extension.
+ *
+ * @param factory The factory to add.
+ * @throws IllegalArgumentException if factory is null
+ */
+ public void addFactory(Object factory) throws IllegalArgumentException {
+ if (factory == null) {
+ throw new IllegalArgumentException("Cannot add null as a factory");
+ }
+
+ Class<?>[] interfaces = factory.getClass().getInterfaces();
+ for (int i = 0; i<interfaces.length; i++) {
+ factories.put(interfaces[i], factory);
+ }
+ }
+
+ /**
+ * Remove a model factory extension.
+ *
+ * @param factory The factory to remove
+ * @throws IllegalArgumentException if factory is null
+ */
+ public void removeFactory(Object factory) throws IllegalArgumentException {
+ if (factory == null) {
+ throw new IllegalArgumentException("Cannot remove null as a factory");
+ }
+
+ Class<?>[] interfaces = factory.getClass().getInterfaces();
+ for (int i = 0; i<interfaces.length; i++) {
+ factories.remove(interfaces[i]);
+ }
+ }
+
+ /**
+ * Get a factory implementing the given interface.
+ *
+ * @param factoryInterface The lookup key (factory interface)
+ * @return The factory
+ */
+ public <T> T getFactory(Class<T> factoryInterface) throws IllegalArgumentException {
+ if (factoryInterface == null) {
+ throw new IllegalArgumentException("Cannot get null as a factory");
+ }
+
+ Object factory = factories.get(factoryInterface);
+ if (factory == null) {
+
+ // Dynamically load a factory class declared under META-INF/services
+ try {
+ Class<?> factoryClass = ServiceDiscovery.getInstance().loadFirstServiceClass(factoryInterface);
+ if (factoryClass != null) {
+
+ // Default empty constructor
+ Constructor<?> constructor = factoryClass.getConstructor(ExtensionPointRegistry.class);
+ factory = constructor.newInstance(registry);
+
+ // Cache the loaded factory
+ addFactory(factory);
+ }
+ } catch (Exception e) {
+ throw new IllegalArgumentException(e);
+ }
+
+ }
+
+ return factoryInterface.cast(factory);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/PropertyValueFactory.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/PropertyValueFactory.java
new file mode 100644
index 0000000000..9766e164b8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/PropertyValueFactory.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.context;
+
+import org.apache.tuscany.sca.assembly.ComponentProperty;
+
+/**
+ * Interface implemented by the provider of the property values
+ *
+ * @version $Rev$ $Date$
+ */
+public interface PropertyValueFactory {
+
+ /**
+ * This method will create an instance of the value for the specified Property.
+ *
+ * @param property The Property from which to retrieve the property value
+ * @param type The type of the property value being retrieved from the Property
+ * @param <B> Type type of the property value being looked up
+ *
+ * @return the value for the Property
+ */
+ <B> B createPropertyValue(ComponentProperty property, Class<B> type);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/RequestContextFactory.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/RequestContextFactory.java
new file mode 100644
index 0000000000..546757c766
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/RequestContextFactory.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.context;
+
+import org.osoa.sca.RequestContext;
+
+/**
+ * Interface implemented by the provider of the RequestContext.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface RequestContextFactory {
+ /**
+ * @return An instance of RequestContext for the current invocation
+ */
+ RequestContext createRequestContext();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/DefaultEndpointResolverFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/DefaultEndpointResolverFactoryExtensionPoint.java
new file mode 100644
index 0000000000..2849c27c1a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/DefaultEndpointResolverFactoryExtensionPoint.java
@@ -0,0 +1,180 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.endpointresolver;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+
+/**
+ * Default implementation of a provider factory extension point.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultEndpointResolverFactoryExtensionPoint implements EndpointResolverFactoryExtensionPoint {
+
+ private ExtensionPointRegistry registry;
+ private final Map<Class<?>, EndpointResolverFactory> endpointResolverFactories = new HashMap<Class<?>, EndpointResolverFactory>();
+ private boolean loaded;
+
+ /**
+ * The default constructor. Does nothing.
+ *
+ */
+ public DefaultEndpointResolverFactoryExtensionPoint(ExtensionPointRegistry registry) {
+ this.registry = registry;
+ }
+
+ /**
+ * Add an endpoint resolver factory.
+ *
+ * @param endpointResolverFactory The resolver factory
+ */
+ public void addEndpointResolverFactory(EndpointResolverFactory endpointResolverFactory){
+ endpointResolverFactories.put(endpointResolverFactory.getModelType(), endpointResolverFactory);
+ }
+
+ /**
+ * Remove a endpoint resolver factory.
+ *
+ * @param endpointResolverFactory The endpoint resolver factory
+ */
+ public void removeEndpointResolverFactory(EndpointResolverFactory endpointResolverFactory){
+ endpointResolverFactories.remove(endpointResolverFactory.getModelType());
+ }
+
+ /**
+ * Returns the provider factory associated with the given model type.
+ * @param modelType A model type
+ * @return The provider factory associated with the given model type
+ */
+ public EndpointResolverFactory getEndpointResolverFactory(Class<?> modelType) {
+ loadProviderFactories();
+
+ Class<?>[] classes = modelType.getInterfaces();
+ for (Class<?> c : classes) {
+ EndpointResolverFactory factory = endpointResolverFactories.get(c);
+ if (factory != null) {
+ return factory;
+ }
+ }
+ return endpointResolverFactories.get(modelType);
+ }
+
+
+ /**
+ * Load provider factories declared under META-INF/services.
+ * @param registry
+ */
+ private void loadProviderFactories() {
+ if (loaded)
+ return;
+
+ // Get the provider factory service declarations
+ Set<ServiceDeclaration> factoryDeclarations;
+ ServiceDiscovery serviceDiscovery = ServiceDiscovery.getInstance();
+ try {
+ factoryDeclarations = serviceDiscovery.getServiceDeclarations(EndpointResolverFactory.class);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+
+ // Get the extension point
+ EndpointResolverFactoryExtensionPoint factoryExtensionPoint =
+ registry.getExtensionPoint(EndpointResolverFactoryExtensionPoint.class);
+ List<EndpointResolverFactory> factories = new ArrayList<EndpointResolverFactory>();
+
+ for (ServiceDeclaration factoryDeclaration : factoryDeclarations) {
+ Map<String, String> attributes = factoryDeclaration.getAttributes();
+
+ // Find the model type that identifies this resolver
+ String modelTypeName = attributes.get("model");
+
+ // Create a provider factory wrapper and register it
+ EndpointResolverFactory factory =
+ new LazyEndpointResolverFactory(registry, modelTypeName, factoryDeclaration);
+ factoryExtensionPoint.addEndpointResolverFactory(factory);
+ factories.add(factory);
+ }
+
+ loaded = true;
+ }
+
+ /**
+ * A wrapper around an endpoint provider factory allowing lazy
+ * loading and initialization of endpoint providers.
+ */
+ private class LazyEndpointResolverFactory implements EndpointResolverFactory {
+ private ExtensionPointRegistry registry;
+ private String modelTypeName;
+ private ServiceDeclaration providerClass;
+ private EndpointResolverFactory factory;
+ private Class modelType;
+
+ private LazyEndpointResolverFactory(ExtensionPointRegistry registry,
+ String modelTypeName,
+ ServiceDeclaration providerClass) {
+ this.registry = registry;
+ this.modelTypeName = modelTypeName;
+ this.providerClass = providerClass;
+ }
+
+ @SuppressWarnings("unchecked")
+ private EndpointResolverFactory getFactory() {
+ if (factory == null) {
+ try {
+ Class<EndpointResolverFactory> factoryClass = (Class<EndpointResolverFactory>)providerClass.loadClass();
+ Constructor<EndpointResolverFactory> constructor =
+ factoryClass.getConstructor(ExtensionPointRegistry.class);
+ factory = constructor.newInstance(registry);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return factory;
+ }
+
+ public EndpointResolver createEndpointResolver(Endpoint endpoint, Binding binding) {
+ return getFactory().createEndpointResolver(endpoint, binding);
+ }
+
+ public Class getModelType() {
+ if (modelType == null) {
+ try {
+ modelType = providerClass.loadClass(modelTypeName);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return modelType;
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolver.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolver.java
new file mode 100644
index 0000000000..79a10f6d84
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolver.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.endpointresolver;
+
+
+/**
+ * A reference binding implementation can options implement this
+ * interface to tie into the Tuscany SCA runtime
+ *
+ * @version $Rev$ $Date$
+ */
+public interface EndpointResolver {
+
+ /**
+ * This method will be invoked when the endpoint is
+ * activated. It gives the resolver the opportunity
+ * to do any set up ready for when it is asked to
+ * resolve the endpoint when a message arrives
+ */
+ void start();
+
+ /**
+ * This method will be invoked when the endpoint is
+ * to be resolved. The resolver will attempt to resolve the
+ * endpoint against available services. The resolvers extending
+ * this interface will provide environment or binding specific
+ * resolution processing
+ */
+ void resolve();
+
+ /**
+ * This method will be invoked when the endpont is
+ * deactivated. It gives the resolver the opportunity
+ * to take and required resolver shutdown actions
+ */
+ void stop();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolverFactory.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolverFactory.java
new file mode 100644
index 0000000000..fdd304a9c7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolverFactory.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.endpointresolver;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Endpoint;
+
+/**
+ * A factory for creating the runtime artifacts that resolve endpoints.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface EndpointResolverFactory <M>{
+
+ /**
+ * Creates a new endpoint resolver for the given component,
+ * reference and binding.
+ *
+ * @param component The runtime component
+ * @param reference The reference on the runtime component
+ * @param enpoint The endpoint assembly model object
+ * @return The endpoint provider
+ */
+ EndpointResolver createEndpointResolver(Endpoint endpoint, Binding binding);
+
+ Class<M> getModelType();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolverFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolverFactoryExtensionPoint.java
new file mode 100644
index 0000000000..be55981131
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/endpointresolver/EndpointResolverFactoryExtensionPoint.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.endpointresolver;
+
+import java.util.List;
+
+
+/**
+ * An extension point for resolver factories. Holds all of the resolver
+ * factories from loaded extension points. Allows a resolver factory
+ * to be located based on a given model type. Hence the runtime can
+ * generate endpoint resolvers from the in memory assembly model.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface EndpointResolverFactoryExtensionPoint {
+
+
+ /**
+ * Add an endpoint resolver factory.
+ *
+ * @param endpointResolverFactory The resolver factory
+ */
+ void addEndpointResolverFactory(EndpointResolverFactory endpointResolverFactory);
+
+ /**
+ * Remove a endpoint resolver factory.
+ *
+ * @param endpointResolverFactory The endpoint resolver factory
+ */
+ void removeEndpointResolverFactory(EndpointResolverFactory endpointResolverFactory);
+
+ /**
+ * Returns the endpoint resolver factory associated with the given binding type.
+ * @param bindingType A binding type
+ * @return The endpoint resolver factory associated with the given binding type
+ */
+ EndpointResolverFactory getEndpointResolverFactory(Class<?> bindingType);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/Event.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/Event.java
new file mode 100644
index 0000000000..992c1188f7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/Event.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.event;
+
+/**
+ * The base interface for events that are propagated in the runtime
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Event {
+
+ /**
+ * Returns the source of the event
+ */
+ Object getSource();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventFilter.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventFilter.java
new file mode 100644
index 0000000000..d17aebd7e8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventFilter.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.event;
+
+/**
+ * Evaluates whether a {@link RuntimeEventListener} is applicable to a given runtime event
+ *
+ * @version $Rev$ $Date$
+ */
+public interface EventFilter {
+
+ /**
+ * Performs the actual evaluation on an event
+ * @param event Returns true if the event matches implemented criteria
+ * @return Match result
+ */
+ boolean match(Event event);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventPublisher.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventPublisher.java
new file mode 100644
index 0000000000..f209eb8936
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/EventPublisher.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.event;
+
+/**
+ * Publishes events in the runtime by accepting {@link Event} objects and
+ * forwarding them to all registered {@link RuntimeEventListener} objects.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface EventPublisher {
+
+ /**
+ * Publish an event to all registered listeners
+ * @param object The event to publish
+ */
+ void publish(Event object);
+
+ /**
+ * Registers a listener to receive notifications for the context
+ * @param listener The listener to add
+ */
+ void addListener(RuntimeEventListener listener);
+
+ /**
+ * Registers a listener to receive notifications for the context
+ * @param filter The filter that will be applied before the lister is called
+ * @param listener The lister to add
+ */
+ void addListener(EventFilter filter, RuntimeEventListener listener);
+
+
+ /**
+ * Removes a previously registered listener
+ * @param listener The listener to remove
+ */
+ void removeListener(RuntimeEventListener listener);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/RuntimeEventListener.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/RuntimeEventListener.java
new file mode 100644
index 0000000000..b34dceee62
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/RuntimeEventListener.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.event;
+
+import java.util.EventListener;
+
+/**
+ * Listeners observe events fired in the SCA runtime.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface RuntimeEventListener extends EventListener {
+
+ /**
+ * Accepts and event and acts on it
+ * @param event The event to act on
+ */
+ void onEvent(Event event);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/TrueFilter.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/TrueFilter.java
new file mode 100644
index 0000000000..f888908340
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/event/TrueFilter.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.event;
+
+/**
+ * An event filter that always returns a true condition
+ *
+ * @version $Rev$ $Date$
+ */
+public class TrueFilter implements EventFilter {
+
+ /**
+ * Performs the actual evaluation on an event. Always returns true
+ * in this case
+ * @param event The incoming event which is ignored
+ * @return true
+ */
+ public boolean match(Event event) {
+ return true;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/DataExchangeSemantics.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/DataExchangeSemantics.java
new file mode 100644
index 0000000000..957a15ce8a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/DataExchangeSemantics.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.invocation;
+
+/**
+ * An invoker or interceptor can optionally implement this interface to indicate if they can
+ * enforce the pass-by-value semantics for an operation on remotable interfaces.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface DataExchangeSemantics {
+ /**
+ * Indicate if the data can be passed in by reference as they won't be mutated.
+ * @return true if pass-by-reference is allowed
+ */
+ boolean allowsPassByReference();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Interceptor.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Interceptor.java
new file mode 100644
index 0000000000..a5f221fc11
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Interceptor.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.invocation;
+
+/**
+ * Synchronous mediation associated with a client- or target- side wire.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Interceptor extends Invoker {
+
+ /**
+ * Sets the next invoker
+ * @param next The next invoker
+ */
+ void setNext(Invoker next);
+
+ /**
+ * Returns the next invoker or null
+ * @return The next Invoker
+ */
+ Invoker getNext();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.java
new file mode 100644
index 0000000000..75719bb0cc
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/InvocationChain.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.invocation;
+
+import org.apache.tuscany.sca.interfacedef.Operation;
+
+/**
+ * A wire consists of 1..n invocation chains associated with the operations of its source service contract.
+ * <p/>
+ * Invocation chains may contain <code>Interceptors</code> that process invocations.
+ * <p/>
+ * A <code>Message</code> is used to pass data associated with an invocation through the chain.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface InvocationChain {
+ /**
+ * Returns the target operation for this invocation chain.
+ *
+ * @return The target operation for this invocation chain
+ */
+ Operation getTargetOperation();
+
+ /**
+ * Updates the target operation for this invocation chain.
+ *
+ * @param operation The new target operation for this invocation chain
+ */
+ void setTargetOperation(Operation operation);
+
+ /**
+ * Returns the source operation for this invocation chain.
+ *
+ * @return The source operation for this invocation chain
+ */
+ Operation getSourceOperation();
+
+ /**
+ * Adds an interceptor to the chain. For reference side, it will be added to
+ * Phase.REFERENCE. For service side, it will be added to Phase.SERVICE
+ *
+ * @param interceptor The interceptor to add
+ */
+ void addInterceptor(Interceptor interceptor);
+
+ /**
+ * Adds an invoker to the chain
+ *
+ * @param invoker The invoker to add
+ */
+ void addInvoker(Invoker invoker);
+
+ /**
+ * Returns the first invoker in the chain.
+ *
+ * @return The first invoker in the chain
+ */
+ Invoker getHeadInvoker();
+
+ /**
+ * @deprecated This method is not used
+ * Returns the last invoker in the chain.
+ *
+ * @return The last invoker in the chain
+ */
+ @Deprecated
+ Invoker getTailInvoker();
+
+ /**
+ * @deprecated Please use <code>void addInterceptor(String phase, Interceptor interceptor);</code>
+ * Adds an interceptor at the given position in the interceptor stack
+ *
+ * @param index The position in the interceptor stack to add the interceptor
+ * @param interceptor The interceptor to add
+ */
+ @Deprecated
+ void addInterceptor(int index, Interceptor interceptor);
+
+ /**
+ * Add an interceptor to the given phase
+ * @param phase
+ * @param interceptor
+ */
+ void addInterceptor(String phase, Interceptor interceptor);
+
+ /**
+ * Indicate if the data can be passed in by reference as they won't be mutated.
+ * @return true if pass-by-reference is allowed
+ */
+ boolean allowsPassByReference();
+ /**
+ * Force the invocation to allow pass-by-reference
+ * @param allowsPBR
+ */
+ void setAllowsPassByReference(boolean allowsPBR);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Invoker.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Invoker.java
new file mode 100644
index 0000000000..2748bbed9a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Invoker.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.invocation;
+
+/**
+ * Synchronous mediation associated with a client- or target- side wire.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Invoker {
+
+ /**
+ * Process a synchronous wire
+ *
+ * @param msg The request Message for the wire
+ * @return The response Message from the wire
+ */
+ Message invoke(Message msg);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Message.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Message.java
new file mode 100644
index 0000000000..a727693132
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Message.java
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.invocation;
+
+import java.util.Map;
+
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+
+/**
+ * Represents a request, response, or exception flowing through a wire
+ *
+ * @version $Rev $Date$
+ */
+public interface Message {
+ String QOS_CTX_SECURITY_PRINCIPAL = "PRINCIPAL";
+
+ /**
+ * Returns the body of the message, which will be the payload or parameters associated with the wire
+ * @return The body of the message
+ */
+ <T> T getBody();
+
+ /**
+ * Sets the body of the message.
+ * @param body The body of the message
+ */
+ <T> void setBody(T body);
+
+ /**
+ * Get the end point reference of the source reference
+ * @return The end point reference of the reference originating the message
+ */
+ EndpointReference getFrom();
+
+ /**
+ * Set the end point reference of the reference originating the message
+ * @param from The end point reference of the reference originating the message
+ */
+ void setFrom(EndpointReference from);
+
+ /**
+ * Get the end point reference of target service
+ * @return The end point reference of the service that the message targets
+ */
+ EndpointReference getTo();
+
+ /**
+ * Set the end point reference of target service
+ * @param to The end point reference of the service that the message targets
+ */
+ void setTo(EndpointReference to);
+
+ /**
+ * Returns the id of the message
+ * @return The message Id
+ */
+ Object getMessageID();
+
+ /**
+ * Sets the id of the message
+ * @param messageId The message ID
+ */
+ void setMessageID(Object messageId);
+
+ /**
+ * Determines if the message represents a fault/exception
+ *
+ * @return true If the message body is a fault object, false if the body is a normal payload
+ */
+ boolean isFault();
+
+ /**
+ * Set the message body with a fault object. After this method is called, isFault() returns true.
+ *
+ * @param fault The fault object represents an exception
+ */
+ <T> void setFaultBody(T fault);
+
+ /**
+ * Returns the operation that created the message.
+ *
+ * @return The operation that created the message
+ */
+ Operation getOperation();
+
+ /**
+ * Sets the operation that created the message.
+ *
+ * @param op The operation that created the message
+ */
+ void setOperation(Operation op);
+
+ /**
+ * Returns a map of objects that represents the QoS context that wraps this message such as
+ * invoking authenticated principal and so on.
+ *
+ * @return
+ */
+ Map<String, Object> getQoSContext();
+
+ /**
+ * Returns a map of objects that are contained in the message header
+ *
+ * @return
+ */
+ Map<String, Object> getHeader();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/MessageFactory.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/MessageFactory.java
new file mode 100644
index 0000000000..38c900e36a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/MessageFactory.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.invocation;
+
+
+/**
+ * A factory for messages
+ *
+ * @version $Rev $Date$
+ */
+public interface MessageFactory {
+
+ /**
+ * Creates a new message.
+ *
+ * @return The new message
+ */
+ Message createMessage();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Phase.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Phase.java
new file mode 100644
index 0000000000..2deb273f84
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/invocation/Phase.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.invocation;
+
+/**
+ * Tuscany built-in phases for the invocation chain
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Phase {
+ // The first phase for outgoing invocations via a reference
+ String REFERENCE = "component.reference";
+
+ // data transformation and validation
+ String REFERENCE_INTERFACE = "reference.interface";
+
+ // reference policy handling
+ String REFERENCE_POLICY = "reference.policy";
+
+ // reference binding invoker
+ String REFERENCE_BINDING = "reference.binding";
+
+ // The first phase for incoming invocations via a service
+ String SERVICE_BINDING = "service.binding";
+
+ // service policy handling
+ String SERVICE_POLICY = "service.policy";
+
+ // data validation and transformation
+ String SERVICE_INTERFACE = "service.interface";
+
+ // TODO: not sure if we need to have this face
+ String SERVICE = "component.service";
+
+ // implementation policy handling
+ String IMPLEMENTATION_POLICY = "implementation.policy";
+
+ // implementation invoker
+ String IMPLEMENTATION = "component.implementation";
+
+ // String getName();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/management/ManagementService.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/management/ManagementService.java
new file mode 100644
index 0000000000..3887db4873
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/management/ManagementService.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.management;
+
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * Interface for the management service abstraction. The implementation
+ * could be based on a variety of technologies including JMX, WSDM,
+ * SNMP etc.
+ *
+ * @version $Revision$ $Date$
+ */
+public interface ManagementService {
+
+ /**
+ * Registers a component for management.
+ *
+ * @param name Name of the component.
+ * @param component Component to be registered.
+ */
+ void registerComponent(String name, RuntimeComponent component);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BindingProviderFactory.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BindingProviderFactory.java
new file mode 100644
index 0000000000..0f6a932c51
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/BindingProviderFactory.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.provider;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+/**
+ * A factory for creating the runtime artifacts that represent bindings.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface BindingProviderFactory<M extends Binding> extends ProviderFactory<M> {
+
+ /**
+ * Creates a new reference binding provider for the given component and
+ * reference.
+ *
+ * @param component The runtime component
+ * @param reference The reference on the runtime component
+ * @param binding The binding assembly model object
+ * @return The binding provider
+ */
+ ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component,
+ RuntimeComponentReference reference,
+ M binding);
+
+ /**
+ * Creates a new service binding provider for the given component and
+ * service.
+ *
+ * @param component The runtime component
+ * @param service The service on the runtime component
+ * @param binding The binding assembly model object
+ * @return The binding provider
+ */
+ ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component,
+ RuntimeComponentService service,
+ M binding);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java
new file mode 100644
index 0000000000..dfc3ddb468
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java
@@ -0,0 +1,362 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.provider;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+/**
+ * Default implementation of a provider factory extension point.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultProviderFactoryExtensionPoint implements ProviderFactoryExtensionPoint {
+
+ private ExtensionPointRegistry registry;
+ private final Map<Class<?>, ProviderFactory> providerFactories = new HashMap<Class<?>, ProviderFactory>();
+ private final List<PolicyProviderFactory> policyProviderFactories = new ArrayList<PolicyProviderFactory>();
+ private boolean loaded;
+
+ /**
+ * The default constructor. Does nothing.
+ *
+ */
+ public DefaultProviderFactoryExtensionPoint(ExtensionPointRegistry registry) {
+ this.registry = registry;
+ }
+
+ /**
+ * Add a provider factory.
+ *
+ * @param providerFactory The provider factory
+ */
+ public void addProviderFactory(ProviderFactory providerFactory) {
+ if(providerFactory instanceof PolicyProviderFactory) {
+ policyProviderFactories.add((PolicyProviderFactory)providerFactory);
+ }
+ providerFactories.put(providerFactory.getModelType(), providerFactory);
+ }
+
+ /**
+ * Remove a provider factory.
+ *
+ * @param providerFactory The provider factory
+ */
+ public void removeProviderFactory(ProviderFactory providerFactory) {
+ if(providerFactory instanceof PolicyProviderFactory) {
+ policyProviderFactories.remove((PolicyProviderFactory)providerFactory);
+ }
+ providerFactories.remove(providerFactory.getModelType());
+ }
+
+ /**
+ * Returns the provider factory associated with the given model type.
+ * @param modelType A model type
+ * @return The provider factory associated with the given model type
+ */
+ public ProviderFactory getProviderFactory(Class<?> modelType) {
+ loadProviderFactories();
+
+ Class<?>[] classes = modelType.getInterfaces();
+ for (Class<?> c : classes) {
+ ProviderFactory factory = providerFactories.get(c);
+ if (factory != null) {
+ return factory;
+ }
+ }
+ return providerFactories.get(modelType);
+ }
+
+ public List<PolicyProviderFactory> getPolicyProviderFactories() {
+ loadProviderFactories();
+ return policyProviderFactories;
+ }
+
+ /**
+ * Load provider factories declared under META-INF/services.
+ * @param registry
+ */
+ private void loadProviderFactories() {
+ if (loaded)
+ return;
+
+ loadProviderFactories(BindingProviderFactory.class);
+ loadProviderFactories(ImplementationProviderFactory.class);
+ loadProviderFactories(PolicyProviderFactory.class);
+
+ loaded = true;
+ }
+
+ /**
+ * Load provider factories declared under META-INF/services.
+ * @param registry
+ * @param factoryClass
+ * @return
+ */
+ private List<ProviderFactory> loadProviderFactories(Class<?> factoryClass) {
+
+ // Get the provider factory service declarations
+ Set<ServiceDeclaration> factoryDeclarations;
+ ServiceDiscovery serviceDiscovery = ServiceDiscovery.getInstance();
+ try {
+ factoryDeclarations = serviceDiscovery.getServiceDeclarations(factoryClass);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+
+ // Get the target extension point
+ ProviderFactoryExtensionPoint factoryExtensionPoint =
+ registry.getExtensionPoint(ProviderFactoryExtensionPoint.class);
+ List<ProviderFactory> factories = new ArrayList<ProviderFactory>();
+
+ for (ServiceDeclaration factoryDeclaration : factoryDeclarations) {
+ Map<String, String> attributes = factoryDeclaration.getAttributes();
+
+ // Load an implementation provider factory
+ if (factoryClass == ImplementationProviderFactory.class) {
+ String modelTypeName = attributes.get("model");
+
+ // Create a provider factory wrapper and register it
+ ImplementationProviderFactory factory =
+ new LazyImplementationProviderFactory(registry, modelTypeName, factoryDeclaration);
+ factoryExtensionPoint.addProviderFactory(factory);
+ factories.add(factory);
+
+ } else if (factoryClass == BindingProviderFactory.class) {
+
+ // Load a binding provider factory
+ String modelTypeName = attributes.get("model");
+
+ // Create a provider factory wrapper and register it
+ BindingProviderFactory factory =
+ new LazyBindingProviderFactory(registry, modelTypeName, factoryDeclaration);
+ factoryExtensionPoint.addProviderFactory(factory);
+ factories.add(factory);
+ } else if (factoryClass == PolicyProviderFactory.class) {
+ // Load a policy provider factory
+ String modelTypeName = attributes.get("model");
+
+ // Create a provider factory wrapper and register it
+ PolicyProviderFactory factory =
+ new LazyPolicyProviderFactory(registry, modelTypeName, factoryDeclaration);
+ factoryExtensionPoint.addProviderFactory(factory);
+ factories.add(factory);
+ }
+ }
+ return factories;
+ }
+
+ /**
+ * A wrapper around an implementation provider factory allowing lazy
+ * loading and initialization of implementation providers.
+ */
+ private static class LazyBindingProviderFactory implements BindingProviderFactory {
+
+ private ExtensionPointRegistry registry;
+ private String modelTypeName;
+ private ServiceDeclaration factoryDeclaration;
+ private BindingProviderFactory factory;
+ private Class modelType;
+
+ private LazyBindingProviderFactory(ExtensionPointRegistry registry,
+ String modelTypeName,
+ ServiceDeclaration factoryDeclaration) {
+ this.registry = registry;
+ this.modelTypeName = modelTypeName;
+ this.factoryDeclaration = factoryDeclaration;
+ }
+
+ @SuppressWarnings("unchecked")
+ private BindingProviderFactory getFactory() {
+ if (factory == null) {
+ try {
+ Class<BindingProviderFactory> factoryClass =
+ (Class<BindingProviderFactory>)factoryDeclaration.loadClass();
+ Constructor<BindingProviderFactory> constructor =
+ factoryClass.getConstructor(ExtensionPointRegistry.class);
+ factory = constructor.newInstance(registry);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return factory;
+ }
+
+ @SuppressWarnings("unchecked")
+ public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component,
+ RuntimeComponentReference reference,
+ Binding binding) {
+ return getFactory().createReferenceBindingProvider(component, reference, binding);
+ }
+
+ @SuppressWarnings("unchecked")
+ public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component,
+ RuntimeComponentService service,
+ Binding binding) {
+ return getFactory().createServiceBindingProvider(component, service, binding);
+ }
+
+ public Class getModelType() {
+ if (modelType == null) {
+ try {
+ modelType = factoryDeclaration.loadClass(modelTypeName);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return modelType;
+ }
+
+ }
+
+ /**
+ * A wrapper around an implementation provider factory allowing lazy
+ * loading and initialization of implementation providers.
+ */
+ private class LazyImplementationProviderFactory implements ImplementationProviderFactory {
+
+ private ExtensionPointRegistry registry;
+ private String modelTypeName;
+ private ServiceDeclaration providerClass;
+ private ImplementationProviderFactory factory;
+ private Class modelType;
+
+ private LazyImplementationProviderFactory(ExtensionPointRegistry registry,
+ String modelTypeName,
+ ServiceDeclaration providerClass) {
+ this.registry = registry;
+ this.modelTypeName = modelTypeName;
+ this.providerClass = providerClass;
+ }
+
+ @SuppressWarnings("unchecked")
+ private ImplementationProviderFactory getFactory() {
+ if (factory == null) {
+ try {
+ Class<ImplementationProviderFactory> factoryClass =
+ (Class<ImplementationProviderFactory>)providerClass.loadClass();
+ Constructor<ImplementationProviderFactory> constructor =
+ factoryClass.getConstructor(ExtensionPointRegistry.class);
+ factory = constructor.newInstance(registry);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return factory;
+ }
+
+ @SuppressWarnings("unchecked")
+ public ImplementationProvider createImplementationProvider(RuntimeComponent component,
+ Implementation Implementation) {
+ return getFactory().createImplementationProvider(component, Implementation);
+ }
+
+ public Class getModelType() {
+ if (modelType == null) {
+ try {
+
+ modelType = providerClass.loadClass(modelTypeName);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return modelType;
+ }
+
+ }
+
+ /**
+ * A wrapper around an policy provider factory allowing lazy
+ * loading and initialization of policy providers.
+ */
+ private class LazyPolicyProviderFactory implements PolicyProviderFactory {
+ private ExtensionPointRegistry registry;
+ private String modelTypeName;
+ private ServiceDeclaration providerClass;
+ private PolicyProviderFactory factory;
+ private Class modelType;
+
+ private LazyPolicyProviderFactory(ExtensionPointRegistry registry,
+ String modelTypeName,
+ ServiceDeclaration providerClass) {
+ this.registry = registry;
+ this.modelTypeName = modelTypeName;
+ this.providerClass = providerClass;
+ }
+
+ @SuppressWarnings("unchecked")
+ private PolicyProviderFactory getFactory() {
+ if (factory == null) {
+ try {
+ Class<PolicyProviderFactory> factoryClass = (Class<PolicyProviderFactory>)providerClass.loadClass();
+ Constructor<PolicyProviderFactory> constructor =
+ factoryClass.getConstructor(ExtensionPointRegistry.class);
+ factory = constructor.newInstance(registry);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return factory;
+ }
+
+ public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component,
+ Implementation implementation) {
+ return getFactory().createImplementationPolicyProvider(component, implementation);
+ }
+
+ public PolicyProvider createReferencePolicyProvider(RuntimeComponent component,
+ RuntimeComponentReference reference,
+ Binding binding) {
+ return getFactory().createReferencePolicyProvider(component, reference, binding);
+ }
+
+ public PolicyProvider createServicePolicyProvider(RuntimeComponent component,
+ RuntimeComponentService service,
+ Binding binding) {
+ return getFactory().createServicePolicyProvider(component, service, binding);
+ }
+
+ public Class getModelType() {
+ if (modelType == null) {
+ try {
+ modelType = providerClass.loadClass(modelTypeName);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return modelType;
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultSCADefinitionsProviderExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultSCADefinitionsProviderExtensionPoint.java
new file mode 100644
index 0000000000..068d0d12d7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultSCADefinitionsProviderExtensionPoint.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.provider;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+
+/**
+ * Concrete Implementation for the SCADefinitionsProviderExtensionPoint
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultSCADefinitionsProviderExtensionPoint implements
+ SCADefinitionsProviderExtensionPoint {
+
+ private ExtensionPointRegistry extensionPointRegistry = null;
+
+ private List<SCADefinitionsProvider> scaDefnsProviders = new ArrayList<SCADefinitionsProvider>();
+
+ public DefaultSCADefinitionsProviderExtensionPoint(ExtensionPointRegistry extnPtReg) {
+ this.extensionPointRegistry = extnPtReg;
+ }
+
+ public void addSCADefinitionsProvider(SCADefinitionsProvider provider) {
+ scaDefnsProviders.add(provider);
+ }
+
+ public void removeSCADefinitionsProvider(SCADefinitionsProvider provider) {
+ scaDefnsProviders.remove(provider);
+ }
+
+ public List<SCADefinitionsProvider> getSCADefinitionsProviders() {
+ if (scaDefnsProviders.isEmpty()) {
+ loadProviders();
+ }
+ return scaDefnsProviders;
+ }
+
+ private void loadProviders() {
+ // Get the provider service declarations
+ Set<ServiceDeclaration> defnProviderDecls;
+ SCADefinitionsProvider aProvider = null;
+ Class providerClass = null;
+ Constructor constructor = null;
+
+ try {
+ defnProviderDecls =
+ ServiceDiscovery.getInstance().getServiceDeclarations(SCADefinitionsProvider.class);
+
+ for (ServiceDeclaration aDefnProviderDecl : defnProviderDecls) {
+ providerClass = aDefnProviderDecl.loadClass();
+
+ try {
+ constructor = providerClass.getConstructor();
+ aProvider = (SCADefinitionsProvider)constructor.newInstance();
+ } catch (NoSuchMethodException e1) {
+ constructor = providerClass.getConstructor(ExtensionPointRegistry.class);
+ aProvider = (SCADefinitionsProvider)constructor.newInstance(extensionPointRegistry);
+ }
+
+ scaDefnsProviders.add(aProvider);
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProvider.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProvider.java
new file mode 100644
index 0000000000..015c673d66
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProvider.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.provider;
+
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+/**
+ * A component implementation can implement this interface in order to tie
+ * into the Tuscany runtime
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ImplementationProvider {
+
+ /**
+ * This method will be invoked when the component implementation
+ * is activated.
+ */
+ void start();
+
+ /**
+ * This method will be invoked when the component implementation
+ * is deactivated.
+ */
+ void stop();
+
+ /**
+ * Create an invoker for the component implementation in the invocation
+ * chain. The invoker will be responsible for calling the implementation
+ * logic for the given component.
+ *
+ * @param service The component service
+ * @param operation The operation that the interceptor will handle
+ * @return An invoker that handles the invocation logic, null should be
+ * returned if no invoker is required
+ */
+ Invoker createInvoker(RuntimeComponentService service, Operation operation);
+
+ /**
+ * For bindings that invoke one-way callback operations asynchronously,
+ * there is no need to perform a thread switch before calling the invoker.
+ * This method indicates whether the binding has this capability.
+ *
+ * @return true if the callback invoker is able to invoke one-way operations
+ * asynchronously, false if all invocations are synchronous
+ */
+ boolean supportsOneWayInvocation();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProviderFactory.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProviderFactory.java
new file mode 100644
index 0000000000..6a37d1e951
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ImplementationProviderFactory.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.provider;
+
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * An interface for factories that create implementation providers.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ImplementationProviderFactory<M extends Implementation> extends ProviderFactory<M> {
+
+ /**
+ * Creates a new implementation provider for the given
+ * component.
+ *
+ * @param component The runtime component
+ * @param Implementation The implementation type
+ * @return The implementation provider
+ */
+ ImplementationProvider createImplementationProvider(RuntimeComponent component, M Implementation);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyImplementor.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyImplementor.java
new file mode 100644
index 0000000000..f2b59a7c54
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyImplementor.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.provider;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+/**
+ * This interface can be optionally implemented by the Binding or Implementation providers to
+ * indicate if they implement the policies in the binding/implementation provider.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface PolicyImplementor {
+ /**
+ * Get a list of policy names that are implemented by this policy implementor
+ * @return A list of policy names
+ */
+ List<QName> getImplementedPolicies();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProvider.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProvider.java
new file mode 100644
index 0000000000..644283dea1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProvider.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.provider;
+
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface PolicyProvider {
+ /**
+ * Create an interceptor for a given operation
+ * @param operation
+ * @return An interceptor that realize the policySet
+ */
+ Interceptor createInterceptor(Operation operation);
+
+ /**
+ * Get the phase that the interceptor should be added
+ * @return The phase that this interceptor belongs to
+ */
+ String getPhase();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProviderFactory.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProviderFactory.java
new file mode 100644
index 0000000000..b60a14d2da
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProviderFactory.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.provider;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.policy.Policy;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface PolicyProviderFactory<M extends Policy> extends ProviderFactory<M> {
+ /**
+ * Create policy provider for a given reference binding
+ * @param component
+ * @param reference
+ * @param binding
+ * @return
+ */
+ PolicyProvider createReferencePolicyProvider(RuntimeComponent component,
+ RuntimeComponentReference reference,
+ Binding binding);
+
+ /**
+ * Create policy provider for a given service binding
+ * @param component
+ * @param service
+ * @param binding
+ * @return
+ */
+ PolicyProvider createServicePolicyProvider(RuntimeComponent component,
+ RuntimeComponentService service,
+ Binding binding);
+
+ /**
+ * Create policy provider for a given component implementation
+ * @param component
+ * @param implementation
+ * @return
+ */
+ PolicyProvider createImplementationPolicyProvider(RuntimeComponent component, Implementation implementation);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactory.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactory.java
new file mode 100644
index 0000000000..2102806881
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactory.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.provider;
+
+/**
+ * A factory for runtime providers.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ProviderFactory<M> {
+
+ /**
+ * The model type that this factory creates providers for.
+ *
+ * @return the model type
+ */
+ Class<M> getModelType();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactoryExtensionPoint.java
new file mode 100644
index 0000000000..d8f9973338
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactoryExtensionPoint.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.provider;
+
+import java.util.List;
+
+
+/**
+ * An extension point for provider factories. Holds all of the provider
+ * factories from loaded extension points. Allows a provider factory
+ * to be located based on a given model type. Hence the runtime can
+ * generate runtime artifacts from the in memory assembly model.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ProviderFactoryExtensionPoint {
+
+
+ /**
+ * Add a provider factory.
+ *
+ * @param providerFactory The provider factory
+ */
+ void addProviderFactory(ProviderFactory providerFactory);
+
+ /**
+ * Remove a provider factory.
+ *
+ * @param providerFactory The provider factory
+ */
+ void removeProviderFactory(ProviderFactory providerFactory);
+
+ /**
+ * Returns the provider factory associated with the given model type.
+ * @param modelType A model type
+ * @return The provider factory associated with the given model type
+ */
+ ProviderFactory getProviderFactory(Class<?> modelType);
+
+ /**
+ * Get a list of registered PolicyProviderFactory
+ * @return a list of registered PolicyProviderFactory
+ */
+ List<PolicyProviderFactory> getPolicyProviderFactories();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ReferenceBindingProvider.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ReferenceBindingProvider.java
new file mode 100644
index 0000000000..b3ab1d8b87
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ReferenceBindingProvider.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.provider;
+
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Invoker;
+
+/**
+ * A reference binding implementation can options implement this
+ * interface to tie into the Tuscany SCA runtime
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ReferenceBindingProvider {
+
+ /**
+ * This method will be invoked when the component reference binding is
+ * activated.
+ */
+ void start();
+
+ /**
+ * This method will be invoked when the component reference binding is
+ * deactivated.
+ */
+ void stop();
+
+ /**
+ * Create an invoker for the reference binding in the invocation chain. The
+ * invoker is responsible for making the outbound invocation over the
+ * binding protocol.
+ *
+ * @param operation The operation that the interceptor will handle
+ * @return An invoker that handles the invocation logic, null should be
+ * returned if no invoker is required
+ */
+ Invoker createInvoker(Operation operation);
+
+ /**
+ * Get the effective interface contract imposed by the binding. For example,
+ * it will be interface contract introspected from the WSDL portType used by
+ * the endpoint for a WebService binding.
+ *
+ * @return The effective interface contract, if null is returned, the
+ * interface contract for the component reference will be used
+ */
+ InterfaceContract getBindingInterfaceContract();
+
+ /**
+ * For bindings that invoke one-way operations asynchronously, there is no
+ * need to perform a thread switch before calling the invoker. This method
+ * indicates whether the binding has this capability.
+ *
+ * @return true if the binding invoker is able to invoke one-way operations
+ * asynchronously, false if all invocations are synchronous
+ */
+ boolean supportsOneWayInvocation();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProvider.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProvider.java
new file mode 100644
index 0000000000..bd0f4d4b75
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProvider.java
@@ -0,0 +1,33 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.provider;
+
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+
+/**
+ * Models a provider of SCA Definitions. Typically SCA Definitions providers
+ * may either load a definitions.xml file or create the SCA Definitions model
+ * programmatically.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface SCADefinitionsProvider {
+ SCADefinitions getSCADefinition() throws SCADefinitionsProviderException ;
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProviderException.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProviderException.java
new file mode 100644
index 0000000000..b05130d6c8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProviderException.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.provider;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SCADefinitionsProviderException extends Exception {
+
+ public SCADefinitionsProviderException(Throwable e) {
+ super(e);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProviderExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProviderExtensionPoint.java
new file mode 100644
index 0000000000..a5d60cc6eb
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/SCADefinitionsProviderExtensionPoint.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.provider;
+
+import java.util.List;
+
+/**
+ * An extension point for SCA Definitions Providers. SCA Definition providers, load SCA Definitions
+ * items that are being specifically contributed by the module that hosts the provider in question.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface SCADefinitionsProviderExtensionPoint {
+
+ void addSCADefinitionsProvider(SCADefinitionsProvider provider);
+ void removeSCADefinitionsProvider(SCADefinitionsProvider provider);
+ List<SCADefinitionsProvider> getSCADefinitionsProviders();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ServiceBindingProvider.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ServiceBindingProvider.java
new file mode 100644
index 0000000000..e15234a549
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ServiceBindingProvider.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.provider;
+
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+
+/**
+ * A service binding can optionally implement this interface to tie
+ * into the Tuscany SCA runtime
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ServiceBindingProvider {
+ /**
+ * This method will be invoked when the component service binding is
+ * activated.
+ */
+ void start();
+
+ /**
+ * This method will be invoked when the component service binding is
+ * deactivated.
+ */
+ void stop();
+
+ /**
+ * Get the effective interface contract imposed by the binding. For example,
+ * it will be interface contract introspected from the WSDL portType used by
+ * the endpoint for a WebService binding.
+ *
+ * @return The effective interface contract, if null is returned, the
+ * interface contract for the component service will be used
+ */
+ InterfaceContract getBindingInterfaceContract();
+
+ /**
+ * For bindings that invoke one-way callback operations asynchronously,
+ * there is no need to perform a thread switch before calling the invoker.
+ * This method indicates whether the binding has this capability.
+ *
+ * @return true if the callback invoker is able to invoke one-way operations
+ * asynchronously, false if all invocations are synchronous
+ */
+ boolean supportsOneWayInvocation();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultWireProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultWireProcessorExtensionPoint.java
new file mode 100644
index 0000000000..851afee3c1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/DefaultWireProcessorExtensionPoint.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.runtime;
+
+import java.util.ArrayList;
+import java.util.List;
+
+
+/**
+ * The default implementation of a <code>WireProcessorExtensionPoint</code>
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultWireProcessorExtensionPoint implements RuntimeWireProcessorExtensionPoint {
+
+ /**
+ * The list of WireProcessors available to the runtime
+ */
+ private final List<RuntimeWireProcessor> processors = new ArrayList<RuntimeWireProcessor>();
+
+ /**
+ * Registers a wire-processor in the runtime
+ *
+ * @param processor The processor to register
+ */
+ public void addWireProcessor(RuntimeWireProcessor processor) {
+ processors.add(processor);
+ }
+
+ /**
+ * De-registers a wire-processor in the runtime
+ *
+ * @param processor The processor to de-register
+ */
+ public void removeWireProcessor(RuntimeWireProcessor processor) {
+ processors.remove(processor);
+ }
+
+ /**
+ * Returns a list of registered wire-processors.
+ *
+ * @return The list of wire processors
+ */
+ public List<RuntimeWireProcessor> getWireProcessors() {
+ return processors;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReference.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReference.java
new file mode 100644
index 0000000000..b6fafa5fb6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/EndpointReference.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.runtime;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Contract;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+
+/**
+ * The endpoint reference for a component service or reference
+ *
+ * @version $Rev$ $Date$
+ */
+public interface EndpointReference extends Cloneable {
+ /**
+ * Get the component for the endpoint
+ * @return The component, null of the EPR is for a non-SCA service
+ */
+ RuntimeComponent getComponent();
+
+ /**
+ * Get the component service or reference for the endpoint
+ * @return The component service or reference, null if the EPR is for a non-SCA service
+ */
+ Contract getContract();
+
+ /**
+ * Get the binding for the endpoint
+ * @return The binding
+ */
+ Binding getBinding();
+
+ /**
+ * Get the interface contract for the endpoint
+ * @return The interface contract
+ */
+ InterfaceContract getInterfaceContract();
+
+ /**
+ * Update the interface contract for the endpoint
+ * @param interfaceContract The updated interface contract
+ */
+ void setInterfaceContract(InterfaceContract interfaceContract);
+
+ /**
+ * Get the URI for this endpoint
+ * @return The URI of the endpoint
+ */
+ String getURI();
+
+ /**
+ * Set the URI for this endpoint
+ * @param uri The new URI of the endpoint
+ */
+ void setURI(String uri);
+
+ /**
+ * Get the callback endpoint for this endpoint
+ * @return The callback endpoint for this endpoint
+ */
+ EndpointReference getCallbackEndpoint();
+
+ /**
+ * Set the callback endpoint for this endpoint
+ * @param callbackEndpoint The new callback endpoint for this endpoint
+ */
+ void setCallbackEndpoint(EndpointReference callbackEndpoint);
+
+ Object clone() throws CloneNotSupportedException;
+
+ void setReferenceParameters(ReferenceParameters parameters);
+ ReferenceParameters getReferenceParameters();
+
+ void mergeEndpoint(EndpointReference epr);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ReferenceParameters.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ReferenceParameters.java
new file mode 100644
index 0000000000..0e19538aff
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/ReferenceParameters.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.runtime;
+
+/**
+ * Parameters for the EndPointReference
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ReferenceParameters extends Cloneable {
+ /**
+ * Get the callback ID
+ * @return the callbackID
+ */
+ Object getCallbackID();
+
+ /**
+ * Set the callback ID
+ * @param callbackID the callbackID to set
+ */
+ void setCallbackID(Object callbackID);
+
+ /**
+ * Get the conversation ID
+ * @return the conversationID
+ */
+ Object getConversationID();
+
+ /**
+ * Set the conversation ID
+ * @param conversationID the conversationID to set
+ */
+ void setConversationID(Object conversationID);
+
+ /**
+ * Get the ID for the non-ServiceReference callback object
+ * @return
+ */
+ Object getCallbackObjectID();
+
+ /**
+ * Set the ID for the non-ServiceReference callback object
+ * @param callbackObjectID
+ */
+ void setCallbackObjectID(Object callbackObjectID);
+
+ EndpointReference getCallbackReference();
+
+ void setCallbackReference(EndpointReference callback);
+
+ Object clone() throws CloneNotSupportedException;
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponent.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponent.java
new file mode 100644
index 0000000000..30bba78a40
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponent.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.runtime;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.provider.PolicyProvider;
+
+/**
+ * The runtime component interface. Provides the bridge between the
+ * assembly model representation of a component and its runtime
+ * realization.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface RuntimeComponent extends Component {
+ /**
+ * Set the implementation-specific configuration for this component
+ * @param implementationProvider The object that manages the component implementation
+ */
+ void setImplementationProvider(ImplementationProvider implementationProvider);
+
+ /**
+ * Get the implementation-specific configuration for this component
+ * @return The implementation provider for this component
+ */
+ ImplementationProvider getImplementationProvider();
+
+ /**
+ * Get the associated component context
+ * @return
+ */
+ RuntimeComponentContext getComponentContext();
+
+ /**
+ * Set the associated component context
+ * @param context
+ */
+ void setComponentContext(RuntimeComponentContext context);
+
+ /**
+ * Tests if the RuntimeComponent is started
+ * @return true if the RuntimeComponent is started otherwise false
+ */
+ boolean isStarted();
+
+ /**
+ * Sets the RuntimeComponent started state
+ * @param started the state to set
+ */
+ void setStarted(boolean started);
+
+ /**
+ * Add a policy provider to the component
+ * @param policyProvider
+ */
+ void addPolicyProvider(PolicyProvider policyProvider);
+
+ /**
+ * Get a list of policy providers configured for this component
+ * @return
+ */
+ List<PolicyProvider> getPolicyProviders();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java
new file mode 100644
index 0000000000..801bb9e294
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentContext.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.runtime;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.ServiceReference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface RuntimeComponentContext extends ComponentContext {
+ /**
+ * Activate the reference (creating runtime wires)
+ * @param reference
+ */
+ void start(RuntimeComponentReference reference);
+
+ /**
+ * Deserialize the component reference
+ * @param reader
+ * @return A component that contains the reference
+ * @throws IOException
+ */
+ RuntimeComponent read(Reader reader) throws IOException;
+
+ /**
+ * Serialize the component reference
+ * @param reference
+ * @param writer
+ * @throws IOException
+ */
+ void write(RuntimeComponentReference reference, Writer writer) throws IOException;
+
+ /**
+ * Get the CallableReference for a given component reference
+ * @param <B>
+ * @param businessInterface The business interface
+ * @param reference The reference to be wired
+ * @param binding The binding to be used, if it's null, either binding.sca or the 1st binding
+ * will be selected
+ * @return A service reference representing the wire
+ */
+ <B> ServiceReference<B> getServiceReference(Class<B> businessInterface,
+ RuntimeComponentReference reference,
+ Binding binding);
+
+ /**
+ * Bind the reference to a target component/componentService
+ * @param <B>
+ * @param businessInterface The business interface
+ * @param reference The reference to be wired
+ * @param component The target component
+ * @param service The target component service
+ * @return A service reference representing the wire
+ */
+ <B> ServiceReference<B> getServiceReference(Class<B> businessInterface,
+ RuntimeComponentReference reference,
+ RuntimeComponent component,
+ RuntimeComponentService service);
+
+ /**
+ * Create a CallableReference for the given component service
+ * @param <B>
+ * @param businessInterface
+ * @param component
+ * @param service
+ * @return
+ */
+ <B> CallableReference<B> getCallableReference(Class<B> businessInterface,
+ RuntimeComponent component,
+ RuntimeComponentService service);
+
+ /**
+ * @param <B>
+ * @param businessInterface
+ * @param service
+ * @return
+ */
+ <B> ServiceReference<B> createSelfReference(Class<B> businessInterface, ComponentService service);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java
new file mode 100644
index 0000000000..44ae7f552a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentReference.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.runtime;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.endpointresolver.EndpointResolver;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.provider.PolicyProvider;
+import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
+
+/**
+ * The runtime component reference. Provides the bridge between the
+ * assembly model representation of a component reference and its runtime
+ * realization
+ *
+ * @version $Rev$ $Date$
+ */
+public interface RuntimeComponentReference extends ComponentReference {
+
+ /**
+ * Get a list of runtime wires to the reference
+ *
+ * @return The list of wires
+ */
+ List<RuntimeWire> getRuntimeWires();
+
+ /**
+ * Get the runtime wire for the given binding
+ * @param binding The assembly model binding
+ * @return The runtime wire
+ */
+ RuntimeWire getRuntimeWire(Binding binding);
+
+ /**
+ * Returns the reference binding provider associated with this
+ * component reference and the given binding.
+ *
+ * @param binding The assembly model binding
+ * @return The runtime reference binding provider
+ */
+ ReferenceBindingProvider getBindingProvider(Binding binding);
+
+ /**
+ * Sets the reference binding provider associated with this
+ * component reference and the given binding.
+ *
+ * @param binding The assembly model binding
+ * @param bindingProvider The runtime reference binding provider
+ */
+ void setBindingProvider(Binding binding, ReferenceBindingProvider bindingProvider);
+
+ /**
+ * Returns the endpoint resolver associated with this
+ * component reference and the given endpoint.
+ *
+ * @param endpont The assembly model endpoint
+ * @return The enpoint resolver
+ */
+ EndpointResolver getEndpointResolver(Endpoint endpoint);
+
+ /**
+ * Sets the endpoint resolver associated with this
+ * component reference and the given endpoint.
+ *
+ * @param binding The assembly model binding
+ * @param bindingProvider The runtime reference binding provider
+ */
+ void setEndpointResolver(Endpoint endpoint, EndpointResolver endpointResolver);
+
+ /**
+ * Add a policy provider for the given binding to the reference
+ * @param binding The assembly model binding
+ * @param policyProvider The policy handler
+ */
+ void addPolicyProvider(Binding binding, PolicyProvider policyProvider);
+
+ /**
+ * Get a list of policy providers for the given binding
+ * @param binding The assembly model binding
+ * @return A list of policy providers for the given binding
+ */
+ List<PolicyProvider> getPolicyProviders(Binding binding);
+
+ /**
+ * Get the invoker for the given binding and operation
+ * @param binding The assembly model binding
+ * @param operation The assembly model operation
+ * @return The runtime Invoker
+ */
+ Invoker getInvoker(Binding binding, Operation operation);
+
+ /**
+ * Set the owning component
+ * @param component
+ */
+ void setComponent(RuntimeComponent component);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.java
new file mode 100644
index 0000000000..982724d798
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeComponentService.java
@@ -0,0 +1,138 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.runtime;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.provider.PolicyProvider;
+import org.apache.tuscany.sca.provider.ServiceBindingProvider;
+
+/**
+ * The runtime component service. Provides the bridge between the
+ * assembly model representation of a component service and its runtime
+ * realization
+ *
+ * @version $Rev$ $Date$
+ */
+public interface RuntimeComponentService extends ComponentService {
+
+ /**
+ * Get a list of runtime wires to the service
+ *
+ * @return The list of wires
+ */
+ List<RuntimeWire> getRuntimeWires();
+ /**
+ * Get the runtime wire for the given binding
+ * @param binding The assembly model binding
+ * @return The runtime wire
+ */
+ RuntimeWire getRuntimeWire(Binding binding);
+
+ /**
+ * Get the callback wires associated with this service
+ *
+ * @return The list of runtime callback wires
+ */
+ List<RuntimeWire> getCallbackWires();
+
+ /**
+ * Returns the service binding provider associated with this
+ * component service and the given binding.
+ *
+ * @param binding The assembly model binding
+ * @return The runtime service binding provider
+ */
+ ServiceBindingProvider getBindingProvider(Binding binding);
+
+ /**
+ * Returns the service binding provider associated with this
+ * component service and the given binding.
+ *
+ * @param binding
+ * @param interfaceContract
+ * @return
+ */
+ RuntimeWire getRuntimeWire(Binding binding, InterfaceContract interfaceContract);
+
+ /**
+ * Sets the service binding provider associated with this
+ * component service and the given binding.
+ *
+ * @param binding The assembly model binding
+ * @param bindingProvider The runtime service binding provider
+ */
+ void setBindingProvider(Binding binding, ServiceBindingProvider bindingProvider);
+
+ /**
+ * Get the invoker for the given binding and operation
+ * @param binding The assembly model binding
+ * @param operation The assembly model operation
+ * @return The runtime invoker
+ */
+ Invoker getInvoker(Binding binding, Operation operation);
+
+ /**
+ * Get the invoker for the given binding and operation
+ * @param binding The assembly model binding
+ * @param interfaceContract the client interface contract
+ * @param operation The assembly model operation
+ * @return The runtime invoker
+ */
+ Invoker getInvoker(Binding binding, InterfaceContract interfaceContract, Operation operation);
+
+ /**
+ * Get the invocation chain for the given binding and operation
+ * @param binding The assembly model binding
+ * @param operation The assembly model operation
+ * @return The runtime invocation chain
+ */
+ InvocationChain getInvocationChain(Binding binding, Operation operation);
+
+ /**
+ * Get the invocation chain for the given binding and operation
+ * @param binding The assembly model binding
+ * @param operation The assembly model operation
+ * @param interfaceContract the client interface contract
+ * @return The runtime invocation chain
+ */
+ InvocationChain getInvocationChain(Binding binding, InterfaceContract interfaceContract, Operation operation);
+
+ /**
+ * Add a policy provider for the given binding to the service
+ * @param binding The assembly model binding
+ * @param policyProvider The policy handler
+ */
+ void addPolicyProvider(Binding binding, PolicyProvider policyProvider);
+
+ /**
+ * Get a list of policy providers for the given binding
+ * @param binding The assembly model binding
+ * @return A list of policy providers for the given binding
+ */
+ List<PolicyProvider> getPolicyProviders(Binding binding);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.java
new file mode 100644
index 0000000000..da37385af1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWire.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.runtime;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Message;
+
+/**
+ * The runtime wire interface that connects a component reference to a
+ * component service (or an external service) over the selected binding
+ *
+ * @version $Rev$ $Date$
+ */
+public interface RuntimeWire extends Cloneable {
+
+ /**
+ * Get the source of the wire
+ *
+ * @return The end point reference of the source
+ */
+ EndpointReference getSource();
+
+ /**
+ * Get the target of the wire
+ *
+ * @return The end point reference of the target
+ */
+ EndpointReference getTarget();
+
+ /**
+ * Rebind the runtime wire with the given target
+ * @param target The target endpoint reference
+ */
+ void setTarget(EndpointReference target);
+
+ /**
+ * Force the invocation chains to be rebuilt
+ */
+ void rebuild();
+
+ /**
+ * Returns the invocation chains for service operations associated with the
+ * wire
+ *
+ * @return the invocation chains for service operations associated with the
+ * wire
+ */
+ List<InvocationChain> getInvocationChains();
+
+ /**
+ * Lookup the invocation chain by operation
+ * @param operation The operation
+ * @return The invocation chain for the given operation
+ */
+ InvocationChain getInvocationChain(Operation operation);
+
+ /**
+ * Invoke an operation with given arguments
+ * @param operation The operation
+ * @param args The arguments
+ * @return The result
+ * @throws InvocationTargetException
+ */
+ Object invoke(Operation operation, Object[] args) throws InvocationTargetException;
+
+ /**
+ * Invoke an operation with a context message
+ * @param operation The operation
+ * @param msg The message
+ * @return The result
+ * @throws InvocationTargetException
+ */
+ Object invoke(Operation operation, Message msg) throws InvocationTargetException;
+
+ /**
+ * @return a clone of the runtime wire
+ * @throws CloneNotSupportedException
+ */
+ Object clone() throws CloneNotSupportedException;
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessor.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessor.java
new file mode 100644
index 0000000000..fbb7aae467
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessor.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.runtime;
+
+/**
+ * Implementations are called after wires are decorated with policy and before they are connected.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface RuntimeWireProcessor {
+
+ /**
+ * Process the runtime wire to add interceptors
+ *
+ * @param wire
+ */
+ void process(RuntimeWire wire);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessorExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessorExtensionPoint.java
new file mode 100644
index 0000000000..4b2c71b397
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/runtime/RuntimeWireProcessorExtensionPoint.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.runtime;
+
+import java.util.List;
+
+/**
+ * Acts as a delegating <code>WireProcessorExtensionPoint</code>, delegating
+ * processing of wires after policies have been applied and source and targets
+ * have been connected.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface RuntimeWireProcessorExtensionPoint {
+
+ /**
+ * Registers a wire-processor in the runtime
+ *
+ * @param processor The processor to register
+ */
+ void addWireProcessor(RuntimeWireProcessor processor);
+
+ /**
+ * De-registers a wire-processor in the runtime
+ *
+ * @param processor The processor to de-register
+ */
+ void removeWireProcessor(RuntimeWireProcessor processor);
+
+ /**
+ * Returns a list of registered wire-processors.
+ *
+ * @return The list of wire processors
+ */
+ List<RuntimeWireProcessor> getWireProcessors();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/DuplicateRecordException.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/DuplicateRecordException.java
new file mode 100644
index 0000000000..7d5cd6c54b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/DuplicateRecordException.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.store;
+
+/**
+ * thrown when a record already exists during an insert operation
+ *
+ * @version $Rev$ $Date$
+ */
+public class DuplicateRecordException extends StoreWriteException {
+ private static final long serialVersionUID = 3116253222569378447L;
+
+ /**
+ * {@inheritDoc}
+ */
+ public DuplicateRecordException() {
+ super();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public DuplicateRecordException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public DuplicateRecordException(String message) {
+ super(message);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public DuplicateRecordException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/RecoveryListener.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/RecoveryListener.java
new file mode 100644
index 0000000000..9d965a3369
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/RecoveryListener.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.store;
+
+import java.util.UUID;
+
+/**
+ * Implementations receive callback events during a store recovery operation
+ *
+ * @version $Rev$ $Date$
+ */
+public interface RecoveryListener {
+
+ /**
+ * Signals the start of a recovery
+ */
+ void onBegin();
+
+ /**
+ * Received when a record is recovered
+ *
+ * @param id
+ */
+ void onRecord(UUID id);
+
+ /**
+ * Signals the end of recovery
+ */
+ void onEnd();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/Store.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/Store.java
new file mode 100644
index 0000000000..b15cde066a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/Store.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.store;
+
+import org.apache.tuscany.sca.event.EventPublisher;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * Implementations provide a persistent store for runtime data such as conversational state. A persistent store could be
+ * implemented in a durable fashion using JDBC or a journaling system, or using a non-durable mechanism such as an
+ * in-memory map.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Store extends EventPublisher {
+
+ /* Used to indicate an the default expiration offset for records for the store */
+ long DEFAULT_EXPIRATION_OFFSET = -1;
+
+ /* Used to indicate an entry should not expire */
+ long NEVER = -2;
+
+ /**
+ * Adds the given record to the store. Implementations may choose different strategies for writing data such as
+ * write-through or write-behind.
+ *
+ * @param owner the instance owner
+ * @param id the unique id of the record
+ * @param object the object representing the data to write
+ * @param expiration the time in milliseconds when the entry expires
+ * @throws StoreWriteException if an error occurs during the write operation
+ */
+ void insertRecord(RuntimeComponent owner, String id, Object object, long expiration) throws StoreWriteException;
+
+ /**
+ * Updates a given record in the store, overwriting previous information.
+ *
+ * @param owner the instance owner
+ * @param id the unique id of the record
+ * @param object the object representing the data to write
+ * @param expiration the time in milliseconds when the entry expires
+ * @throws StoreWriteException
+ */
+ void updateRecord(RuntimeComponent owner, String id, Object object, long expiration) throws StoreWriteException;
+
+ /**
+ * Returns the deserialized object in the store corresponding to the given id
+ *
+ * @param owner the instance owner
+ * @param id the unique id of the record
+ * @return the deserialized object or null if one is not found
+ * @throws StoreReadException
+ */
+ Object readRecord(RuntimeComponent owner, String id) throws StoreReadException;
+
+ /**
+ * Removes a record from the store
+ *
+ * @param owner the instance owner
+ * @param id the unique id of the record
+ * @throws StoreWriteException
+ */
+ void removeRecord(RuntimeComponent owner, String id) throws StoreWriteException;
+
+ /**
+ * Removes all records from the store
+ *
+ * @throws StoreWriteException
+ */
+ void removeRecords() throws StoreWriteException;
+
+ /**
+ * Initiates a recovery operation, for example during restart after a crash
+ *
+ * @param listener the listener to receive recovery callback events
+ * @throws StoreReadException
+ */
+ void recover(RecoveryListener listener) throws StoreReadException;
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreException.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreException.java
new file mode 100644
index 0000000000..24eaddd3e0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreException.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.store;
+
+
+/**
+ * Represents a generic exception thrown by a <code>Store</code>
+ *
+ * @version $Rev$ $Date$
+ */
+public class StoreException extends Exception {
+ private static final long serialVersionUID = -319152147419962709L;
+
+ /**
+ * {@inheritDoc}
+ */
+ public StoreException() {
+ super();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public StoreException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public StoreException(String message) {
+ super(message);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public StoreException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreExpirationEvent.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreExpirationEvent.java
new file mode 100644
index 0000000000..5c1a3ca79d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreExpirationEvent.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.store;
+
+import org.apache.tuscany.sca.event.Event;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * Fired when a store implementation expires a resource
+ *
+ * @version $Rev$ $Date$
+ */
+public class StoreExpirationEvent implements Event {
+ private Object source;
+ private RuntimeComponent owner;
+ private Object instance;
+
+ /**
+ * Constructor.
+ *
+ * @param source the source of the event
+ * @param owner the owner of the expiring object
+ * @param instance the expiring object
+ */
+ public StoreExpirationEvent(Object source, RuntimeComponent owner, Object instance) {
+ assert source != null;
+ assert owner != null;
+ assert instance != null;
+ this.source = source;
+ this.owner = owner;
+ this.instance = instance;
+ }
+
+ public Object getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the owner of the expiring object.
+ *
+ * @return the owner of the expiring object.
+ */
+ public RuntimeComponent getOwner() {
+ return owner;
+ }
+
+ /**
+ * Returns the expiring object.
+ *
+ * @return the expiring object.
+ */
+ public Object getInstance() {
+ return instance;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreMonitor.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreMonitor.java
new file mode 100644
index 0000000000..4bc7facf39
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreMonitor.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.store;
+
+
+/**
+ * A generic monitor interface for services to log events
+ *
+ * @version $Rev$ $Date$
+ */
+public interface StoreMonitor {
+
+ /**
+ * Signals the service has started
+ *
+ * @param msg
+ */
+ void start(String msg);
+
+ /**
+ * Signals the service has been shutdown
+ *
+ * @param msg
+ */
+ void stop(String msg);
+
+ /**
+ * Fired when recovery is started
+ */
+
+ void beginRecover();
+
+ /**
+ * Fired when recovery is completed
+ */
+
+ void endRecover();
+
+ /**
+ * Fired when a record is processed during recovery
+ *
+ * @param recordId the id of the record being recovered
+ */
+
+ void recover(Object recordId);
+
+ /**
+ * Signals an error event
+ *
+ * @param e the error
+ */
+
+ void error(Throwable e);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreReadException.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreReadException.java
new file mode 100644
index 0000000000..c2346bddca
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreReadException.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.store;
+
+/**
+ * Thrown when an error occurs reading from persistent storage
+ *
+ * @version $Rev$ $Date$
+ */
+public class StoreReadException extends StoreException {
+ private static final long serialVersionUID = -8624542082121467271L;
+
+ /**
+ * {@inheritDoc}
+ */
+ public StoreReadException() {
+ super();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public StoreReadException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public StoreReadException(String message) {
+ super(message);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public StoreReadException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreWriteException.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreWriteException.java
new file mode 100644
index 0000000000..b37519b31c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/store/StoreWriteException.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.store;
+
+/**
+ * Thrown when an error occurs writing to persistent storage
+ *
+ * @version $Rev$ $Date$
+ */
+public class StoreWriteException extends StoreException {
+ private static final long serialVersionUID = 5539070473942048555L;
+
+ /**
+ * {@inheritDoc}
+ */
+ public StoreWriteException() {
+ super();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public StoreWriteException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public StoreWriteException(String message) {
+ super(message);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public StoreWriteException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/NotificationListener.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/NotificationListener.java
new file mode 100644
index 0000000000..d32af450ff
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/NotificationListener.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.work;
+
+/**
+ * A callback interface that can be optionally used for registering
+ * interest in status of asynchronously scheduled unit of work.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface NotificationListener<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 successfully completed.
+ */
+ void workCompleted(T work);
+
+ /**
+ * Callback when the unit of work is started.
+ *
+ * @param work Unit of work that was started.
+ */
+ void workStarted(T work);
+
+ /**
+ * Callback when the unit of work is rejected.
+ *
+ * @param work Unit of work that was rejected.
+ */
+ void workRejected(T work);
+
+ /**
+ * Callback when the unit of work fails to complete.
+ *
+ * @param work Unit of work that failed to complete.
+ * @param error Error that caused the unit of work to fail.
+ */
+ void workFailed(T work, Throwable error);
+
+
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkScheduler.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkScheduler.java
new file mode 100644
index 0000000000..b1beac78e2
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkScheduler.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.work;
+
+/**
+ * Defines the contract for scheduling asynchronous units of work.
+ *
+ * <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 notified with the
+ * error details.
+ * </p>
+ *
+ * @version $Rev$ $Date$
+ */
+public interface WorkScheduler {
+
+ /**
+ * Schedules a unit of work for future execution. The notification listener
+ * is used to register interest in callbacks regarding the status of the work.
+ *
+ * @param work The unit of work that needs to be asynchronously executed.
+ * @param listener Notification listener for callbacks.
+ */
+ <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);
+
+ /**
+ * Destroys the work scheduler
+ */
+ void destroy();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkSchedulerException.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkSchedulerException.java
new file mode 100644
index 0000000000..18ec2dfeaa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/java/org/apache/tuscany/sca/work/WorkSchedulerException.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.work;
+
+
+/**
+ * Exception thrown by the work scheduler in case of unexpected exceptions.
+ *
+ * @version $Rev$ $Date$
+ *
+ * @version $Rev$ $Date$
+ */
+public class WorkSchedulerException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * {@inheritDoc}
+ */
+ public WorkSchedulerException() {
+ super();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public WorkSchedulerException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public WorkSchedulerException(String message) {
+ super(message);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public WorkSchedulerException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.context.ContextFactoryExtensionPoint b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.context.ContextFactoryExtensionPoint
new file mode 100644
index 0000000000..ddd91bceac
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.context.ContextFactoryExtensionPoint
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.context.DefaultContextFactoryExtensionPoint
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.endpointresolver.EndpointResolverFactoryExtensionPoint b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.endpointresolver.EndpointResolverFactoryExtensionPoint
new file mode 100644
index 0000000000..91839e998f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.endpointresolver.EndpointResolverFactoryExtensionPoint
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.endpointresolver.DefaultEndpointResolverFactoryExtensionPoint
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint
new file mode 100644
index 0000000000..e9de1f135f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.provider.DefaultProviderFactoryExtensionPoint
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProviderExtensionPoint b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProviderExtensionPoint
new file mode 100644
index 0000000000..2f700671ca
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.SCADefinitionsProviderExtensionPoint
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.provider.DefaultSCADefinitionsProviderExtensionPoint
+ \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint
new file mode 100644
index 0000000000..95591dca5d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/main/resources/META-INF/services/org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.runtime.DefaultWireProcessorExtensionPoint
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/test/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPointTestCase.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/test/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPointTestCase.java
new file mode 100644
index 0000000000..3a27569a3b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/test/java/org/apache/tuscany/sca/context/DefaultContextFactoryExtensionPointTestCase.java
@@ -0,0 +1,208 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.context;
+
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * This test case will test the class
+ * org.apache.tuscany.sca.context.DefaultContextFactoryExtensionPoint
+ *
+ * $Date$ $Rev$
+ */
+public class DefaultContextFactoryExtensionPointTestCase {
+
+ /**
+ * Tests adding/getting/removing a factory with no interfaces
+ */
+ @Test
+ public void testFactoryWithNoInterfaces() {
+ Object factory = new FactoryWithNoInterfaces();
+ Class<?>[] ifaces = {};
+ addGetRemoveFactory(factory, ifaces);
+ }
+
+ /**
+ * Tests adding/getting/removing a factory with one interface
+ */
+ @Test
+ public void testFactoryWithOneInterface() {
+ Object factory = new FactoryWithOneInterface();
+ Class<?>[] ifaces = { FactoryOneInterface.class };
+ addGetRemoveFactory(factory, ifaces);
+ }
+
+ /**
+ * Tests adding/getting/removing a factory with two interfaces
+ */
+ @Test
+ public void testFactoryWithTwoInterfaces() {
+ Object factory = new FactoryWithTwoInterfaces();
+ Class<?>[] ifaces = { FactoryTwoInterfacesA.class, FactoryTwoInterfacesB.class };
+ addGetRemoveFactory(factory, ifaces);
+ }
+
+ /**
+ * Tests having multiple factories registered
+ */
+ @Test
+ public void testMultipleFactories() {
+ // Create new factories
+ FactoryWithOneInterface factory1 = new FactoryWithOneInterface();
+ FactoryWithTwoInterfaces factory2 = new FactoryWithTwoInterfaces();
+
+ ExtensionPointRegistry registry = new DefaultExtensionPointRegistry();
+
+ // Register the factories
+ DefaultContextFactoryExtensionPoint ctxFactory = new DefaultContextFactoryExtensionPoint(registry);
+ ctxFactory.addFactory(factory1);
+ ctxFactory.addFactory(factory2);
+
+ // Re-get each of the factories
+ FactoryOneInterface regotFactory1 = ctxFactory.getFactory(FactoryOneInterface.class);
+ Assert.assertNotNull(regotFactory1);
+ Assert.assertSame(factory1, regotFactory1);
+ FactoryTwoInterfacesA regotFactory2A = ctxFactory.getFactory(FactoryTwoInterfacesA.class);
+ Assert.assertNotNull(regotFactory2A);
+ Assert.assertSame(factory2, regotFactory2A);
+ FactoryTwoInterfacesB regotFactory2B = ctxFactory.getFactory(FactoryTwoInterfacesB.class);
+ Assert.assertNotNull(regotFactory1);
+ Assert.assertSame(factory2, regotFactory2B);
+ }
+
+ /**
+ * Tests passing in null to addFactory()
+ */
+ @Test
+ public void testAddingNullFactory() {
+
+ ExtensionPointRegistry registry = new DefaultExtensionPointRegistry();
+ DefaultContextFactoryExtensionPoint ctxFactory = new DefaultContextFactoryExtensionPoint(registry);
+ try {
+ ctxFactory.addFactory(null);
+ Assert.fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException ex) {
+ // As expected
+ }
+ }
+
+ /**
+ * Test passing in null to removeFactory()
+ */
+ @Test
+ public void testRemovingNullFactory() {
+ ExtensionPointRegistry registry = new DefaultExtensionPointRegistry();
+ DefaultContextFactoryExtensionPoint ctxFactory = new DefaultContextFactoryExtensionPoint(registry);
+ try {
+ ctxFactory.removeFactory(null);
+ Assert.fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException ex) {
+ // As expected
+ }
+ }
+
+ /**
+ * Test passing in null to getFactory()
+ */
+ @Test
+ public void testGetNullFactory() {
+ ExtensionPointRegistry registry = new DefaultExtensionPointRegistry();
+ DefaultContextFactoryExtensionPoint ctxFactory = new DefaultContextFactoryExtensionPoint(registry);
+ try {
+ ctxFactory.getFactory(null);
+ Assert.fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException ex) {
+ // As expected
+ }
+ }
+
+ /**
+ * Utility method for testing adding and removing a factory
+ *
+ * @param factory The factory class to test
+ * @param factoryInterfaces The list of interfaces implemented by the factory
+ */
+ private void addGetRemoveFactory(Object factory, Class<?>[] factoryInterfaces) {
+ ExtensionPointRegistry registry = new DefaultExtensionPointRegistry();
+ DefaultContextFactoryExtensionPoint ctxFactory = new DefaultContextFactoryExtensionPoint(registry);
+
+ // Make sure factory not already present
+ for (Class<?> iface : factoryInterfaces) {
+ Assert.assertNull(ctxFactory.getFactory(iface));
+ }
+
+ // Add the factory
+ ctxFactory.addFactory(factory);
+
+ // Make sure we can get the factory recently registered factory
+ for (Class<?> iface : factoryInterfaces) {
+ Object regot = ctxFactory.getFactory(iface);
+ Assert.assertNotNull(regot);
+ Assert.assertSame(factory, regot);
+ }
+
+ // Remove the factory
+ ctxFactory.removeFactory(factory);
+
+ // Make sure factory is no longer registered
+ for (Class<?> iface : factoryInterfaces) {
+ Assert.assertNull(ctxFactory.getFactory(iface));
+ }
+ }
+
+ /**
+ * Simple factory with no interfaces
+ */
+ private class FactoryWithNoInterfaces {
+ }
+
+ /**
+ * Simple interface for the factory with one interface
+ */
+ private interface FactoryOneInterface {
+ }
+
+ /**
+ * Simple factory with one interface
+ */
+ private class FactoryWithOneInterface implements FactoryOneInterface {
+ }
+
+ /**
+ * Simple interface for the factory with two interfaces
+ */
+ private interface FactoryTwoInterfacesA {
+ }
+
+ /**
+ * Simple interface for the factory with two interfaces
+ */
+ private interface FactoryTwoInterfacesB {
+ }
+
+ /**
+ * Simple factory with two interfaces
+ */
+ private class FactoryWithTwoInterfaces implements FactoryTwoInterfacesA, FactoryTwoInterfacesB {
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core-spi/src/test/java/org/apache/tuscany/sca/event/TrueFilterTestCase.java b/sca-java-1.x/branches/sca-android/modules/core-spi/src/test/java/org/apache/tuscany/sca/event/TrueFilterTestCase.java
new file mode 100644
index 0000000000..2425133273
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core-spi/src/test/java/org/apache/tuscany/sca/event/TrueFilterTestCase.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.event;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+/**
+ * Test case for TrueFilter
+ *
+ * @version $Rev$ $Date$
+ */
+public class TrueFilterTestCase {
+
+ /**
+ * Test TrueFilter matching an event
+ */
+ @Test
+ public void testTrueFilterMatch() {
+ EventFilter filter = new TrueFilter();
+
+ Assert.assertTrue(filter.match(new DummyEvent()));
+ }
+
+ /**
+ * Test TrueFilter matching null
+ */
+ @Test
+ public void testTrueFilterMatchNull() {
+ EventFilter filter = new TrueFilter();
+
+ Assert.assertTrue(filter.match(null));
+ }
+
+ /**
+ * Dummy Event implementation for testing
+ */
+ private class DummyEvent implements Event {
+
+ /**
+ * {@inheritDoc}
+ */
+ public Object getSource() {
+ throw new UnsupportedOperationException();
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/LICENSE b/sca-java-1.x/branches/sca-android/modules/core/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/core/META-INF/README b/sca-java-1.x/branches/sca-android/modules/core/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/core/NOTICE b/sca-java-1.x/branches/sca-android/modules/core/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/core/pom.xml b/sca-java-1.x/branches/sca-android/modules/core/pom.xml
new file mode 100644
index 0000000000..b71f001d06
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/pom.xml
@@ -0,0 +1,107 @@
+<?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.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-core</artifactId>
+ <name>Apache Tuscany SCA Core Runtime</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-extensibility</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core-spi</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution-java</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-interface-java</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.geronimo.specs</groupId>
+ <artifactId>geronimo-commonj_1.1_spec</artifactId>
+ <version>1.0</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ <version>3.2.1</version>
+ <scope>runtime</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>cglib</groupId>
+ <artifactId>cglib-nodep</artifactId>
+ <version>2.1_3</version>
+ </dependency>
+ </dependencies>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.core</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.core*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ActivationException.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ActivationException.java
new file mode 100644
index 0000000000..c86c876075
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ActivationException.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.assembly;
+
+
+/**
+ * Denotes an error starting the runtime
+ *
+ * @version $Rev$ $Date$
+ */
+public class ActivationException extends Exception {
+ private static final long serialVersionUID = 8612661660934426123L;
+
+ public ActivationException(String message) {
+ super(message);
+ }
+
+ public ActivationException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivator.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivator.java
new file mode 100644
index 0000000000..29dcc20f0b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivator.java
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.assembly;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.core.context.ComponentContextHelper;
+import org.apache.tuscany.sca.core.conversation.ConversationManager;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+/**
+ * Start/stop a composite
+ *
+ * @version $Rev$ $Date$
+ */
+public interface CompositeActivator {
+ /**
+ * Activate a composite
+ * @param composite
+ */
+ void activate(Composite composite) throws ActivationException;
+
+ /**
+ * Activate a component reference
+ * @param component
+ * @param ref
+ */
+ void start(RuntimeComponent component, RuntimeComponentReference ref);
+
+ /**
+ * Activate a component reference
+ * @param component
+ * @param ref
+ */
+ void activate(RuntimeComponent component, RuntimeComponentReference ref);
+
+ /**
+ * Activate a component reference
+ * @param component
+ * @param ref
+ */
+ void activate(RuntimeComponent component, RuntimeComponentService service);
+
+ /**
+ * De-activate a component reference
+ * @param component
+ * @param ref
+ */
+ void deactivate(RuntimeComponent component, RuntimeComponentReference ref);
+
+ /**
+ * De-activate a component reference
+ * @param component
+ * @param ref
+ */
+ void deactivate(RuntimeComponent component, RuntimeComponentService service);
+
+ /**
+ * Stop a composite
+ * @param composite
+ */
+ void deactivate(Composite composite) throws ActivationException;
+
+ /**
+ * Start a component
+ * @param component
+ */
+ void start(Component component) throws ActivationException;
+
+ /**
+ * Stop a component
+ * @param component
+ */
+ void stop(Component component) throws ActivationException;
+
+ /**
+ * Start components in a composite
+ * @param composite
+ */
+ void start(Composite composite) throws ActivationException;
+
+ /**
+ * Stop components in a composite
+ * @param composite
+ */
+ void stop(Composite composite) throws ActivationException;
+
+ /**
+ * Get the component context helper
+ * @return
+ */
+ ComponentContextHelper getComponentContextHelper();
+
+ /**
+ * Get the proxy factory
+ * @return
+ */
+ ProxyFactory getProxyFactory();
+
+ /**
+ * Get the java interface factory
+ * @return
+ */
+ JavaInterfaceFactory getJavaInterfaceFactory();
+
+ ConversationManager getConversationManager();
+
+ /**
+ * Configure the runtime component with component context
+ * @param component
+ */
+ void configureComponentContext(RuntimeComponent component);
+
+ /**
+ * Resolve a component by URI in the domain
+ * @param componentURI
+ * @return
+ */
+ Component resolve(String componentURI);
+
+ /**
+ * Set the domain composite
+ * @param domainComposite
+ */
+ void setDomainComposite(Composite domainComposite);
+
+ /**
+ * Get the domain composite
+ * @return
+ */
+ Composite getDomainComposite();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivatorImpl.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivatorImpl.java
new file mode 100644
index 0000000000..f51931c53b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/CompositeActivatorImpl.java
@@ -0,0 +1,1101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.assembly;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.OptimizableBinding;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.context.RequestContextFactory;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.context.ComponentContextHelper;
+import org.apache.tuscany.sca.core.context.ComponentContextImpl;
+import org.apache.tuscany.sca.core.conversation.ConversationManager;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.core.scope.ConversationalScopeContainer;
+import org.apache.tuscany.sca.core.scope.Scope;
+import org.apache.tuscany.sca.core.scope.ScopeContainer;
+import org.apache.tuscany.sca.core.scope.ScopeRegistry;
+import org.apache.tuscany.sca.core.scope.ScopedRuntimeComponent;
+import org.apache.tuscany.sca.endpointresolver.EndpointResolver;
+import org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory;
+import org.apache.tuscany.sca.endpointresolver.EndpointResolverFactoryExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.provider.BindingProviderFactory;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.provider.ImplementationProviderFactory;
+import org.apache.tuscany.sca.provider.PolicyProvider;
+import org.apache.tuscany.sca.provider.PolicyProviderFactory;
+import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
+import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
+import org.apache.tuscany.sca.provider.ServiceBindingProvider;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentContext;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.apache.tuscany.sca.runtime.RuntimeWireProcessor;
+import org.apache.tuscany.sca.work.WorkScheduler;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CompositeActivatorImpl implements CompositeActivator {
+ private static final Logger logger = Logger.getLogger(CompositeActivatorImpl.class.getName());
+
+ private final AssemblyFactory assemblyFactory;
+ private final MessageFactory messageFactory;
+ private final InterfaceContractMapper interfaceContractMapper;
+ private final ScopeRegistry scopeRegistry;
+ private final WorkScheduler workScheduler;
+ private final RuntimeWireProcessor wireProcessor;
+ private final ProviderFactoryExtensionPoint providerFactories;
+ private final EndpointResolverFactoryExtensionPoint endpointResolverFactories;
+
+ private final RequestContextFactory requestContextFactory;
+ private final ProxyFactory proxyFactory;
+ private final JavaInterfaceFactory javaInterfaceFactory;
+ private final ConversationManager conversationManager;
+
+ private final ComponentContextHelper componentContextHelper;
+
+ private Composite domainComposite;
+
+ /**
+ * @param assemblyFactory
+ * @param interfaceContractMapper
+ * @param workScheduler
+ * @param conversationManager TODO
+ * @param workContext
+ * @param wirePostProcessorRegistry
+ */
+ public CompositeActivatorImpl(AssemblyFactory assemblyFactory,
+ MessageFactory messageFactory,
+ JavaInterfaceFactory javaInterfaceFactory,
+ SCABindingFactory scaBindingFactory,
+ InterfaceContractMapper interfaceContractMapper,
+ ScopeRegistry scopeRegistry,
+ WorkScheduler workScheduler,
+ RuntimeWireProcessor wireProcessor,
+ RequestContextFactory requestContextFactory,
+ ProxyFactory proxyFactory,
+ ProviderFactoryExtensionPoint providerFactories,
+ EndpointResolverFactoryExtensionPoint endpointResolverFactories,
+ StAXArtifactProcessorExtensionPoint processors,
+ ConversationManager conversationManager) {
+ this.assemblyFactory = assemblyFactory;
+ this.messageFactory = messageFactory;
+ this.interfaceContractMapper = interfaceContractMapper;
+ this.scopeRegistry = scopeRegistry;
+ this.workScheduler = workScheduler;
+ this.wireProcessor = wireProcessor;
+ this.providerFactories = providerFactories;
+ this.endpointResolverFactories = endpointResolverFactories;
+ this.javaInterfaceFactory = javaInterfaceFactory;
+ this.requestContextFactory = requestContextFactory;
+ this.proxyFactory = proxyFactory;
+ this.conversationManager = conversationManager;
+ this.componentContextHelper = new ComponentContextHelper(assemblyFactory, javaInterfaceFactory, processors);
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.core.assembly.CompositeActivator#activate(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.runtime.RuntimeComponentReference)
+ */
+ public void activate(RuntimeComponent component, RuntimeComponentReference ref) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Activating component reference: " + component.getURI() + "#" + ref.getName());
+ }
+ resolveTargets(ref);
+ for (Binding binding : ref.getBindings()) {
+ addReferenceBindingProvider(component, ref, binding);
+ }
+
+ for (Endpoint endpoint : ref.getEndpoints()){
+ // TODO - source component should be set in the builder but the
+ // way the builder is written it's difficult to get at it
+ endpoint.setSourceComponent(component);
+
+ addEndpointResolver(component, ref, endpoint);
+ }
+ }
+
+ public void start(RuntimeComponent component, RuntimeComponentReference ref) {
+ synchronized (ref) {
+ resolveTargets(ref);
+ for (Binding binding : ref.getBindings()) {
+ ReferenceBindingProvider provider = ref.getBindingProvider(binding);
+ if (provider == null) {
+ provider = addReferenceBindingProvider(component, ref, binding);
+ }
+ if (provider != null) {
+ provider.start();
+ }
+ addReferenceWire(component, ref, binding);
+ }
+
+ // targets now have an endpoint representation. We can use this to
+ // look for unresolved endpoints using dummy wires for late resolution
+ for (Endpoint endpoint : ref.getEndpoints()){
+ addReferenceEndpointWire(component, ref, endpoint);
+ }
+ }
+ }
+
+ public void stop(Component component, ComponentReference reference) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Stopping component reference: " + component.getURI() + "#" + reference.getName());
+ }
+ RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference);
+ for (Binding binding : reference.getBindings()) {
+ ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(binding);
+ if (bindingProvider != null) {
+ bindingProvider.stop();
+ }
+ }
+ }
+
+ public void deactivate(RuntimeComponent component, RuntimeComponentReference ref) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Deactivating component reference: " + component.getURI() + "#" + ref.getName());
+ }
+ removeReferenceWires(ref);
+ for (Binding binding : ref.getBindings()) {
+ removeReferenceBindingProvider(component, ref, binding);
+ }
+
+ }
+
+ /**
+ * @param component
+ * @param reference
+ * @param binding
+ */
+ private EndpointResolver addEndpointResolver(RuntimeComponent component,
+ RuntimeComponentReference reference,
+ Endpoint endpoint){
+
+ // only create endpoint resolvers for unresolved endpoints currently
+ // this will also prevent a wire from being created later
+ if (!endpoint.isUnresolved()){
+ return null;
+ }
+
+ // This souldn't happen as the endpoint resolver extension point is in core-spi but
+ // just in case returning null here will mean that no wire is created and calling
+ // the reference will fail with NPE
+ if (endpointResolverFactories == null){
+ return null;
+ }
+
+ EndpointResolverFactory<Endpoint> resolverFactory =
+ (EndpointResolverFactory<Endpoint>)endpointResolverFactories.getEndpointResolverFactory(endpoint.getClass());
+
+ if (resolverFactory != null) {
+ @SuppressWarnings("unchecked")
+ EndpointResolver endpointResolver =
+ resolverFactory.createEndpointResolver(endpoint, null);
+ if (endpointResolver != null) {
+ ((RuntimeComponentReference)reference).setEndpointResolver(endpoint, endpointResolver);
+ }
+
+ return endpointResolver;
+ } else {
+ // TODO - for the time being allow the lack of an endpoint provider to be the
+ // switch to turn off endpoint processing
+ return null;
+ //throw new IllegalStateException("Endpoint provider factory not found for class: " + endpoint.getClass().getName());
+ }
+ }
+
+ public void addReferenceBindingProviderForEndpoint(Endpoint endpoint){
+ addReferenceBindingProvider((RuntimeComponent)endpoint.getSourceComponent(),
+ (RuntimeComponentReference)endpoint.getSourceComponentReference(),
+ endpoint.getSourceBinding());
+ }
+
+ /**
+ * @param component
+ * @param reference
+ * @param binding
+ */
+ private ReferenceBindingProvider addReferenceBindingProvider(RuntimeComponent component,
+ RuntimeComponentReference reference,
+ Binding binding) {
+ BindingProviderFactory providerFactory =
+ (BindingProviderFactory)providerFactories.getProviderFactory(binding.getClass());
+ if (providerFactory != null) {
+ @SuppressWarnings("unchecked")
+ ReferenceBindingProvider bindingProvider =
+ providerFactory.createReferenceBindingProvider((RuntimeComponent)component,
+ (RuntimeComponentReference)reference,
+ binding);
+ if (bindingProvider != null) {
+ ((RuntimeComponentReference)reference).setBindingProvider(binding, bindingProvider);
+ }
+ for (PolicyProviderFactory f : providerFactories.getPolicyProviderFactories()) {
+ PolicyProvider policyProvider = f.createReferencePolicyProvider(component, reference, binding);
+ if (policyProvider != null) {
+ reference.addPolicyProvider(binding, policyProvider);
+ }
+ }
+
+ return bindingProvider;
+ } else {
+ throw new IllegalStateException("Provider factory not found for class: " + binding.getClass().getName());
+ }
+ }
+
+ /**
+ * @param reference
+ */
+ private void resolveTargets(RuntimeComponentReference reference) {
+ // The code that used to be here to resolved unresolved targets is now
+ // at the bottom of BaseWireBuilder.connectComponentReferences()
+ }
+
+ /**
+ * Create the runtime wires for a reference endpoint. Currently this method
+ * only deals with the late binding case and creates a dummy wire that
+ * will use the Endpoint to resolve the target at the point when the
+ * wire chains are created.
+ *
+ * @param component
+ * @param reference
+ * @param binding
+ */
+ private void addReferenceEndpointWire(Component component, ComponentReference reference, Endpoint endpoint) {
+ // only deal with unresolved endpoints as, to prevent breaking changes, targets that are resolved
+ // at build time are still represented as bindings in the binding list
+ if (((RuntimeComponentReference)reference).getEndpointResolver(endpoint) == null){
+ // no endpoint provider has previously been created so don't create the
+ // wire
+ return;
+ }
+
+ // TODO: TUSCANY-2580: avoid NPE if the InterfaceCOntract is null
+ Reference ctref = endpoint.getSourceComponentReference().getReference();
+ if (ctref != null && ctref.getInterfaceContract() == null) {
+ ctref.setInterfaceContract(reference.getInterfaceContract());
+ }
+
+ RuntimeWire wire = new EndpointWireImpl(endpoint, this);
+
+ RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference;
+ runtimeRef.getRuntimeWires().add(wire);
+ }
+
+
+ /**
+ * Create the runtime wires for a reference binding
+ *
+ * @param component
+ * @param reference
+ * @param binding
+ */
+ private void addReferenceWire(Component component, ComponentReference reference, Binding binding) {
+ if (!(reference instanceof RuntimeComponentReference)) {
+ return;
+ }
+
+ // create wire if binding has an endpoint
+ Component targetComponent = null;
+ ComponentService targetComponentService = null;
+ Binding targetBinding = null;
+
+ if (binding instanceof OptimizableBinding) {
+ OptimizableBinding endpoint = (OptimizableBinding)binding;
+ targetComponent = endpoint.getTargetComponent();
+ targetComponentService = endpoint.getTargetComponentService();
+ targetBinding = endpoint.getTargetBinding();
+ // FIXME: TUSCANY-2136, For unresolved binding, don't add wire. Is it the right solution?
+ if (!reference.isCallback() && binding.getURI() == null && targetComponentService == null) {
+ return;
+ }
+ }
+
+ // create a forward wire, either static or dynamic
+ addReferenceWire(component, reference, binding, targetComponent, targetComponentService, targetBinding);
+
+ /*
+ // if static forward wire (not from self-reference), try to create a static callback wire
+ if (targetComponentService != null && !reference.getName().startsWith("$self$.")) {
+ ComponentReference callbackReference = targetComponentService.getCallbackReference();
+ if (callbackReference != null) {
+ Binding callbackBinding = null;
+ Binding callbackServiceBinding = null;
+ // select a service callback binding that can be wired back to this component
+ for (Binding refBinding : callbackReference.getBindings()) {
+ // first look for a callback binding whose name matches the target binding name
+ if (refBinding.getName().equals(targetBinding.getName())) {
+ callbackBinding = refBinding;
+ break;
+ }
+ }
+ // see if there is a matching reference callback binding
+ if (callbackBinding != null) {
+ callbackServiceBinding = reference.getCallbackService().getBinding(callbackBinding.getClass());
+ }
+ // if there isn't an end-to-end match, try again based on target binding type
+ if (callbackBinding == null || callbackServiceBinding == null) {
+ callbackBinding = callbackReference.getBinding(targetBinding.getClass());
+ if (callbackBinding != null) {
+ callbackServiceBinding = reference.getCallbackService().getBinding(callbackBinding.getClass());
+ }
+ }
+ if (callbackBinding != null && callbackServiceBinding != null) {
+ // end-to-end match, so create a static callback wire as well as the static forward wire
+
+ addReferenceWire(targetComponent, callbackReference, callbackBinding, component, reference
+ .getCallbackService(), callbackServiceBinding);
+ } else {
+ // no end-to-end match, so do not create a static callback wire
+ }
+ }
+ }
+ */
+ }
+
+ public void addReferenceWireForEndpoint(Endpoint endpoint){
+ addReferenceWire(endpoint.getSourceComponent(),
+ endpoint.getSourceComponentReference(),
+ endpoint.getSourceBinding(),
+ endpoint.getTargetComponent(),
+ endpoint.getTargetComponentService(),
+ endpoint.getTargetBinding());
+ }
+ /**
+ * Create a reference wire for a forward call or a callback
+ * @param reference
+ * @param service
+ * @param serviceBinding
+ * @param component
+ * @param referenceBinding
+ */
+ private RuntimeWire addReferenceWire(Component refComponent,
+ ComponentReference reference,
+ Binding refBinding,
+ Component serviceComponent,
+ ComponentService service,
+ Binding serviceBinding) {
+ RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference;
+ InterfaceContract bindingContract = getInterfaceContract(reference, refBinding);
+
+ // Use the interface contract of the reference on the component type
+ Reference componentTypeRef = reference.getReference();
+
+ InterfaceContract sourceContract;
+ if (componentTypeRef == null || componentTypeRef.getInterfaceContract() == null) {
+ sourceContract = reference.getInterfaceContract();
+ } else {
+ sourceContract = componentTypeRef.getInterfaceContract();
+ }
+
+ sourceContract = sourceContract.makeUnidirectional(false);
+
+ EndpointReference wireSource =
+ new EndpointReferenceImpl((RuntimeComponent)refComponent, reference, refBinding, sourceContract);
+ ComponentService callbackService = reference.getCallbackService();
+ if (callbackService != null) {
+ // select a reference callback binding to pass with invocations on this wire
+ Binding callbackBinding = null;
+ for (Binding binding : callbackService.getBindings()) {
+ // first look for a callback binding whose name matches the reference binding name
+ if (refBinding.getName().startsWith(binding.getName())) {
+ callbackBinding = binding;
+ break;
+ }
+ }
+ // if no callback binding found, try again based on reference binding type
+ if (callbackBinding == null) {
+ callbackBinding = callbackService.getBinding(refBinding.getClass());
+ }
+ InterfaceContract callbackContract = callbackService.getInterfaceContract();
+ EndpointReference callbackEndpoint =
+ new EndpointReferenceImpl((RuntimeComponent)refComponent, callbackService, callbackBinding,
+ callbackContract);
+ wireSource.setCallbackEndpoint(callbackEndpoint);
+ }
+
+ EndpointReference wireTarget =
+ new EndpointReferenceImpl((RuntimeComponent)serviceComponent, service, serviceBinding, bindingContract);
+
+ // TUSCANY-2029 - We should use the URI of the serviceBinding because the target may be a Component in a
+ // nested composite.
+ if (serviceBinding != null) {
+ wireTarget.setURI(serviceBinding.getURI());
+ }
+
+ RuntimeWire wire =
+ new RuntimeWireImpl(wireSource, wireTarget, interfaceContractMapper, workScheduler, wireProcessor,
+ messageFactory, conversationManager);
+ runtimeRef.getRuntimeWires().add(wire);
+
+ return wire;
+ }
+
+ private void addImplementationProvider(RuntimeComponent component, Implementation implementation) {
+ ImplementationProviderFactory providerFactory =
+ (ImplementationProviderFactory)providerFactories.getProviderFactory(implementation.getClass());
+ if (providerFactory != null) {
+ @SuppressWarnings("unchecked")
+ ImplementationProvider implementationProvider =
+ providerFactory.createImplementationProvider(component, implementation);
+ if (implementationProvider != null) {
+ component.setImplementationProvider(implementationProvider);
+ }
+ } else {
+ throw new IllegalStateException("Provider factory not found for class: " + implementation.getClass()
+ .getName());
+ }
+ for (PolicyProviderFactory f : providerFactories.getPolicyProviderFactories()) {
+ PolicyProvider policyProvider = f.createImplementationPolicyProvider(component, implementation);
+ if (policyProvider != null) {
+ component.addPolicyProvider(policyProvider);
+ }
+ }
+
+ }
+
+ private void removeImplementationProvider(RuntimeComponent component) {
+ component.setImplementationProvider(null);
+ component.getPolicyProviders().clear();
+ }
+
+ /**
+ * @param component
+ * @param service
+ * @param binding
+ */
+ private ServiceBindingProvider addServiceBindingProvider(RuntimeComponent component,
+ RuntimeComponentService service,
+ Binding binding) {
+ BindingProviderFactory providerFactory =
+ (BindingProviderFactory)providerFactories.getProviderFactory(binding.getClass());
+ if (providerFactory != null) {
+ @SuppressWarnings("unchecked")
+ ServiceBindingProvider bindingProvider =
+ providerFactory.createServiceBindingProvider((RuntimeComponent)component,
+ (RuntimeComponentService)service,
+ binding);
+ if (bindingProvider != null) {
+ ((RuntimeComponentService)service).setBindingProvider(binding, bindingProvider);
+ }
+ for (PolicyProviderFactory f : providerFactories.getPolicyProviderFactories()) {
+ PolicyProvider policyProvider = f.createServicePolicyProvider(component, service, binding);
+ if (policyProvider != null) {
+ service.addPolicyProvider(binding, policyProvider);
+ }
+ }
+ return bindingProvider;
+ } else {
+ throw new IllegalStateException("Provider factory not found for class: " + binding.getClass().getName());
+ }
+ }
+
+ private void removeServiceBindingProvider(RuntimeComponent component,
+ RuntimeComponentService service,
+ Binding binding) {
+ service.setBindingProvider(binding, null);
+ for (Binding b : service.getBindings()) {
+ List<PolicyProvider> pps = service.getPolicyProviders(b);
+ if (pps != null) {
+ pps.clear();
+ }
+ }
+ }
+
+ private void removeReferenceBindingProvider(RuntimeComponent component,
+ RuntimeComponentReference reference,
+ Binding binding) {
+ reference.setBindingProvider(binding, null);
+ for (Binding b : reference.getBindings()) {
+ List<PolicyProvider> pps = reference.getPolicyProviders(b);
+ if (pps != null) {
+ pps.clear();
+ }
+ }
+ }
+
+ public void start(Composite composite) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Starting composite: " + composite.getName());
+ }
+ for (Component component : composite.getComponents()) {
+ start(component);
+ }
+ }
+
+ public void stop(Composite composite) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Stopping composite: " + composite.getName());
+ }
+ for (final Component component : composite.getComponents()) {
+ stop(component);
+ }
+ }
+
+ public void start(Component component) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Starting component: " + component.getURI());
+ }
+ RuntimeComponent runtimeComponent = ((RuntimeComponent)component);
+ if(runtimeComponent.isStarted()) {
+ return;
+ }
+
+ configureComponentContext(runtimeComponent);
+
+ for (ComponentReference reference : component.getReferences()) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Starting component reference: " + component.getURI() + "#" + reference.getName());
+ }
+ RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference);
+ runtimeRef.setComponent(runtimeComponent);
+
+ for (Endpoint endpoint : reference.getEndpoints()) {
+ final EndpointResolver endpointResolver = runtimeRef.getEndpointResolver(endpoint);
+ if (endpointResolver != null) {
+ // Allow endpoint resolvers to do any startup reference manipulation
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ endpointResolver.start();
+ return null;
+ }
+ });
+ }
+ }
+
+ for (Binding binding : reference.getBindings()) {
+ final ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(binding);
+ if (bindingProvider != null) {
+ // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy.
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ bindingProvider.start();
+ return null;
+ }
+ });
+ }
+ }
+ }
+
+ for (ComponentService service : component.getServices()) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Starting component service: " + component.getURI() + "#" + service.getName());
+ }
+ RuntimeComponentService runtimeService = (RuntimeComponentService)service;
+ for (Binding binding : service.getBindings()) {
+ final ServiceBindingProvider bindingProvider = runtimeService.getBindingProvider(binding);
+ if (bindingProvider != null) {
+ // bindingProvider.start();
+ // Allow bindings to add shutdown hooks. Requires RuntimePermission shutdownHooks in policy.
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ bindingProvider.start();
+ return null;
+ }
+ });
+ }
+ }
+ }
+
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ start((Composite)implementation);
+ } else {
+ ImplementationProvider implementationProvider = runtimeComponent.getImplementationProvider();
+ if (implementationProvider != null) {
+ implementationProvider.start();
+ }
+ }
+
+ if (component instanceof ScopedRuntimeComponent) {
+ ScopedRuntimeComponent scopedRuntimeComponent = (ScopedRuntimeComponent)component;
+ if (scopedRuntimeComponent.getScopeContainer() != null) {
+ scopedRuntimeComponent.getScopeContainer().start();
+ }
+ }
+
+ runtimeComponent.setStarted(true);
+ }
+
+ /**
+ * @param runtimeComponent
+ */
+ public void configureComponentContext(RuntimeComponent runtimeComponent) {
+ RuntimeComponentContext componentContext =
+ new ComponentContextImpl(this, assemblyFactory, proxyFactory, interfaceContractMapper,
+ requestContextFactory, javaInterfaceFactory, runtimeComponent);
+ runtimeComponent.setComponentContext(componentContext);
+ }
+
+ /**
+ * Stop a component
+ */
+ public void stop(Component component) {
+ if (!((RuntimeComponent)component).isStarted()) {
+ return;
+ }
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Stopping component: " + component.getURI());
+ }
+ for (ComponentService service : component.getServices()) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Stopping component service: " + component.getURI() + "#" + service.getName());
+ }
+ for (Binding binding : service.getBindings()) {
+ final ServiceBindingProvider bindingProvider = ((RuntimeComponentService)service).getBindingProvider(binding);
+ if (bindingProvider != null) {
+ // Allow bindings to read properties. Requires PropertyPermission read in security policy.
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ bindingProvider.stop();
+ return null;
+ }
+ });
+ }
+ }
+ }
+ for (ComponentReference reference : component.getReferences()) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Starting component reference: " + component.getURI() + "#" + reference.getName());
+ }
+ RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)reference);
+
+ for (Binding binding : reference.getBindings()) {
+ final ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(binding);
+ if (bindingProvider != null) {
+ // Allow bindings to read properties. Requires PropertyPermission read in security policy.
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ bindingProvider.stop();
+ return null;
+ }
+ });
+ }
+ }
+
+ for (Endpoint endpoint : reference.getEndpoints()) {
+ final EndpointResolver endpointResolver = runtimeRef.getEndpointResolver(endpoint);
+ if (endpointResolver != null) {
+ // Allow endpoint resolvers to do any shutdown reference manipulation
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ endpointResolver.stop();
+ return null;
+ }
+ });
+ }
+ }
+ }
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ stop((Composite)implementation);
+ } else {
+ final ImplementationProvider implementationProvider = ((RuntimeComponent)component).getImplementationProvider();
+ if (implementationProvider != null) {
+ // Allow bindings to read properties. Requires PropertyPermission read in security policy.
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ implementationProvider.stop();
+ return null;
+ }
+ });
+ }
+ }
+
+ if (component instanceof ScopedRuntimeComponent) {
+ ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component;
+ if (runtimeComponent.getScopeContainer() != null &&
+ runtimeComponent.getScopeContainer().getLifecycleState() != ScopeContainer.STOPPED) {
+ runtimeComponent.getScopeContainer().stop();
+ }
+ }
+
+ ((RuntimeComponent)component).setStarted(false);
+ }
+
+ /**
+ * Get the effective interface contract for a reference binding
+ *
+ * @param reference
+ * @param binding
+ * @return
+ */
+ private InterfaceContract getInterfaceContract(ComponentReference reference, Binding binding) {
+ InterfaceContract interfaceContract = reference.getInterfaceContract();
+ ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding);
+ if (provider != null) {
+ InterfaceContract bindingContract = provider.getBindingInterfaceContract();
+ if (bindingContract != null) {
+ interfaceContract = bindingContract;
+ }
+ }
+ return interfaceContract.makeUnidirectional(false);
+ }
+
+ /**
+ * Remove the runtime wires for a reference binding
+ * @param reference
+ */
+ private void removeReferenceWires(ComponentReference reference) {
+ if (!(reference instanceof RuntimeComponentReference)) {
+ return;
+ }
+ // [rfeng] Comment out the following statements to avoid the on-demand activation
+ // RuntimeComponentReference runtimeRef = (RuntimeComponentReference)reference;
+ // runtimeRef.getRuntimeWires().clear();
+ }
+
+ /**
+ * Get the effective interface contract for the service binding
+ *
+ * @param service
+ * @param binding
+ * @return
+ */
+ private InterfaceContract getInterfaceContract(ComponentService service, Binding binding) {
+ InterfaceContract interfaceContract = service.getInterfaceContract();
+
+ ServiceBindingProvider provider = ((RuntimeComponentService)service).getBindingProvider(binding);
+ if (provider != null) {
+ InterfaceContract bindingContract = provider.getBindingInterfaceContract();
+ if (bindingContract != null) {
+ interfaceContract = bindingContract;
+ }
+ }
+ return interfaceContract.makeUnidirectional(false);
+ }
+
+ /**
+ * Remove runtime wires for a service binding
+ *
+ * @param component
+ * @param service
+ */
+ private void removeServiceWires(ComponentService service) {
+ if (!(service instanceof RuntimeComponentService)) {
+ return;
+ }
+ RuntimeComponentService runtimeService = (RuntimeComponentService)service;
+ runtimeService.getRuntimeWires().clear();
+ }
+
+ /**
+ * Create a service wire for a forward call or a callback
+ * @param service
+ * @param serviceBinding
+ * @param reference
+ * @param component
+ * @param referenceBinding
+ */
+ private RuntimeWire addServiceWire(Component serviceComponent, ComponentService service, Binding serviceBinding) {
+ if (!(service instanceof RuntimeComponentService)) {
+ return null;
+ }
+ RuntimeComponentService runtimeService = (RuntimeComponentService)service;
+
+ // FIXME: [rfeng] We might need a better way to get the impl interface contract
+ Service targetService = service.getService();
+ if (targetService == null) {
+ targetService = service;
+ }
+ InterfaceContract targetContract = targetService.getInterfaceContract().makeUnidirectional(false);
+
+ InterfaceContract sourceContract = getInterfaceContract(service, serviceBinding);
+
+ EndpointReference wireSource = new EndpointReferenceImpl(null, null, serviceBinding, sourceContract);
+
+ EndpointReference wireTarget =
+ new EndpointReferenceImpl((RuntimeComponent)serviceComponent, (RuntimeComponentService)service,
+ serviceBinding, targetContract);
+
+ RuntimeWire wire =
+ new RuntimeWireImpl(wireSource, wireTarget, interfaceContractMapper, workScheduler, wireProcessor,
+ messageFactory, conversationManager);
+ runtimeService.getRuntimeWires().add(wire);
+
+ return wire;
+ }
+
+ public void activate(RuntimeComponent component, RuntimeComponentService service) {
+ if (service.getService() == null) {
+ if (logger.isLoggable(Level.WARNING)) {
+ logger.warning("Skipping component service not defined in the component type: " + component.getURI()
+ + "#"
+ + service.getName());
+ }
+ return;
+ }
+ if (service.getService() instanceof CompositeService) {
+ return;
+ }
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Activating component service: " + component.getURI() + "#" + service.getName());
+ }
+
+ for (Binding binding : service.getBindings()) {
+ addServiceBindingProvider(component, service, binding);
+ addServiceWire(component, service, binding);
+ }
+ }
+
+ public void deactivate(RuntimeComponent component, RuntimeComponentService service) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Deactivating component service: " + component.getURI() + "#" + service.getName());
+ }
+ removeServiceWires(service);
+ for (Binding binding : service.getBindings()) {
+ removeServiceBindingProvider(component, service, binding);
+ }
+ }
+
+ private void addScopeContainer(Component component) {
+ if (!(component instanceof ScopedRuntimeComponent)) {
+ return;
+ }
+ ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component;
+ ScopeContainer scopeContainer = scopeRegistry.getScopeContainer(runtimeComponent);
+ if (scopeContainer != null && scopeContainer.getScope() == Scope.CONVERSATION) {
+ conversationManager.addListener((ConversationalScopeContainer)scopeContainer);
+ }
+ runtimeComponent.setScopeContainer(scopeContainer);
+ }
+
+ private void removeScopeContainer(Component component) {
+ if (!(component instanceof ScopedRuntimeComponent)) {
+ return;
+ }
+ ScopedRuntimeComponent runtimeComponent = (ScopedRuntimeComponent)component;
+ ScopeContainer scopeContainer = runtimeComponent.getScopeContainer();
+ if(scopeContainer != null && scopeContainer.getScope() == Scope.CONVERSATION) {
+ conversationManager.removeListener((ConversationalScopeContainer) scopeContainer);
+ }
+ runtimeComponent.setScopeContainer(null);
+ }
+
+ public void activateComponent(Component component)
+ throws ActivationException {
+ try {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Activating component: " + component.getURI());
+ }
+
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ activate((Composite) implementation);
+ } else if (implementation != null) {
+ addImplementationProvider((RuntimeComponent) component,
+ implementation);
+ addScopeContainer(component);
+ }
+
+ for (ComponentService service : component.getServices()) {
+ activate((RuntimeComponent) component,
+ (RuntimeComponentService) service);
+ }
+
+ for (ComponentReference reference : component.getReferences()) {
+ activate((RuntimeComponent) component,
+ (RuntimeComponentReference) reference);
+ }
+ } catch (Exception e) {
+ throw new ActivationException(e);
+ }
+ }
+
+ public void deactivateComponent(Component component)
+ throws ActivationException {
+ try {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Deactivating component: " + component.getURI());
+ }
+ for (ComponentService service : component.getServices()) {
+ deactivate((RuntimeComponent) component,
+ (RuntimeComponentService) service);
+ }
+
+ for (ComponentReference reference : component.getReferences()) {
+ deactivate((RuntimeComponent) component,
+ (RuntimeComponentReference) reference);
+ }
+
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ deactivate((Composite) implementation);
+ } else if (implementation != null) {
+ removeImplementationProvider((RuntimeComponent) component);
+ removeScopeContainer(component);
+ }
+ } catch (Exception e) {
+ throw new ActivationException(e);
+ }
+ }
+
+ public void activate(Composite composite) throws ActivationException {
+ try {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Activating composite: " + composite.getName());
+ }
+ for (Component component : composite.getComponents()) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Activating component: " + component.getURI());
+ }
+
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ activate((Composite)implementation);
+ } else if (implementation != null) {
+ addImplementationProvider((RuntimeComponent)component, implementation);
+ addScopeContainer(component);
+ }
+
+ for (ComponentService service : component.getServices()) {
+ activate((RuntimeComponent)component, (RuntimeComponentService)service);
+ }
+
+ for (ComponentReference reference : component.getReferences()) {
+ activate((RuntimeComponent)component, (RuntimeComponentReference)reference);
+ }
+ }
+ } catch (Exception e) {
+ throw new ActivationException(e);
+ }
+ }
+
+ public void deactivate(Composite composite) throws ActivationException {
+ try {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Deactivating composite: " + composite.getName());
+ }
+ for (Component component : composite.getComponents()) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Deactivating component: " + component.getURI());
+ }
+ for (ComponentService service : component.getServices()) {
+ deactivate((RuntimeComponent)component, (RuntimeComponentService)service);
+ }
+
+ for (ComponentReference reference : component.getReferences()) {
+ deactivate((RuntimeComponent)component, (RuntimeComponentReference)reference);
+ }
+
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof Composite) {
+ deactivate((Composite)implementation);
+ } else if (implementation != null) {
+ removeImplementationProvider((RuntimeComponent)component);
+ removeScopeContainer(component);
+ }
+ }
+ } catch (Exception e) {
+ throw new ActivationException(e);
+ }
+ }
+
+ /**
+ * @return the referenceHelper
+ */
+ public ComponentContextHelper getComponentContextHelper() {
+ return componentContextHelper;
+ }
+
+ /**
+ * @return the proxyFactory
+ */
+ public ProxyFactory getProxyFactory() {
+ return proxyFactory;
+ }
+
+ /**
+ * @return the domainComposite
+ */
+ public Composite getDomainComposite() {
+ return domainComposite;
+ }
+
+ /**
+ * @param domainComposite the domainComposite to set
+ */
+ public void setDomainComposite(Composite domainComposite) {
+ this.domainComposite = domainComposite;
+ }
+
+ public Component resolve(String componentURI) {
+ for (Composite composite : domainComposite.getIncludes()) {
+ Component component = resolve(composite, componentURI);
+ if (component != null) {
+ return component;
+ }
+ }
+ return null;
+ }
+
+ public Component resolve(Composite composite, String componentURI) {
+ for (Component component : composite.getComponents()) {
+ String uri = component.getURI();
+ if (uri.equals(componentURI)) {
+ return component;
+ }
+ if (componentURI.startsWith(uri)) {
+ Implementation implementation = component.getImplementation();
+ if (!(implementation instanceof Composite)) {
+ return null;
+ }
+ return resolve((Composite)implementation, componentURI);
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @return the javaInterfaceFactory
+ */
+ public JavaInterfaceFactory getJavaInterfaceFactory() {
+ return javaInterfaceFactory;
+ }
+
+ /**
+ * @return the conversationManager
+ */
+ public ConversationManager getConversationManager() {
+ return conversationManager;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointReferenceImpl.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointReferenceImpl.java
new file mode 100644
index 0000000000..78096b20ab
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointReferenceImpl.java
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.assembly;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Contract;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.apache.tuscany.sca.runtime.ReferenceParameters;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class EndpointReferenceImpl implements EndpointReference {
+ private RuntimeComponent component;
+ private Contract contract;
+ private Binding binding;
+ private InterfaceContract interfaceContract;
+ private String uri;
+ private EndpointReference callbackEndpoint;
+ private ReferenceParameters parameters = new ReferenceParametersImpl();
+
+ /**
+ * @param component
+ * @param contract
+ * @param binding
+ * @param interfaceContract
+ */
+ public EndpointReferenceImpl(RuntimeComponent component,
+ Contract contract,
+ Binding binding,
+ InterfaceContract interfaceContract) {
+ super();
+ this.component = component;
+ this.contract = contract;
+ this.binding = binding;
+ this.interfaceContract = interfaceContract;
+ this.uri = (component != null ? component.getURI() : "") + '/' +
+ (contract != null ? contract.getName() : "");
+ }
+
+ /**
+ * @param uri
+ */
+ public EndpointReferenceImpl(String uri) {
+ super();
+ this.uri = uri;
+ }
+
+ public Binding getBinding() {
+ return binding;
+ }
+
+ public void setBinding(Binding binding) {
+ this.binding = binding;
+ }
+
+ public RuntimeComponent getComponent() {
+ return component;
+ }
+
+ public void setComponent(RuntimeComponent component) {
+ this.component = component;
+ }
+
+ public Contract getContract() {
+ return contract;
+ }
+
+ public void setContract(Contract contract) {
+ this.contract = contract;
+ }
+
+ public InterfaceContract getInterfaceContract() {
+ return interfaceContract;
+ }
+
+ public void setInterfaceContract(InterfaceContract interfaceContract) {
+ this.interfaceContract = interfaceContract;
+ }
+
+ public String getURI() {
+ return uri;
+ }
+
+ public void setURI(String uri) {
+ this.uri = uri;
+ }
+
+ public EndpointReference getCallbackEndpoint() {
+ return callbackEndpoint;
+ }
+
+ public void setCallbackEndpoint(EndpointReference callbackEndpoint) {
+ this.callbackEndpoint = callbackEndpoint;
+ }
+
+ @Override
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + ((uri == null) ? 0 : uri.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ final EndpointReferenceImpl other = (EndpointReferenceImpl)obj;
+ if (uri == null) {
+ if (other.uri != null) {
+ return false;
+ }
+ } else if (!uri.equals(other.uri)) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * @see java.lang.Object#clone()
+ */
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ EndpointReferenceImpl copy = (EndpointReferenceImpl)super.clone();
+ /* [nash] no need to copy callback endpoint
+ if (callbackEndpoint != null) {
+ copy.callbackEndpoint = (EndpointReference)callbackEndpoint.clone();
+ }
+ */
+ if (parameters != null) {
+ copy.parameters = (ReferenceParameters)parameters.clone();
+ }
+ return copy;
+ }
+
+ /**
+ * @return the parameters
+ */
+ public ReferenceParameters getReferenceParameters() {
+ return parameters;
+ }
+
+ /**
+ * @param parameters the parameters to set
+ */
+ public void setReferenceParameters(ReferenceParameters parameters) {
+ this.parameters = parameters;
+ }
+
+ public void mergeEndpoint(EndpointReference epr) {
+ this.component = epr.getComponent();
+ this.contract = epr.getContract();
+ this.binding = epr.getBinding();
+ this.interfaceContract = epr.getInterfaceContract();
+ this.uri = epr.getURI();
+ this.callbackEndpoint = epr.getCallbackEndpoint();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointWireImpl.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointWireImpl.java
new file mode 100644
index 0000000000..c25c580fe6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/EndpointWireImpl.java
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.assembly;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.endpointresolver.EndpointResolver;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.ServiceUnavailableException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class EndpointWireImpl implements RuntimeWire {
+
+ private Endpoint endpoint;
+ private CompositeActivatorImpl compositeActivator;
+
+ private EndpointResolver endpointResolver;
+ private EndpointReference source;
+ private RuntimeWire wire;
+
+ /**
+ * @param endpoint
+ */
+ public EndpointWireImpl(Endpoint endpoint, CompositeActivator compositeActivator) {
+ super();
+ this.endpoint = endpoint;
+ // TODO - improve the SPI to get rid of this cast
+ this.compositeActivator = (CompositeActivatorImpl)compositeActivator;
+
+ // store source configuration as we have most of this now. We don't though know what the
+ // target is yet.
+ Reference componentTypeRef = endpoint.getSourceComponentReference().getReference();
+ InterfaceContract sourceContract =
+ componentTypeRef == null ? endpoint.getSourceComponentReference().getInterfaceContract() : componentTypeRef.getInterfaceContract();
+ sourceContract = sourceContract.makeUnidirectional(false);
+
+ source = new EndpointReferenceImpl((RuntimeComponent)endpoint.getSourceComponent(),
+ endpoint.getSourceComponentReference(),
+ null,
+ sourceContract);
+
+ RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)endpoint.getSourceComponentReference());
+ endpointResolver = runtimeRef.getEndpointResolver(endpoint);
+
+ }
+
+ public synchronized List<InvocationChain> getInvocationChains() {
+ // where late binding happens. Find the endpoint provider and
+ // ask it to do the endpoint resolution.
+ if (endpoint.isUnresolved()){
+
+ // this method should locate a viable target service and complete the
+ // endpoint configuration
+ endpointResolver.resolve();
+
+ if (endpoint.isUnresolved()){
+ throw new ServiceUnavailableException("Unable to resolve service for component: " +
+ endpoint.getSourceComponent().getName() +
+ " reference: " +
+ endpoint.getSourceComponentReference().getName() +
+ " target: " +
+ endpoint.getTargetName());
+ }
+ }
+
+ if (wire == null){
+ RuntimeComponentReference runtimeRef = ((RuntimeComponentReference)endpoint.getSourceComponentReference());
+
+ // add the resolved binding into the reference
+ runtimeRef.getBindings().add(endpoint.getSourceBinding());
+
+ // add a binding provider into the reference for the resolved binding
+ compositeActivator.addReferenceBindingProviderForEndpoint(endpoint);
+
+ // extract the binding provider that has been created
+ ReferenceBindingProvider bindingProvider = runtimeRef.getBindingProvider(endpoint.getSourceBinding());
+
+ // start the binding provider
+ bindingProvider.start();
+
+ // create the wire
+ compositeActivator.addReferenceWireForEndpoint(endpoint);
+
+ // extract the wire that has been created
+ wire = runtimeRef.getRuntimeWire(endpoint.getSourceBinding());
+ }
+
+ return wire.getInvocationChains();
+ }
+
+ public InvocationChain getInvocationChain(Operation operation) {
+ if (wire ==null){
+ return null;
+ } else {
+ return wire.getInvocationChain(operation);
+ }
+ }
+
+ public Object invoke(Operation operation, Object[] args) throws InvocationTargetException {
+ // not called as the endpoint wire only appears on the reference side
+ return null;
+ }
+
+ public Object invoke(Operation operation, Message msg) throws InvocationTargetException {
+ // not called as the endpoint wire only appears on the reference side
+ return null;
+ }
+
+
+ public EndpointReference getSource() {
+ return source;
+ }
+
+ public EndpointReference getTarget() {
+ return null;
+ }
+
+ public void setTarget(EndpointReference target) {
+ }
+
+ public void rebuild() {
+ }
+
+ // TODO: TUSCANY-2580: give RuntimeComponentReferenceImpl a way to get at the endpoint
+ public Endpoint getEndpoint() {
+ return endpoint;
+ }
+
+ /**
+ * @see java.lang.Object#clone()
+ */
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ EndpointWireImpl copy = (EndpointWireImpl)super.clone();
+ return copy;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ReferenceParameterProcessor.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ReferenceParameterProcessor.java
new file mode 100644
index 0000000000..c82543c4ca
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ReferenceParameterProcessor.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.assembly;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.runtime.ReferenceParameters;
+
+/**
+ * Artifact processor for reference parameters.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReferenceParameterProcessor implements StAXArtifactProcessor<ReferenceParameters> {
+ private static final QName REFERENCE_PARAMETERS =
+ new QName("http://tuscany.apache.org/xmlns/sca/1.0", "referenceParameters", "tuscany");
+
+ /**
+ * Constructs a new processor.
+ *
+ * @param modelFactories
+ */
+ public ReferenceParameterProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#getArtifactType()
+ */
+ public QName getArtifactType() {
+ return REFERENCE_PARAMETERS;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#read(javax.xml.stream.XMLStreamReader)
+ */
+ public ReferenceParameters read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ ReferenceParameters parameters = new ReferenceParametersImpl();
+ parameters.setConversationID(reader.getAttributeValue(null, "conversationID"));
+ parameters.setCallbackID(reader.getAttributeValue(null, "callbackID"));
+ return parameters;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor#write(java.lang.Object, javax.xml.stream.XMLStreamWriter)
+ */
+ public void write(ReferenceParameters model, XMLStreamWriter writer) throws ContributionWriteException,
+ XMLStreamException {
+ writer.writeStartElement(REFERENCE_PARAMETERS.getPrefix(),
+ REFERENCE_PARAMETERS.getLocalPart(),
+ REFERENCE_PARAMETERS.getNamespaceURI());
+ writer.writeNamespace(REFERENCE_PARAMETERS.getPrefix(), REFERENCE_PARAMETERS.getNamespaceURI());
+ if (model.getConversationID() != null) {
+ writer.writeAttribute("conversationID", model.getConversationID().toString());
+ }
+ if (model.getCallbackID() != null) {
+ writer.writeAttribute("callbackID", model.getCallbackID().toString());
+ }
+ writer.writeEndElement();
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.contribution.processor.ArtifactProcessor#getModelType()
+ */
+ public Class<ReferenceParameters> getModelType() {
+ return ReferenceParameters.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.contribution.processor.ArtifactProcessor#resolve(java.lang.Object, org.apache.tuscany.sca.contribution.resolver.ModelResolver)
+ */
+ public void resolve(ReferenceParameters model, ModelResolver resolver) throws ContributionResolveException {
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ReferenceParametersImpl.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ReferenceParametersImpl.java
new file mode 100644
index 0000000000..14a5f565fc
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/ReferenceParametersImpl.java
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.assembly;
+
+import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.apache.tuscany.sca.runtime.ReferenceParameters;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReferenceParametersImpl implements ReferenceParameters {
+ private Object callbackID;
+ private Object conversationID;
+ private EndpointReference callbackReference;
+ private Object callbackObjectID;
+
+ /**
+ * @return the callbackID
+ */
+ public Object getCallbackID() {
+ return callbackID;
+ }
+ /**
+ * @param callbackID the callbackID to set
+ */
+ public void setCallbackID(Object callbackID) {
+ this.callbackID = callbackID;
+ }
+ /**
+ * @return the conversationID
+ */
+ public Object getConversationID() {
+ return conversationID;
+ }
+ /**
+ * @param conversationID the conversationID to set
+ */
+ public void setConversationID(Object conversationID) {
+ this.conversationID = conversationID;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.runtime.ReferenceParameters#getCallbackReference()
+ */
+ public EndpointReference getCallbackReference() {
+ return callbackReference;
+ }
+ /**
+ * @see org.apache.tuscany.sca.runtime.ReferenceParameters#setCallback(java.lang.Object)
+ */
+ public void setCallbackReference(EndpointReference callback) {
+ this.callbackReference = callback;
+ }
+
+ /**
+ * @see java.lang.Object#clone()
+ */
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+ /**
+ * @return the callbackObjectID
+ */
+ public Object getCallbackObjectID() {
+ return callbackObjectID;
+ }
+ /**
+ * @param callbackObjectID the callbackObjectID to set
+ */
+ public void setCallbackObjectID(Object callbackObjectID) {
+ this.callbackObjectID = callbackObjectID;
+ }
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((callbackID == null) ? 0 : callbackID.hashCode());
+ result = prime * result + ((callbackObjectID == null) ? 0 : callbackObjectID.hashCode());
+ result = prime * result + ((callbackReference == null) ? 0 : callbackReference.hashCode());
+ result = prime * result + ((conversationID == null) ? 0 : conversationID.hashCode());
+ return result;
+ }
+ /**
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (!(obj instanceof ReferenceParametersImpl))
+ return false;
+ final ReferenceParametersImpl other = (ReferenceParametersImpl)obj;
+ if (callbackID == null) {
+ if (other.callbackID != null)
+ return false;
+ } else if (!callbackID.equals(other.callbackID))
+ return false;
+ if (callbackObjectID == null) {
+ if (other.callbackObjectID != null)
+ return false;
+ } else if (!callbackObjectID.equals(other.callbackObjectID))
+ return false;
+ if (callbackReference == null) {
+ if (other.callbackReference != null)
+ return false;
+ } else if (!callbackReference.equals(other.callbackReference))
+ return false;
+ if (conversationID == null) {
+ if (other.conversationID != null)
+ return false;
+ } else if (!conversationID.equals(other.conversationID))
+ return false;
+ return true;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java
new file mode 100644
index 0000000000..b174dea6ce
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeAssemblyFactory.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.assembly;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+
+/**
+ * The runtime version of assembly factory
+ * @version $Rev$ $Date$
+ */
+public class RuntimeAssemblyFactory extends DefaultAssemblyFactory implements AssemblyFactory {
+
+ public RuntimeAssemblyFactory() {
+ super();
+ }
+
+ @Override
+ public Component createComponent() {
+ return new RuntimeComponentImpl();
+ }
+
+ @Override
+ public ComponentReference createComponentReference() {
+ return new RuntimeComponentReferenceImpl();
+ }
+
+ @Override
+ public ComponentService createComponentService() {
+ return new RuntimeComponentServiceImpl();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentImpl.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentImpl.java
new file mode 100644
index 0000000000..32ac611e54
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentImpl.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.assembly;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.impl.ComponentImpl;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ResolverExtension;
+import org.apache.tuscany.sca.core.scope.ScopeContainer;
+import org.apache.tuscany.sca.core.scope.ScopedRuntimeComponent;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.provider.PolicyProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentContext;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class RuntimeComponentImpl extends ComponentImpl implements RuntimeComponent,
+ ScopedRuntimeComponent, ResolverExtension {
+ protected RuntimeComponentContext componentContext;
+ protected ImplementationProvider implementationProvider;
+ protected List<PolicyProvider> policyProviders = new ArrayList<PolicyProvider>();
+ protected ScopeContainer scopeContainer;
+ protected boolean started;
+ protected ModelResolver modelResolver;
+
+ /**
+ */
+ public RuntimeComponentImpl() {
+ super();
+ }
+
+ public ImplementationProvider getImplementationProvider() {
+ return implementationProvider;
+ }
+
+ public void setImplementationProvider(ImplementationProvider provider) {
+ this.implementationProvider = provider;
+ }
+
+ public ScopeContainer getScopeContainer() {
+ return scopeContainer;
+ }
+
+ public void setScopeContainer(ScopeContainer scopeContainer) {
+ this.scopeContainer = scopeContainer;
+ }
+
+ public boolean isStarted() {
+ return started;
+ }
+
+ public void setStarted(boolean started) {
+ this.started = started;
+ }
+
+ /**
+ * @return the componentContext
+ */
+ public RuntimeComponentContext getComponentContext() {
+ return componentContext;
+ }
+
+ /**
+ * @param componentContext the componentContext to set
+ */
+ public void setComponentContext(RuntimeComponentContext componentContext) {
+ this.componentContext = componentContext;
+ }
+
+ public void addPolicyProvider(PolicyProvider policyProvider) {
+ policyProviders.add(policyProvider);
+ }
+
+ public List<PolicyProvider> getPolicyProviders() {
+ return policyProviders;
+ }
+
+ public ModelResolver getModelResolver() {
+ return modelResolver;
+ }
+
+ public void setModelResolver(ModelResolver modelResolver) {
+ this.modelResolver = modelResolver;
+ }
+
+ @Override
+ public String toString() {
+ return getName();
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentReferenceImpl.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentReferenceImpl.java
new file mode 100644
index 0000000000..b386495a08
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentReferenceImpl.java
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.assembly;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.impl.ComponentReferenceImpl;
+import org.apache.tuscany.sca.endpointresolver.EndpointResolver;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.provider.PolicyProvider;
+import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+
+/**
+ * Implementation of a Component Reference.
+ *
+ * @version $Rev$ $Date$
+ */
+public class RuntimeComponentReferenceImpl extends ComponentReferenceImpl implements RuntimeComponentReference {
+ private ArrayList<RuntimeWire> wires;
+ private HashMap<Binding, ReferenceBindingProvider> bindingProviders =
+ new HashMap<Binding, ReferenceBindingProvider>();
+ private HashMap<Endpoint, EndpointResolver> endpointResolvers =
+ new HashMap<Endpoint, EndpointResolver>();
+ private HashMap<Binding, List<PolicyProvider>> policyProviders = new HashMap<Binding, List<PolicyProvider>>();
+
+ private RuntimeComponent component;
+
+ public RuntimeComponentReferenceImpl() {
+ super();
+ }
+
+ public synchronized List<RuntimeWire> getRuntimeWires() {
+ if (wires == null) {
+ wires = new ArrayList<RuntimeWire>();
+ component.getComponentContext().start(this);
+ }
+ return wires;
+ }
+
+ public RuntimeWire getRuntimeWire(Binding binding) {
+ for (RuntimeWire wire : getRuntimeWires()) {
+ if (wire.getSource().getBinding() == binding) {
+ return wire;
+ }
+ }
+
+ // TODO: TUSCANY-2580: before returning null see if a candidate binding matches
+ for (RuntimeWire wire : getRuntimeWires()) {
+ if (wire instanceof EndpointWireImpl) {
+ Endpoint endpoint = ((EndpointWireImpl)wire).getEndpoint();
+ for (Binding b : endpoint.getCandidateBindings()) {
+ if (b == binding) {
+ return wire;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
+ public ReferenceBindingProvider getBindingProvider(Binding binding) {
+ return bindingProviders.get(binding);
+ }
+
+ public void setBindingProvider(Binding binding, ReferenceBindingProvider bindingProvider) {
+ bindingProviders.put(binding, bindingProvider);
+ }
+
+ public EndpointResolver getEndpointResolver(Endpoint endpoint){
+ return endpointResolvers.get(endpoint);
+ }
+
+ public void setEndpointResolver(Endpoint endpoint, EndpointResolver endpointResolver){
+ endpointResolvers.put(endpoint, endpointResolver);
+ }
+
+ public Invoker getInvoker(Binding binding, Operation operation) {
+ RuntimeWire wire = getRuntimeWire(binding);
+ if (wire == null) {
+ return null;
+ }
+ InvocationChain chain = wire.getInvocationChain(operation);
+ return chain == null ? null : chain.getHeadInvoker();
+ }
+
+ /**
+ * @return the component
+ */
+ public RuntimeComponent getComponent() {
+ return component;
+ }
+
+ /**
+ * @param component the component to set
+ */
+ public void setComponent(RuntimeComponent component) {
+ this.component = component;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.assembly.impl.ComponentReferenceImpl#clone()
+ */
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ RuntimeComponentReferenceImpl ref = (RuntimeComponentReferenceImpl)super.clone();
+ ref.wires = null;
+ ref.bindingProviders = new HashMap<Binding, ReferenceBindingProvider>();
+ ref.policyProviders = new HashMap<Binding, List<PolicyProvider>>();
+ return ref;
+ }
+
+ public void addPolicyProvider(Binding binding, PolicyProvider policyProvider) {
+ List<PolicyProvider> providers = policyProviders.get(binding);
+ if (providers == null) {
+ providers = new ArrayList<PolicyProvider>();
+ policyProviders.put(binding, providers);
+ }
+ providers.add(policyProvider);
+ }
+
+ public List<PolicyProvider> getPolicyProviders(Binding binding) {
+ return policyProviders.get(binding);
+ }
+
+ @Override
+ public String toString() {
+ return getName();
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentServiceImpl.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentServiceImpl.java
new file mode 100644
index 0000000000..af5230a163
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeComponentServiceImpl.java
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.assembly;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.impl.ComponentServiceImpl;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.provider.PolicyProvider;
+import org.apache.tuscany.sca.provider.ServiceBindingProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * Implementation of a Component Service.
+ *
+ * @version $Rev$ $Date$
+ */
+public class RuntimeComponentServiceImpl extends ComponentServiceImpl implements RuntimeComponentService {
+ private ArrayList<RuntimeWire> wires = new ArrayList<RuntimeWire>();
+ private ArrayList<RuntimeWire> callbackWires = new ArrayList<RuntimeWire>();
+ private HashMap<Binding, ServiceBindingProvider> bindingProviders = new HashMap<Binding, ServiceBindingProvider>();
+ private HashMap<Binding, List<PolicyProvider>> policyProviders = new HashMap<Binding, List<PolicyProvider>>();
+
+ public RuntimeComponentServiceImpl() {
+ super();
+ }
+
+ public List<RuntimeWire> getRuntimeWires() {
+ return wires;
+ }
+
+ public RuntimeWire getRuntimeWire(Binding binding) {
+ for (RuntimeWire wire : wires) {
+ if (wire.getTarget().getBinding() == binding) {
+ return wire;
+ }
+ }
+ return null;
+ }
+
+ public RuntimeWire getRuntimeWire(Binding binding, InterfaceContract interfaceContract) {
+ RuntimeWire wire = getRuntimeWire(binding);
+ if (wire == null) {
+ return null;
+ }
+ if (interfaceContract != null && interfaceContract != wire.getSource().getInterfaceContract()) {
+ try {
+ // FIXME: [rfeng] We could avoid clone() using a better comparison of the two interface contracts
+ wire = (RuntimeWire)wire.clone();
+ wire.getSource().setInterfaceContract(interfaceContract);
+ wire.rebuild();
+ } catch (CloneNotSupportedException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ return wire;
+ }
+
+ public List<RuntimeWire> getCallbackWires() {
+ return callbackWires;
+ }
+
+ public ServiceBindingProvider getBindingProvider(Binding binding) {
+ return bindingProviders.get(binding);
+ }
+
+ public void setBindingProvider(Binding binding, ServiceBindingProvider bindingProvider) {
+ bindingProviders.put(binding, bindingProvider);
+ }
+
+ public Invoker getInvoker(Binding binding, Operation operation) {
+ return getInvoker(binding, null, operation);
+ }
+
+ public Invoker getInvoker(Binding binding, InterfaceContract interfaceContract, Operation operation) {
+ InvocationChain chain = getInvocationChain(binding, interfaceContract, operation);
+ if (chain != null) {
+ return chain.getHeadInvoker();
+ } else {
+ return null;
+ }
+ }
+
+ public InvocationChain getInvocationChain(Binding binding, InterfaceContract interfaceContract, Operation operation) {
+ RuntimeWire wire = getRuntimeWire(binding);
+ if (wire == null) {
+ return null;
+ }
+ if (interfaceContract != null && interfaceContract != wire.getSource().getInterfaceContract()) {
+ try {
+ // FIXME: [rfeng] We could avoid clone() using a better comparison of the two interface contracts
+ wire = (RuntimeWire)wire.clone();
+ wire.getSource().setInterfaceContract(interfaceContract);
+ wire.rebuild();
+ } catch (CloneNotSupportedException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+ return wire.getInvocationChain(operation);
+ }
+
+ public InvocationChain getInvocationChain(Binding binding, Operation operation) {
+ return getInvocationChain(binding, null, operation);
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.assembly.impl.ComponentServiceImpl#clone()
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ RuntimeComponentServiceImpl clone = (RuntimeComponentServiceImpl)super.clone();
+ clone.bindingProviders = (HashMap<Binding, ServiceBindingProvider>)bindingProviders.clone();
+ clone.wires = (ArrayList<RuntimeWire>)wires.clone();
+ clone.callbackWires = (ArrayList<RuntimeWire>)callbackWires.clone();
+ clone.policyProviders = (HashMap<Binding, List<PolicyProvider>>)policyProviders.clone();
+ return clone;
+ }
+
+ public void addPolicyProvider(Binding binding, PolicyProvider policyProvider) {
+ List<PolicyProvider> providers = policyProviders.get(binding);
+ if (providers == null) {
+ providers = new ArrayList<PolicyProvider>();
+ policyProviders.put(binding, providers);
+ }
+ providers.add(policyProvider);
+ }
+
+ public List<PolicyProvider> getPolicyProviders(Binding binding) {
+ return policyProviders.get(binding);
+ }
+
+ @Override
+ public String toString() {
+ return getName();
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java
new file mode 100644
index 0000000000..58109fd86b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/assembly/RuntimeWireImpl.java
@@ -0,0 +1,378 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.assembly;
+
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Contract;
+import org.apache.tuscany.sca.core.conversation.ConversationManager;
+import org.apache.tuscany.sca.core.invocation.InvocationChainImpl;
+import org.apache.tuscany.sca.core.invocation.NonBlockingInterceptor;
+import org.apache.tuscany.sca.core.invocation.RuntimeWireInvoker;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.provider.PolicyProvider;
+import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
+import org.apache.tuscany.sca.provider.ServiceBindingProvider;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.apache.tuscany.sca.runtime.RuntimeWireProcessor;
+import org.apache.tuscany.sca.work.WorkScheduler;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class RuntimeWireImpl implements RuntimeWire {
+ private EndpointReference wireSource;
+ private EndpointReference wireTarget;
+
+ private transient RuntimeWireProcessor wireProcessor;
+ private transient InterfaceContractMapper interfaceContractMapper;
+ private transient WorkScheduler workScheduler;
+ private transient MessageFactory messageFactory;
+ private transient ConversationManager conversationManager;
+ private transient RuntimeWireInvoker invoker;
+
+ // the following is a very simple cache that avoids re-cloning a wire
+ // when consecutive callbacks to the same endpoint are made
+ private EndpointReference lastCallback;
+ private RuntimeWire cachedWire;
+ private boolean wireReserved;
+ private RuntimeWireImpl clonedFrom;
+
+ private List<InvocationChain> chains;
+
+ /**
+ * @param source
+ * @param target
+ * @param interfaceContractMapper
+ * @param workScheduler
+ * @param wireProcessor
+ * @param messageFactory
+ * @param conversationManager
+ */
+ public RuntimeWireImpl(EndpointReference source,
+ EndpointReference target,
+ InterfaceContractMapper interfaceContractMapper,
+ WorkScheduler workScheduler,
+ RuntimeWireProcessor wireProcessor,
+ MessageFactory messageFactory,
+ ConversationManager conversationManager) {
+ super();
+ this.wireSource = source;
+ this.wireTarget = target;
+ this.interfaceContractMapper = interfaceContractMapper;
+ this.workScheduler = workScheduler;
+ this.wireProcessor = wireProcessor;
+ this.messageFactory = messageFactory;
+ this.conversationManager = conversationManager;
+ this.invoker = new RuntimeWireInvoker(this.messageFactory, this.conversationManager, this);
+ }
+
+ public synchronized List<InvocationChain> getInvocationChains() {
+ if (chains == null) {
+ initInvocationChains();
+ }
+ return chains;
+ }
+
+ public InvocationChain getInvocationChain(Operation operation) {
+ for (InvocationChain chain : getInvocationChains()) {
+ Operation op = null;
+ if (wireSource.getContract() != null) {
+ // Reference chain
+ op = chain.getSourceOperation();
+ } else {
+ // Service chain
+ op = chain.getTargetOperation();
+ }
+ if (interfaceContractMapper.isCompatible(operation, op, op.getInterface().isRemotable())) {
+ return chain;
+ }
+ }
+ return null;
+ }
+
+ public Object invoke(Operation operation, Object[] args) throws InvocationTargetException {
+ Message msg = messageFactory.createMessage();
+ msg.setBody(args);
+ return invoker.invoke(operation, msg);
+ }
+
+ public Object invoke(Operation operation, Message msg) throws InvocationTargetException {
+ return invoker.invoke(operation, msg);
+ }
+
+ /**
+ * Initialize the invocation chains
+ */
+ private void initInvocationChains() {
+ chains = new ArrayList<InvocationChain>();
+ InterfaceContract sourceContract = wireSource.getInterfaceContract();
+ InterfaceContract targetContract = wireTarget.getInterfaceContract();
+
+ Contract source = wireSource.getContract();
+ if (source instanceof RuntimeComponentReference) {
+ // It's the reference wire
+ RuntimeComponentReference reference = (RuntimeComponentReference)wireSource.getContract();
+ Binding refBinding = wireSource.getBinding();
+ for (Operation operation : sourceContract.getInterface().getOperations()) {
+ Operation targetOperation = interfaceContractMapper.map(targetContract.getInterface(), operation);
+ if (targetOperation == null) {
+ throw new ServiceRuntimeException("No matching operation for " + operation.getName()
+ + " is found in reference "
+ + wireSource.getComponent().getURI()
+ + "#"
+ + reference.getName());
+ }
+ InvocationChain chain = new InvocationChainImpl(operation, targetOperation, true);
+ if (operation.isNonBlocking()) {
+ addNonBlockingInterceptor(reference, refBinding, chain);
+ }
+ addReferenceBindingInterceptor(reference, refBinding, chain, operation);
+ chains.add(chain);
+ }
+ } else {
+ // It's the service wire
+ RuntimeComponentService service = (RuntimeComponentService)wireTarget.getContract();
+ RuntimeComponent serviceComponent = wireTarget.getComponent();
+ Binding serviceBinding = wireTarget.getBinding();
+ for (Operation operation : sourceContract.getInterface().getOperations()) {
+ Operation targetOperation = interfaceContractMapper.map(targetContract.getInterface(), operation);
+ if (targetOperation == null) {
+ throw new ServiceRuntimeException("No matching operation for " + operation.getName()
+ + " is found in service "
+ + serviceComponent.getURI()
+ + "#"
+ + service.getName());
+ }
+ InvocationChain chain = new InvocationChainImpl(operation, targetOperation, false);
+ if (operation.isNonBlocking()) {
+ addNonBlockingInterceptor(service, serviceBinding, chain);
+ }
+ addServiceBindingInterceptor(service, serviceBinding, chain, operation);
+ addImplementationInterceptor(serviceComponent, service, chain, targetOperation);
+ chains.add(chain);
+ }
+ }
+ wireProcessor.process(this);
+ }
+
+ public EndpointReference getSource() {
+ return wireSource;
+ }
+
+ public EndpointReference getTarget() {
+ return wireTarget;
+ }
+
+ public void setTarget(EndpointReference target) {
+ if (this.wireTarget != target) {
+ rebuild();
+ }
+ this.wireTarget = target;
+ }
+
+ public void rebuild() {
+ this.chains = null;
+ }
+
+ /**
+ * Add the interceptor for a reference binding
+ *
+ * @param reference
+ * @param binding
+ * @param chain
+ * @param operation
+ */
+ private void addReferenceBindingInterceptor(ComponentReference reference,
+ Binding binding,
+ InvocationChain chain,
+ Operation operation) {
+ ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding);
+ if (provider != null) {
+ Invoker invoker = provider.createInvoker(operation);
+ if (invoker != null) {
+ chain.addInvoker(invoker);
+ }
+ }
+ List<PolicyProvider> pps = ((RuntimeComponentReference)reference).getPolicyProviders(binding);
+ if (pps != null) {
+ for (PolicyProvider p : pps) {
+ Interceptor interceptor = p.createInterceptor(operation);
+ if (interceptor != null) {
+ chain.addInterceptor(p.getPhase(), p.createInterceptor(operation));
+ }
+ }
+ }
+ }
+
+ /**
+ * Add the interceptor for a binding
+ *
+ * @param reference
+ * @param binding
+ * @param chain
+ * @param operation
+ */
+ private void addServiceBindingInterceptor(ComponentService service,
+ Binding binding,
+ InvocationChain chain,
+ Operation operation) {
+ List<PolicyProvider> pps = ((RuntimeComponentService)service).getPolicyProviders(binding);
+ if (pps != null) {
+ for (PolicyProvider p : pps) {
+ Interceptor interceptor = p.createInterceptor(operation);
+ if (interceptor != null) {
+ chain.addInterceptor(p.getPhase(), p.createInterceptor(operation));
+ }
+ }
+ }
+ }
+
+ /**
+ * Add a non-blocking interceptor if the reference binding needs it
+ *
+ * @param reference
+ * @param binding
+ * @param chain
+ */
+ private void addNonBlockingInterceptor(ComponentReference reference, Binding binding, InvocationChain chain) {
+ ReferenceBindingProvider provider = ((RuntimeComponentReference)reference).getBindingProvider(binding);
+ if (provider != null) {
+ boolean supportsOneWayInvocation = provider.supportsOneWayInvocation();
+ if (!supportsOneWayInvocation) {
+ chain.addInterceptor(Phase.REFERENCE, new NonBlockingInterceptor(workScheduler));
+ }
+ }
+ }
+
+ /**
+ * Add a non-blocking interceptor if the service binding needs it
+ *
+ * @param service
+ * @param binding
+ * @param chain
+ */
+ private void addNonBlockingInterceptor(ComponentService service, Binding binding, InvocationChain chain) {
+ ServiceBindingProvider provider = ((RuntimeComponentService)service).getBindingProvider(binding);
+ if (provider != null) {
+ if (!provider.supportsOneWayInvocation()) {
+ chain.addInterceptor(Phase.SERVICE, new NonBlockingInterceptor(workScheduler));
+ }
+ }
+ }
+
+ /**
+ * Add the interceptor for a component implementation
+ *
+ * @param component
+ * @param service
+ * @param chain
+ * @param operation
+ */
+ private void addImplementationInterceptor(Component component,
+ ComponentService service,
+ InvocationChain chain,
+ Operation operation) {
+ ImplementationProvider provider = ((RuntimeComponent)component).getImplementationProvider();
+ if (provider != null) {
+ Invoker invoker = null;
+ invoker = provider.createInvoker((RuntimeComponentService)service, operation);
+ chain.addInvoker(invoker);
+ }
+ List<PolicyProvider> pps = ((RuntimeComponent)component).getPolicyProviders();
+ if (pps != null) {
+ for (PolicyProvider p : pps) {
+ Interceptor interceptor = p.createInterceptor(operation);
+ if (interceptor != null) {
+ chain.addInterceptor(p.getPhase(), p.createInterceptor(operation));
+ }
+ }
+ }
+ }
+
+ /**
+ * @see java.lang.Object#clone()
+ */
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ RuntimeWireImpl copy = (RuntimeWireImpl)super.clone();
+ copy.wireSource = (EndpointReference)wireSource.clone();
+ copy.wireTarget = (EndpointReference)wireTarget.clone();
+ copy.invoker = new RuntimeWireInvoker(copy.messageFactory, copy.conversationManager, copy);
+ return copy;
+ }
+
+ /**
+ * @return the conversationManager
+ */
+ public ConversationManager getConversationManager() {
+ return conversationManager;
+ }
+
+ public synchronized RuntimeWire lookupCache(EndpointReference callback) {
+ if (lastCallback != null && callback.getURI().equals(lastCallback.getURI()) && !wireReserved) {
+ wireReserved = true;
+ return cachedWire;
+ } else {
+ return null;
+ }
+ }
+
+ public synchronized void addToCache(EndpointReference callback, RuntimeWire clonedWire) {
+ ((RuntimeWireImpl)clonedWire).setClonedFrom(this);
+ lastCallback = callback;
+ cachedWire = clonedWire;
+ wireReserved = true;
+ }
+
+ public synchronized void releaseClonedWire(RuntimeWire wire) {
+ if (cachedWire == wire) {
+ wireReserved = false;
+ }
+ }
+
+ public synchronized void releaseWire() {
+ clonedFrom.releaseClonedWire(this);
+ }
+
+ private void setClonedFrom(RuntimeWireImpl wire) {
+ clonedFrom = wire;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java
new file mode 100644
index 0000000000..fc6d7abf6a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/CallableReferenceImpl.java
@@ -0,0 +1,605 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.context;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.UUID;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.OptimizableBinding;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.builder.BindingBuilderExtension;
+import org.apache.tuscany.sca.core.assembly.CompositeActivator;
+import org.apache.tuscany.sca.core.assembly.CompositeActivatorImpl;
+import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl;
+import org.apache.tuscany.sca.core.assembly.EndpointWireImpl;
+import org.apache.tuscany.sca.core.assembly.ReferenceParametersImpl;
+import org.apache.tuscany.sca.core.conversation.ConversationManager;
+import org.apache.tuscany.sca.core.conversation.ConversationState;
+import org.apache.tuscany.sca.core.conversation.ExtendedConversation;
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.apache.tuscany.sca.runtime.ReferenceParameters;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.Conversation;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * Base class for implementations of service and callback references.
+ *
+ * @version $Rev$ $Date$
+ * @param <B> the type of the business interface
+ */
+public class CallableReferenceImpl<B> implements CallableReference<B>, Externalizable {
+ static final long serialVersionUID = -521548304761848325L;
+ protected transient CompositeActivator compositeActivator;
+ protected transient ProxyFactory proxyFactory;
+ protected transient Class<B> businessInterface;
+ protected transient Object proxy;
+
+ // if the wire targets a conversational service this holds the conversation state
+ protected transient ConversationManager conversationManager;
+ protected transient ExtendedConversation conversation;
+ protected transient Object conversationID;
+ protected Object callbackID; // The callbackID should be serializable
+
+ protected transient RuntimeComponent component;
+ protected transient RuntimeComponentReference reference;
+ protected transient Binding binding;
+
+ protected String scdl;
+
+ private transient RuntimeComponentReference clonedRef;
+ private transient ReferenceParameters refParams;
+ private transient XMLStreamReader xmlReader;
+
+ private transient RuntimeWire endpointWire;
+
+ /*
+ * Public constructor for Externalizable serialization/deserialization
+ */
+ public CallableReferenceImpl() {
+ super();
+ }
+
+ /*
+ * Public constructor for use by XMLStreamReader2CallableReference
+ */
+ public CallableReferenceImpl(XMLStreamReader xmlReader) throws Exception {
+ this.xmlReader = xmlReader;
+ resolve();
+ }
+
+ protected CallableReferenceImpl(Class<B> businessInterface,
+ RuntimeComponent component,
+ RuntimeComponentReference reference,
+ Binding binding,
+ ProxyFactory proxyFactory,
+ CompositeActivator compositeActivator) {
+ this.proxyFactory = proxyFactory;
+ this.businessInterface = businessInterface;
+ this.component = component;
+ this.reference = reference;
+ this.binding = binding;
+ // FIXME: The SCA Specification is not clear how we should handle multiplicity
+ // for CallableReference
+ if (this.binding == null) {
+ this.binding = this.reference.getBinding(SCABinding.class);
+ if (this.binding == null) {
+
+ // TODO: TUSCANY-2580: if the refernece doesn't have a binding yet then instead of NPE use a candidate one if its avaialable
+ if (reference.getBindings() != null && reference.getBindings().size() > 0) {
+ this.binding = this.reference.getBindings().get(0);
+ } else {
+ this.binding = this.reference.getEndpoints().get(0).getCandidateBindings().get(0);
+ if (this.reference.getEndpoints().get(0).getInterfaceContract() == null) {
+ this.reference.getEndpoints().get(0).setInterfaceContract(reference.getInterfaceContract());
+ }
+ }
+ }
+ }
+
+ // FIXME: Should we normalize the componentName/serviceName URI into an absolute SCA URI in the SCA binding?
+ // sca:component1/component11/component112/service1?
+ this.compositeActivator = compositeActivator;
+ this.conversationManager = this.compositeActivator.getConversationManager();
+ initCallbackID();
+ }
+
+ public CallableReferenceImpl(Class<B> businessInterface, RuntimeWire wire, ProxyFactory proxyFactory) {
+ this.proxyFactory = proxyFactory;
+ this.businessInterface = businessInterface;
+ bind(wire);
+ }
+
+ public RuntimeWire getRuntimeWire() {
+ try {
+ resolve();
+ if (endpointWire != null){
+ return endpointWire;
+ } else if (reference != null) {
+ return reference.getRuntimeWire(binding);
+ } else {
+ return null;
+ }
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ protected void bind(RuntimeWire wire) {
+ if (wire != null) {
+
+ if (wire instanceof EndpointWireImpl){
+ endpointWire = wire;
+ }
+ this.component = wire.getSource().getComponent();
+ this.reference = (RuntimeComponentReference)wire.getSource().getContract();
+ this.binding = wire.getSource().getBinding();
+ this.compositeActivator = ((ComponentContextImpl)component.getComponentContext()).getCompositeActivator();
+ this.conversationManager = this.compositeActivator.getConversationManager();
+ initCallbackID();
+ }
+ }
+
+ protected void initCallbackID() {
+ if (reference.getInterfaceContract() != null) {
+ if (reference.getInterfaceContract().getCallbackInterface() != null) {
+ this.callbackID = createCallbackID();
+ }
+ }
+ }
+
+ public B getProxy() throws ObjectCreationException {
+ try {
+ if (proxy == null) {
+ proxy = createProxy();
+ }
+ return businessInterface.cast(proxy);
+ } catch (Exception e) {
+ throw new ObjectCreationException(e);
+ }
+ }
+
+ public void setProxy(Object proxy) {
+ this.proxy = proxy;
+ }
+
+ protected Object createProxy() throws Exception {
+ return proxyFactory.createProxy(this);
+ }
+
+ public B getService() {
+ try {
+ resolve();
+ return getProxy();
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ public Class<B> getBusinessInterface() {
+ try {
+ resolve();
+ return businessInterface;
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ public boolean isConversational() {
+ try {
+ resolve();
+ return reference == null ? false : reference.getInterfaceContract().getInterface().isConversational();
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ public Conversation getConversation() {
+ try {
+ // resolve from XML just in case this CallableReference is the result of
+ // passing a CallableReference as a parameter
+ resolve();
+
+ if (conversation == null || conversation.getState() == ConversationState.ENDED) {
+ conversation = null;
+ }
+ return conversation;
+
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ public Object getCallbackID() {
+ try {
+ resolve();
+ return callbackID;
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ /**
+ * @see java.io.Externalizable#readExternal(java.io.ObjectInput)
+ */
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ final boolean hasSCDL = in.readBoolean();
+ if (hasSCDL) {
+ this.scdl = in.readUTF();
+ } else {
+ this.scdl = null;
+ }
+ }
+
+ /**
+ * @throws IOException
+ */
+ private synchronized void resolve() throws Exception {
+ if ((scdl != null || xmlReader != null) && component == null && reference == null) {
+ ComponentContextHelper componentContextHelper = ComponentContextHelper.getCurrentComponentContextHelper();
+ if (componentContextHelper != null) {
+ this.compositeActivator = ComponentContextHelper.getCurrentCompositeActivator();
+ this.conversationManager = this.compositeActivator.getConversationManager();
+ Component c;
+ if (xmlReader != null) {
+ c = componentContextHelper.fromXML(xmlReader);
+ xmlReader = null; // OK to GC this now
+ } else {
+ c = componentContextHelper.fromXML(scdl);
+ scdl = null; // OK to GC this now
+ }
+ this.component = (RuntimeComponent)c;
+ compositeActivator.configureComponentContext(this.component);
+ this.reference = (RuntimeComponentReference)c.getReferences().get(0);
+ this.reference.setComponent(this.component);
+ clonedRef = reference;
+ ReferenceParameters parameters = null;
+ for (Object ext : reference.getExtensions()) {
+ if (ext instanceof ReferenceParameters) {
+ parameters = (ReferenceParameters)ext;
+ break;
+ }
+ }
+ if (parameters != null) {
+ refParams = parameters;
+ this.callbackID = parameters.getCallbackID();
+ attachConversation(parameters.getConversationID());
+ }
+
+ for (Binding binding : reference.getBindings()) {
+ if (binding instanceof OptimizableBinding) {
+ // Resolve the Component
+ final String bindingURI = binding.getURI();
+ final Component targetComponent = resolveComponentURI(bindingURI);
+
+ // Find the Service
+ ComponentService targetService = resolveServiceURI(bindingURI, targetComponent);
+
+ // if the target service is a promoted service then find the
+ // service it promotes
+ if ((targetService != null) && (targetService.getService() instanceof CompositeService)) {
+ CompositeService compositeService = (CompositeService) targetService.getService();
+ // Find the promoted component service
+ ComponentService promotedComponentService = getPromotedComponentService(compositeService);
+ if (promotedComponentService != null && !promotedComponentService.isUnresolved()) {
+ targetService = promotedComponentService;
+ }
+ }
+
+ OptimizableBinding optimizableBinding = (OptimizableBinding)binding;
+ optimizableBinding.setTargetComponent(targetComponent);
+ optimizableBinding.setTargetComponentService(targetService);
+ if (targetService != null) {
+ for (Binding serviceBinding : targetService.getBindings()) {
+ if (serviceBinding.getClass() == binding.getClass()) {
+ optimizableBinding.setTargetBinding(serviceBinding);
+ break;
+ }
+ }
+ }
+ }
+ }
+ // FIXME: The SCA Specification is not clear how we should handle multiplicity
+ // for CallableReference
+ if (binding == null) {
+ binding = reference.getBinding(SCABinding.class);
+ if (binding == null) {
+ binding = reference.getBindings().get(0);
+ }
+ }
+ Interface i = reference.getInterfaceContract().getInterface();
+ if (i instanceof JavaInterface) {
+ JavaInterface javaInterface = (JavaInterface)i;
+ if (javaInterface.isUnresolved()) {
+ // Allow privileged access to get ClassLoader. Requires RuntimePermission in
+ // security policy.
+ ClassLoader classLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+ public ClassLoader run() {
+ return Thread.currentThread().getContextClassLoader();
+ }
+ });
+ javaInterface.setJavaClass(classLoader.loadClass(javaInterface.getName()));
+ compositeActivator.getJavaInterfaceFactory().createJavaInterface(javaInterface,
+ javaInterface.getJavaClass());
+ //FIXME: If the interface needs XSDs to be loaded (e.g., for static SDO),
+ // this needs to be done here. We usually search for XSDs in the current
+ // contribution at resolve time. Is it possible to locate the current
+ // contribution at runtime?
+ }
+ this.businessInterface = (Class<B>)javaInterface.getJavaClass();
+ }
+ if (binding instanceof BindingBuilderExtension) {
+ ((BindingBuilderExtension)binding).getBuilder().build(component, reference, binding, null);
+ }
+ this.proxyFactory = compositeActivator.getProxyFactory();
+ }
+ } else {
+ this.compositeActivator = ComponentContextHelper.getCurrentCompositeActivator();
+ if (this.compositeActivator != null) {
+ this.proxyFactory = this.compositeActivator.getProxyFactory();
+ }
+ }
+ }
+
+ /**
+ * Follow a service promotion chain down to the inner most (non composite)
+ * component service.
+ *
+ * @param topCompositeService
+ * @return
+ */
+ private ComponentService getPromotedComponentService(CompositeService compositeService) {
+ ComponentService componentService = compositeService.getPromotedService();
+ if (componentService != null) {
+ Service service = componentService.getService();
+ if (componentService.getName() != null && service instanceof CompositeService) {
+
+ // Continue to follow the service promotion chain
+ return getPromotedComponentService((CompositeService)service);
+
+ } else {
+
+ // Found a non-composite service
+ return componentService;
+ }
+ } else {
+
+ // No promoted service
+ return null;
+ }
+ }
+
+ /**
+ * @see java.io.Externalizable#writeExternal(java.io.ObjectOutput)
+ */
+ public void writeExternal(ObjectOutput out) throws IOException {
+ try {
+ final String xml = toXMLString();
+ if (xml == null) {
+ out.writeBoolean(false);
+ } else {
+ out.writeBoolean(true);
+ out.writeUTF(xml);
+ }
+ } catch (Exception e) {
+ // e.printStackTrace();
+ throw new IOException(e.toString());
+ }
+ }
+
+ public String toXMLString() throws IOException {
+ if (reference != null) {
+ if (clonedRef == null) {
+ try {
+ clonedRef = (RuntimeComponentReference)reference.clone();
+ } catch (CloneNotSupportedException e) {
+ // will not happen
+ }
+ }
+ if (refParams == null) {
+ refParams = new ReferenceParametersImpl();
+
+ // remove any existing reference parameters from the clone
+ Object toRemove = null;
+ for (Object extension : clonedRef.getExtensions()){
+ if (extension instanceof ReferenceParameters){
+ toRemove = extension;
+ }
+ }
+
+ if (toRemove != null){
+ clonedRef.getExtensions().remove(toRemove);
+ }
+
+ // add the new reference parameter object
+ clonedRef.getExtensions().add(refParams);
+ }
+ refParams.setCallbackID(callbackID);
+ if (conversation != null){
+ refParams.setConversationID(conversation.getConversationID());
+ }
+ return ((CompositeActivatorImpl)compositeActivator).getComponentContextHelper()
+ .toXML(component, clonedRef);
+ } else {
+ return scdl;
+ }
+ }
+
+ /**
+ * Create a callback id
+ *
+ * @return the callback id
+ */
+ private String createCallbackID() {
+ return UUID.randomUUID().toString();
+ }
+
+ public void attachCallbackID(Object callbackID) {
+ this.callbackID = callbackID;
+ }
+
+ public void attachConversationID(Object conversationID) {
+ this.conversationID = conversationID;
+ }
+
+ public void attachConversation(ExtendedConversation conversation) {
+ this.conversation = conversation;
+ }
+
+ public void attachConversation(Object conversationID) {
+ if (conversationID != null) {
+ ExtendedConversation conversation = conversationManager.getConversation(conversationID);
+ if (conversation == null){
+ conversation = conversationManager.startConversation(conversationID);
+ }
+ this.conversation = conversation;
+ } else {
+ this.conversation = null;
+ }
+ }
+
+ protected ReferenceParameters getReferenceParameters() {
+ ReferenceParameters parameters = new ReferenceParametersImpl();
+ parameters.setCallbackID(callbackID);
+ if (getConversation() != null) {
+ parameters.setConversationID(conversation.getConversationID());
+ }
+ return parameters;
+ }
+
+ public EndpointReference getEndpointReference() {
+ try {
+ resolve();
+
+ // Use the interface contract of the reference on the component type
+ Reference componentTypeRef = reference.getReference();
+ InterfaceContract sourceContract =
+ componentTypeRef == null ? reference.getInterfaceContract() : componentTypeRef.getInterfaceContract();
+ sourceContract = sourceContract.makeUnidirectional(false);
+ EndpointReference epr = new EndpointReferenceImpl(component, reference, binding, sourceContract);
+ ReferenceParameters parameters = getReferenceParameters();
+ epr.setReferenceParameters(parameters);
+ return epr;
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ public XMLStreamReader getXMLReader() {
+ return xmlReader;
+ }
+
+ /**
+ * Resolves the specified URI to a Component using the compositeActivator.
+ * There are two cases that we need to handle:
+ * <ul>
+ * <li>URI containing just Composite name(s) (i.e. no Service name specified)
+ * <li>URI containing Composite name(s) and a Service Name
+ * </ul>
+ *
+ * @param componentURI The URI of the Component to resolve
+ * @return The Component for the specified URI or null if not founds
+ */
+ protected Component resolveComponentURI(String componentURI) {
+ // If the URI has come from a binding, it may well start with a '/'. We will need
+ // to remove this so we can match it to the composite names.
+ if (componentURI.startsWith("/")) {
+ componentURI = componentURI.substring(1);
+ }
+
+ // First assume that we are dealing with a Component URI without a Service Name
+ Component component = compositeActivator.resolve(componentURI);
+ if (component != null) {
+ return component;
+ }
+
+ // Perhaps we have a ComponentURI that has a ServiceName on the end of it
+ final int index = componentURI.lastIndexOf('/');
+ if (index > -1) {
+ componentURI = componentURI.substring(0, index);
+ return compositeActivator.resolve(componentURI);
+ }
+
+ // We could not resolve the Component URI
+ return null;
+ }
+
+ /**
+ * Examines the Services on the specified Component and returns the Service that matches the
+ * specified Binding URI.
+ *
+ * @param bindingURI The Binding URI to resolve on the Component
+ * @param targetComponent The Component containing the Services
+ * @return The Service with the specified serviceName or null if no such Service found.
+ */
+ protected ComponentService resolveServiceURI(String bindingURI, Component targetComponent) {
+
+ ComponentService targetService = null;
+
+ if (targetComponent != null) {
+ if (bindingURI.startsWith("/")) {
+ bindingURI = bindingURI.substring(1);
+ }
+
+ final String componentURI = targetComponent.getURI();
+ final String serviceName;
+ if (componentURI.equals(bindingURI)) {
+ // No service specified
+ serviceName = "";
+ } else {
+ // Get the Service name from the Binding URI
+ serviceName = bindingURI.substring(componentURI.length() + 1);
+ }
+
+ if ("".equals(serviceName)) {
+ targetService = ComponentContextHelper.getSingleService(targetComponent);
+ } else {
+ for (ComponentService service : targetComponent.getServices()) {
+ if (service.getName().equals(serviceName)) {
+ targetService = service;
+ break;
+ }
+ }
+ }
+ }
+
+ return targetService;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java
new file mode 100644
index 0000000000..78b0887482
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextHelper.java
@@ -0,0 +1,320 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.context;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Multiplicity;
+import org.apache.tuscany.sca.assembly.OptimizableBinding;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.assembly.CompositeActivator;
+import org.apache.tuscany.sca.core.invocation.ThreadMessageContext;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ComponentContextHelper {
+
+ private final AssemblyFactory assemblyFactory;
+ private final JavaInterfaceFactory javaInterfaceFactory;
+ private final StAXArtifactProcessorExtensionPoint staxProcessors;
+
+ /**
+ * @param assemblyFactory The factory to create assembly models
+ * @param processors The extension point for StAX artifact processors
+ */
+ public ComponentContextHelper(AssemblyFactory assemblyFactory,
+ JavaInterfaceFactory javaInterfaceFactory,
+ StAXArtifactProcessorExtensionPoint processors) {
+ this.assemblyFactory = assemblyFactory;
+ this.javaInterfaceFactory = javaInterfaceFactory;
+ this.staxProcessors = processors;
+ }
+
+ /**
+ * Create a self-reference for a component service
+ * @param component
+ * @param service
+ * @throws CloneNotSupportedException
+ * @throws InvalidInterfaceException
+ */
+ public ComponentReference createSelfReference(Component component,
+ ComponentService service,
+ Class<?> businessInterface) throws CloneNotSupportedException,
+ InvalidInterfaceException {
+ ComponentReference componentReference = assemblyFactory.createComponentReference();
+ componentReference.setName("$self$." + service.getName());
+ for (Binding binding : service.getBindings()) {
+ if (binding instanceof OptimizableBinding) {
+ OptimizableBinding optimizableBinding = (OptimizableBinding)((OptimizableBinding)binding).clone();
+ optimizableBinding.setTargetBinding(binding);
+ optimizableBinding.setTargetComponent(component);
+ optimizableBinding.setTargetComponentService(service);
+ componentReference.getBindings().add(optimizableBinding);
+ } else {
+ componentReference.getBindings().add(binding);
+ }
+ }
+
+ componentReference.setCallback(service.getCallback());
+ componentReference.getTargets().add(service);
+ componentReference.getPolicySets().addAll(service.getPolicySets());
+ componentReference.getRequiredIntents().addAll(service.getRequiredIntents());
+
+ InterfaceContract interfaceContract = service.getInterfaceContract();
+ Service componentTypeService = service.getService();
+ if (componentTypeService != null && componentTypeService.getInterfaceContract() != null) {
+ interfaceContract = componentTypeService.getInterfaceContract();
+ }
+ interfaceContract = getInterfaceContract(interfaceContract, businessInterface);
+ componentReference.setInterfaceContract(interfaceContract);
+ componentReference.setMultiplicity(Multiplicity.ONE_ONE);
+ // component.getReferences().add(componentReference);
+ return componentReference;
+ }
+
+ /**
+ * @param interfaceContract
+ * @param businessInterface
+ * @return
+ * @throws CloneNotSupportedException
+ * @throws InvalidInterfaceException
+ */
+ private InterfaceContract getInterfaceContract(InterfaceContract interfaceContract, Class<?> businessInterface)
+ throws CloneNotSupportedException, InvalidInterfaceException {
+ Interface interfaze = interfaceContract.getInterface();
+ boolean compatible = false;
+ if (interfaze instanceof JavaInterface) {
+ Class<?> cls = ((JavaInterface)interfaze).getJavaClass();
+ if (businessInterface.isAssignableFrom(cls)) {
+ compatible = true;
+ }
+ }
+ if (!compatible) {
+ // The interface is not assignable from the interface contract
+ interfaceContract = (InterfaceContract)interfaceContract.clone();
+ interfaceContract.setInterface(javaInterfaceFactory.createJavaInterface(businessInterface));
+ }
+
+ return interfaceContract;
+ }
+
+ /**
+ * Bind a component reference to a component service
+ * @param <B>
+ * @param businessInterface
+ * @param reference
+ * @param service
+ * @return
+ * @throws CloneNotSupportedException
+ * @throws InvalidInterfaceException
+ */
+ public RuntimeComponentReference bindComponentReference(Class<?> businessInterface,
+ RuntimeComponentReference reference,
+ RuntimeComponent component,
+ RuntimeComponentService service)
+ throws CloneNotSupportedException, InvalidInterfaceException {
+ RuntimeComponentReference ref = (RuntimeComponentReference)reference.clone();
+ InterfaceContract interfaceContract = reference.getInterfaceContract();
+ Reference componentTypeReference = reference.getReference();
+ if (componentTypeReference != null && componentTypeReference.getInterfaceContract() != null) {
+ interfaceContract = componentTypeReference.getInterfaceContract();
+ }
+ InterfaceContract refInterfaceContract = getInterfaceContract(interfaceContract, businessInterface);
+ if (refInterfaceContract != interfaceContract) {
+ ref = (RuntimeComponentReference)reference.clone();
+ ref.setInterfaceContract(interfaceContract);
+ }
+ ref.setComponent(component);
+ ref.getTargets().add(service);
+ ref.getBindings().clear();
+ for (Binding binding : service.getBindings()) {
+ if (binding instanceof OptimizableBinding) {
+ OptimizableBinding optimizableBinding = (OptimizableBinding)((OptimizableBinding)binding).clone();
+ optimizableBinding.setTargetBinding(binding);
+ optimizableBinding.setTargetComponent(component);
+ optimizableBinding.setTargetComponentService(service);
+ ref.getBindings().add(optimizableBinding);
+ } else {
+ ref.getBindings().add(binding);
+ }
+ }
+ return ref;
+ }
+
+ public void write(Component component, ComponentReference reference, Writer writer) throws IOException {
+ write(component, reference, null, writer);
+ }
+
+ public void write(Component component, ComponentReference reference, ComponentService service, Writer writer) throws IOException {
+ try {
+ StAXArtifactProcessor<Composite> processor = staxProcessors.getProcessor(Composite.class);
+ Composite composite = assemblyFactory.createComposite();
+ composite.setName(new QName("http://tuscany.apache.org/xmlns/sca/1.0", "default"));
+ Component comp = assemblyFactory.createComponent();
+ comp.setName("default");
+ comp.setURI(component.getURI());
+ composite.getComponents().add(comp);
+ if (reference != null) {
+ comp.getReferences().add(reference);
+ }
+ if (service != null) {
+ comp.getServices().add(service);
+ }
+
+ XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
+ XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
+ processor.write(composite, streamWriter);
+ } catch (Exception e) {
+ throw new IOException(e.getMessage());
+ }
+ }
+
+ public String toXML(Component component, ComponentReference reference) throws IOException {
+ StringWriter writer = new StringWriter();
+ write(component, reference, writer);
+ return writer.toString();
+ }
+
+ public String toXML(Component component, ComponentService service) throws IOException {
+ StringWriter writer = new StringWriter();
+ write(component, null, service, writer);
+ return writer.toString();
+ }
+
+ public RuntimeComponent read(Reader reader) throws IOException {
+ try {
+ XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+ XMLStreamReader streamReader = inputFactory.createXMLStreamReader(reader);
+ return read(streamReader);
+ } catch (Exception e) {
+ throw new IOException(e.getMessage());
+ }
+ }
+
+ public RuntimeComponent read(XMLStreamReader streamReader) throws IOException {
+ try {
+ StAXArtifactProcessor<Composite> processor = staxProcessors.getProcessor(Composite.class);
+ Composite composite = processor.read(streamReader);
+ RuntimeComponent component = (RuntimeComponent)composite.getComponents().get(0);
+ return component;
+ } catch (Exception e) {
+ throw new IOException(e.getMessage());
+ }
+ }
+
+ public Component fromXML(String xml) throws IOException {
+ return read(new StringReader(xml));
+ }
+
+ public Component fromXML(XMLStreamReader streamReader) throws IOException {
+ return read(streamReader);
+ }
+
+ public static RuntimeComponent getCurrentComponent() {
+ Message message = ThreadMessageContext.getMessageContext();
+ if (message != null) {
+ EndpointReference to = message.getTo();
+ if (to == null) {
+ return null;
+ }
+ RuntimeComponent component = message.getTo().getComponent();
+ return component;
+ }
+ return null;
+ }
+
+ public static CompositeActivator getCurrentCompositeActivator() {
+ RuntimeComponent component = getCurrentComponent();
+ if (component != null) {
+ ComponentContextImpl context = (ComponentContextImpl)component.getComponentContext();
+ return context.getCompositeActivator();
+ }
+ return null;
+ }
+
+ public static ComponentContextHelper getCurrentComponentContextHelper() {
+ CompositeActivator activator = getCurrentCompositeActivator();
+ if (activator != null) {
+ return activator.getComponentContextHelper();
+ }
+ return null;
+ }
+
+ /**
+ * @param component
+ */
+ public static ComponentService getSingleService(Component component) {
+ ComponentService targetService;
+ List<ComponentService> services = component.getServices();
+ List<ComponentService> regularServices = new ArrayList<ComponentService>();
+ for (ComponentService service : services) {
+ if (service.isCallback()) {
+ continue;
+ }
+ String name = service.getName();
+ if (!name.startsWith("$") || name.startsWith("$dynamic$")) {
+ regularServices.add(service);
+ }
+ }
+ if (regularServices.size() == 0) {
+ throw new ServiceRuntimeException("No service is declared on component " + component.getURI());
+ }
+ if (regularServices.size() != 1) {
+ throw new ServiceRuntimeException("More than one service is declared on component " + component.getURI()
+ + ". Service name is required to get the service.");
+ }
+ targetService = regularServices.get(0);
+ return targetService;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java
new file mode 100644
index 0000000000..ed01a509d2
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ComponentContextImpl.java
@@ -0,0 +1,403 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.context;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentProperty;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Multiplicity;
+import org.apache.tuscany.sca.assembly.OptimizableBinding;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.context.PropertyValueFactory;
+import org.apache.tuscany.sca.context.RequestContextFactory;
+import org.apache.tuscany.sca.core.assembly.CompositeActivator;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentContext;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.RequestContext;
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * Implementation of ComponentContext that delegates to a ComponentContextProvider.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentContextImpl implements RuntimeComponentContext {
+ private final RuntimeComponent component;
+
+ private final CompositeActivator compositeActivator;
+ private final RequestContextFactory requestContextFactory;
+ private final ProxyFactory proxyFactory;
+ private final AssemblyFactory assemblyFactory;
+ private final JavaInterfaceFactory javaInterfaceFactory;
+
+ /**
+ * This is a reference to the PropertyValueFactory that is provided by the Implementation
+ * that can be used to get the value from a Property Object.
+ *
+ * @see #setPropertyValueFactory(PropertyValueFactory)
+ * @see #getProperty(Class, String)
+ */
+ private PropertyValueFactory propertyFactory;
+
+ public ComponentContextImpl(CompositeActivator compositeActivator,
+ AssemblyFactory assemblyFactory,
+ ProxyFactory proxyFactory,
+ InterfaceContractMapper interfaceContractMapper,
+ RequestContextFactory requestContextFactory,
+ JavaInterfaceFactory javaInterfaceFactory,
+ RuntimeComponent component) {
+ super();
+ this.compositeActivator = compositeActivator;
+ this.assemblyFactory = assemblyFactory;
+ this.proxyFactory = proxyFactory;
+ this.requestContextFactory = requestContextFactory;
+ this.javaInterfaceFactory = javaInterfaceFactory;
+ this.component = component;
+ }
+
+ public String getURI() {
+ return component.getURI();
+ }
+
+ public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+ return (R)proxyFactory.cast(target);
+ }
+
+ public <B> B getService(Class<B> businessInterface, String referenceName) {
+ ServiceReference<B> serviceRef = getServiceReference(businessInterface, referenceName);
+ return serviceRef.getService();
+ }
+
+ public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String referenceName) {
+ try {
+ for (ComponentReference ref : component.getReferences()) {
+ if (referenceName.equals(ref.getName())) {
+ return getServiceReference(businessInterface, (RuntimeComponentReference)ref, null);
+ }
+ }
+ throw new ServiceRuntimeException("Reference not found: " + referenceName);
+ } catch (ServiceRuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * The Implementation is responsible for calling this method to set the
+ * PropertyValueFactory that is used to get the Property Value from
+ * a Tuscany Property object.
+ *
+ * @param factory The PropertyValueFactory to use
+ *
+ * @see #getProperty(Class, String)
+ */
+ public void setPropertyValueFactory(PropertyValueFactory factory) {
+ propertyFactory = factory;
+ }
+
+ /**
+ * Gets the value for the specified property with the specified type.
+ *
+ * @param type The type of the property value we are getting
+ * @param propertyName The name of the property we are getting
+ * @param B The class of the property value we are getting
+ *
+ * @throws ServiceRuntimeException If a Property for the specified propertyName
+ * is not found
+ *
+ * @see #setPropertyValueFactory(PropertyValueFactory)
+ */
+ public <B> B getProperty(Class<B> type, String propertyName) {
+ for (ComponentProperty p : component.getProperties()) {
+ if (propertyName.equals(p.getName())) {
+ return propertyFactory.createPropertyValue(p, type);
+ }
+ }
+ throw new ServiceRuntimeException("Property not found: " + propertyName);
+ }
+
+ public <B> ServiceReference<B> createSelfReference(Class<B> businessInterface) {
+ ComponentService service = ComponentContextHelper.getSingleService(component);
+ try {
+ return createSelfReference(businessInterface, service);
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ public <B> ServiceReference<B> createSelfReference(Class<B> businessInterface, String serviceName) {
+ try {
+ for (ComponentService service : component.getServices()) {
+ if (serviceName.equals(service.getName())) {
+ return createSelfReference(businessInterface, service);
+ }
+ }
+ throw new ServiceRuntimeException("Service not found: " + serviceName);
+ } catch (ServiceRuntimeException e) {
+ throw e;
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * @param <B>
+ * @param businessInterface
+ * @param service
+ * @return
+ */
+ public <B> ServiceReference<B> createSelfReference(Class<B> businessInterface, ComponentService service) {
+ try {
+ RuntimeComponentReference ref =
+ (RuntimeComponentReference)createSelfReference(component, service, businessInterface);
+ ref.setComponent(component);
+ return getServiceReference(businessInterface, ref, null);
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ public RequestContext getRequestContext() {
+ if (requestContextFactory != null) {
+ return requestContextFactory.createRequestContext();
+ } else {
+ return new RequestContextImpl(proxyFactory);
+ }
+ }
+
+ /**
+ * @param businessInterface
+ * @param reference
+ * @return
+ * @throws CloneNotSupportedException
+ * @throws InvalidInterfaceException
+ */
+ public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, RuntimeComponentReference reference, Binding binding) {
+ try {
+ RuntimeComponentReference ref = (RuntimeComponentReference)reference;
+ InterfaceContract interfaceContract = reference.getInterfaceContract();
+ Reference componentTypeReference = reference.getReference();
+ if (componentTypeReference != null && componentTypeReference.getInterfaceContract() != null) {
+ interfaceContract = componentTypeReference.getInterfaceContract();
+ }
+ InterfaceContract refInterfaceContract = getInterfaceContract(interfaceContract, businessInterface);
+ if (refInterfaceContract != interfaceContract) {
+ ref = (RuntimeComponentReference)reference.clone();
+ if (interfaceContract != null) {
+ ref.setInterfaceContract(interfaceContract);
+ } else {
+ ref.setInterfaceContract(refInterfaceContract);
+ }
+ }
+ ref.setComponent(component);
+ return new ServiceReferenceImpl<B>(businessInterface, component, ref, binding, proxyFactory, compositeActivator);
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ /**
+ * Bind a component reference to a component service
+ * @param <B>
+ * @param businessInterface
+ * @param reference
+ * @param service
+ * @return
+ * @throws CloneNotSupportedException
+ * @throws InvalidInterfaceException
+ */
+ public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface,
+ RuntimeComponentReference reference,
+ RuntimeComponent component,
+ RuntimeComponentService service) {
+ try {
+ RuntimeComponentReference ref = (RuntimeComponentReference)reference.clone();
+ InterfaceContract interfaceContract = reference.getInterfaceContract();
+ Reference componentTypeReference = reference.getReference();
+ if (componentTypeReference != null && componentTypeReference.getInterfaceContract() != null) {
+ interfaceContract = componentTypeReference.getInterfaceContract();
+ }
+ InterfaceContract refInterfaceContract = getInterfaceContract(interfaceContract, businessInterface);
+ if (refInterfaceContract != interfaceContract) {
+ ref = (RuntimeComponentReference)reference.clone();
+ ref.setInterfaceContract(interfaceContract);
+ }
+ ref.getTargets().add(service);
+ ref.getBindings().clear();
+ for (Binding binding : service.getBindings()) {
+ if (binding instanceof OptimizableBinding) {
+ OptimizableBinding optimizableBinding = (OptimizableBinding)((OptimizableBinding)binding).clone();
+ optimizableBinding.setTargetBinding(binding);
+ optimizableBinding.setTargetComponent(component);
+ optimizableBinding.setTargetComponentService(service);
+ ref.getBindings().add(optimizableBinding);
+ } else {
+ ref.getBindings().add(binding);
+ }
+ }
+ return new ServiceReferenceImpl<B>(businessInterface, component, ref, proxyFactory, compositeActivator);
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ public <B> CallableReference<B> getCallableReference(Class<B> businessInterface,
+ RuntimeComponent component,
+ RuntimeComponentService service) {
+ try {
+ if (businessInterface == null) {
+ InterfaceContract contract = service.getInterfaceContract();
+ businessInterface = (Class<B>)((JavaInterface)contract.getInterface()).getJavaClass();
+ }
+ RuntimeComponentReference ref =
+ (RuntimeComponentReference)createSelfReference(component, service, businessInterface);
+ ref.setComponent(component);
+ return new CallableReferenceImpl<B>(businessInterface, component, ref, null, proxyFactory,
+ compositeActivator);
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ /**
+ * Create a self-reference for a component service
+ * @param component
+ * @param service
+ * @throws CloneNotSupportedException
+ * @throws InvalidInterfaceException
+ */
+ private ComponentReference createSelfReference(Component component,
+ ComponentService service,
+ Class<?> businessInterface) throws CloneNotSupportedException,
+ InvalidInterfaceException {
+ ComponentReference componentReference = assemblyFactory.createComponentReference();
+ componentReference.setName("$self$." + service.getName());
+ for (Binding binding : service.getBindings()) {
+ if (binding instanceof OptimizableBinding) {
+ OptimizableBinding optimizableBinding = (OptimizableBinding)((OptimizableBinding)binding).clone();
+ optimizableBinding.setTargetBinding(binding);
+ optimizableBinding.setTargetComponent(component);
+ optimizableBinding.setTargetComponentService(service);
+ componentReference.getBindings().add(optimizableBinding);
+ } else {
+ componentReference.getBindings().add(binding);
+ }
+ }
+
+ componentReference.setCallback(service.getCallback());
+ componentReference.getTargets().add(service);
+ componentReference.getPolicySets().addAll(service.getPolicySets());
+ componentReference.getRequiredIntents().addAll(service.getRequiredIntents());
+
+ InterfaceContract interfaceContract = service.getInterfaceContract();
+ Service componentTypeService = service.getService();
+ if (componentTypeService != null && componentTypeService.getInterfaceContract() != null) {
+ interfaceContract = componentTypeService.getInterfaceContract();
+ }
+ interfaceContract = getInterfaceContract(interfaceContract, businessInterface);
+ componentReference.setInterfaceContract(interfaceContract);
+ componentReference.setMultiplicity(Multiplicity.ONE_ONE);
+ // component.getReferences().add(componentReference);
+ return componentReference;
+ }
+
+ /**
+ * @param interfaceContract
+ * @param businessInterface
+ * @return
+ * @throws CloneNotSupportedException
+ * @throws InvalidInterfaceException
+ */
+ private InterfaceContract getInterfaceContract(InterfaceContract interfaceContract, Class<?> businessInterface)
+ throws CloneNotSupportedException, InvalidInterfaceException {
+ boolean compatible = false;
+ if (interfaceContract != null && interfaceContract.getInterface() != null) {
+ Interface interfaze = interfaceContract.getInterface();
+ if (interfaze instanceof JavaInterface) {
+ Class<?> cls = ((JavaInterface)interfaze).getJavaClass();
+ if (businessInterface.isAssignableFrom(cls)) {
+ compatible = true;
+ }
+ }
+ }
+
+ if (!compatible) {
+ // The interface is not assignable from the interface contract
+ interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
+ JavaInterface callInterface = javaInterfaceFactory.createJavaInterface(businessInterface);
+ interfaceContract.setInterface(callInterface);
+ if (callInterface.getCallbackClass() != null) {
+ interfaceContract.setCallbackInterface(javaInterfaceFactory.createJavaInterface(callInterface
+ .getCallbackClass()));
+ }
+ }
+
+ return interfaceContract;
+ }
+
+ /**
+ * @return the compositeActivator
+ */
+ public CompositeActivator getCompositeActivator() {
+ return compositeActivator;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.runtime.RuntimeComponentContext#start(org.apache.tuscany.sca.runtime.RuntimeComponentReference)
+ */
+ public void start(RuntimeComponentReference reference) {
+ compositeActivator.start(component, reference);
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.runtime.RuntimeComponentContext#read(java.io.Reader)
+ */
+ public RuntimeComponent read(Reader reader) throws IOException {
+ RuntimeComponent component = compositeActivator.getComponentContextHelper().read(reader);
+ compositeActivator.configureComponentContext(component);
+ return component;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.runtime.RuntimeComponentContext#write(org.apache.tuscany.sca.runtime.RuntimeComponentReference, java.io.Writer)
+ */
+ public void write(RuntimeComponentReference reference, Writer writer) throws IOException {
+ compositeActivator.getComponentContextHelper().write(component, reference, writer);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/DefaultComponentContextFactory.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/DefaultComponentContextFactory.java
new file mode 100644
index 0000000000..c5b68389b2
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/DefaultComponentContextFactory.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.context;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.context.ComponentContextFactory;
+import org.apache.tuscany.sca.context.RequestContextFactory;
+import org.apache.tuscany.sca.core.assembly.CompositeActivator;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.osoa.sca.ComponentContext;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DefaultComponentContextFactory implements ComponentContextFactory {
+ private final CompositeActivator compositeActivator;
+ private final RequestContextFactory requestContextFactory;
+ private final ProxyFactory proxyFactory;
+ private final AssemblyFactory assemblyFactory;
+ private final JavaInterfaceFactory javaInterfaceFactory;
+ private final InterfaceContractMapper interfaceContractMapper;
+
+ public DefaultComponentContextFactory(CompositeActivator compositeActivator,
+ AssemblyFactory assemblyFactory,
+ ProxyFactory proxyFactory,
+ InterfaceContractMapper interfaceContractMapper,
+ RequestContextFactory requestContextFactory,
+ JavaInterfaceFactory javaInterfaceFactory) {
+ super();
+ this.compositeActivator = compositeActivator;
+ this.assemblyFactory = assemblyFactory;
+ this.proxyFactory = proxyFactory;
+ this.requestContextFactory = requestContextFactory;
+ this.javaInterfaceFactory = javaInterfaceFactory;
+ this.interfaceContractMapper = interfaceContractMapper;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.context.ComponentContextFactory#createComponentContext(org.apache.tuscany.sca.runtime.RuntimeComponent, org.apache.tuscany.sca.context.RequestContextFactory)
+ */
+ public ComponentContext createComponentContext(RuntimeComponent component,
+ RequestContextFactory requestContextFactory) {
+ if (requestContextFactory == null) {
+ requestContextFactory = this.requestContextFactory;
+ }
+ return new ComponentContextImpl(compositeActivator, assemblyFactory, proxyFactory, interfaceContractMapper,
+ requestContextFactory, javaInterfaceFactory, component);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/InstanceWrapper.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/InstanceWrapper.java
new file mode 100644
index 0000000000..b577180291
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/InstanceWrapper.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.context;
+
+import org.apache.tuscany.sca.core.scope.TargetDestructionException;
+import org.apache.tuscany.sca.core.scope.TargetInitializationException;
+
+
+/**
+ * Provides lifecycle management for an implementation instance associated with
+ * a component for use by the component's associated {@link org.apache.tuscany.sca.core.scope.ScopeContainer}
+ *
+ * @version $Rev$ $Date$
+ */
+public interface InstanceWrapper<T> {
+
+ /**
+ * @return
+ */
+ T getInstance();
+
+ /**
+ * @throws TargetInitializationException
+ */
+ void start() throws TargetInitializationException;
+
+ /**
+ * @throws TargetDestructionException
+ */
+ void stop() throws TargetDestructionException;
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/RequestContextImpl.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/RequestContextImpl.java
new file mode 100644
index 0000000000..aa69bb3ae5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/RequestContextImpl.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.context;
+
+import java.util.List;
+
+import javax.security.auth.Subject;
+
+import org.apache.tuscany.sca.core.invocation.CallbackReferenceImpl;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.core.invocation.ThreadMessageContext;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.apache.tuscany.sca.runtime.ReferenceParameters;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.RequestContext;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class RequestContextImpl implements RequestContext {
+
+ private ProxyFactory proxyFactory;
+
+ public RequestContextImpl(ProxyFactory proxyFactory) {
+ this.proxyFactory = proxyFactory;
+ }
+
+ public Subject getSecuritySubject() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getServiceName() {
+ return ThreadMessageContext.getMessageContext().getTo().getContract().getName();
+ }
+
+ @SuppressWarnings("unchecked")
+ public <B> CallableReference<B> getServiceReference() {
+ Message msgContext = ThreadMessageContext.getMessageContext();
+ // FIXME: [rfeng] Is this the service reference matching the caller side?
+ EndpointReference to = msgContext.getTo();
+ RuntimeComponentService service = (RuntimeComponentService) to.getContract();
+ RuntimeComponent component = (RuntimeComponent) to.getComponent();
+
+ CallableReference<B> callableReference = component.getComponentContext().getCallableReference(null, component, service);
+ ReferenceParameters parameters = msgContext.getFrom().getReferenceParameters();
+ ((CallableReferenceImpl<B>) callableReference).attachCallbackID(parameters.getCallbackID());
+ ((CallableReferenceImpl<B>) callableReference).attachConversation(parameters.getConversationID());
+ return callableReference;
+ }
+
+ @SuppressWarnings("unchecked")
+ public <CB> CB getCallback() {
+ CallableReference<CB> cb = getCallbackReference();
+ if (cb == null) {
+ return null;
+ }
+ return cb.getService();
+ }
+
+ @SuppressWarnings("unchecked")
+ public <CB> CallableReference<CB> getCallbackReference() {
+ Message msgContext = ThreadMessageContext.getMessageContext();
+ EndpointReference to = msgContext.getTo();
+ RuntimeComponentService service = (RuntimeComponentService) to.getContract();
+ RuntimeComponentReference callbackReference = (RuntimeComponentReference)service.getCallbackReference();
+ if (callbackReference == null) {
+ return null;
+ }
+ JavaInterface javaInterface = (JavaInterface) callbackReference.getInterfaceContract().getInterface();
+ Class<CB> javaClass = (Class<CB>)javaInterface.getJavaClass();
+ List<RuntimeWire> wires = callbackReference.getRuntimeWires();
+ CallbackReferenceImpl ref = CallbackReferenceImpl.newInstance(javaClass, proxyFactory, wires);
+ if (ref != null) {
+ //ref.resolveTarget();
+ ReferenceParameters parameters = msgContext.getFrom().getReferenceParameters();
+ ref.attachCallbackID(parameters.getCallbackID());
+ if (ref.getConversation() != null) {
+ ref.attachConversationID(parameters.getConversationID());
+ }
+ }
+ return ref;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ServiceReferenceImpl.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ServiceReferenceImpl.java
new file mode 100644
index 0000000000..1d178421cf
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/context/ServiceReferenceImpl.java
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.context;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.core.assembly.CompositeActivator;
+import org.apache.tuscany.sca.core.conversation.ConversationState;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.apache.tuscany.sca.runtime.ReferenceParameters;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ServiceReference;
+
+/**
+ * Default implementation of a ServiceReference.
+ *
+ * @version $Rev$ $Date$
+ * @param <B> the type of the business interface
+ */
+public class ServiceReferenceImpl<B> extends CallableReferenceImpl<B> implements ServiceReference<B> {
+ private static final long serialVersionUID = 6763709434194361540L;
+
+ protected transient Object callback;
+
+ /*
+ * Public constructor for Externalizable serialization/deserialization
+ */
+ public ServiceReferenceImpl() {
+ super();
+ }
+
+ /*
+ * Public constructor for use by XMLStreamReader2CallableReference
+ */
+ public ServiceReferenceImpl(XMLStreamReader xmlReader) throws Exception {
+ super(xmlReader);
+ }
+
+ /**
+ * @param businessInterface
+ * @param wire
+ * @param proxyFactory
+ */
+ public ServiceReferenceImpl(Class<B> businessInterface, RuntimeWire wire, ProxyFactory proxyFactory) {
+ super(businessInterface, wire, proxyFactory);
+ }
+
+ public ServiceReferenceImpl(Class<B> businessInterface,
+ RuntimeComponent component,
+ RuntimeComponentReference reference,
+ ProxyFactory proxyFactory,
+ CompositeActivator compositeActivator) {
+ super(businessInterface, component, reference, null, proxyFactory, compositeActivator);
+ }
+
+ public ServiceReferenceImpl(Class<B> businessInterface,
+ RuntimeComponent component,
+ RuntimeComponentReference reference,
+ Binding binding,
+ ProxyFactory proxyFactory,
+ CompositeActivator compositeActivator) {
+ super(businessInterface, component, reference, binding, proxyFactory, compositeActivator);
+ }
+
+ public Object getConversationID() {
+ return conversationID;
+ }
+
+ public void setConversationID(Object conversationID) throws IllegalStateException {
+ if (conversation == null || conversation.getState() != ConversationState.ENDED) {
+ this.conversationID = conversationID;
+ this.conversation = null;
+ } else {
+ throw new IllegalStateException("Trying to set the conversationId on a service reference but the state of the conversation "
+ + conversation.getConversationID()
+ + " is "
+ + conversation.getState());
+ }
+ }
+
+ public void setCallbackID(Object callbackID) {
+ this.callbackID = callbackID;
+ }
+
+ public Object getCallback() {
+ return callback;
+ }
+
+ public void setCallback(Object callback) {
+ if (callback != null && !(callback instanceof CallableReference)) {
+ //FIXME: need to check if callback object supports the callback interface
+ // returned by reference.getInterfaceContract().getCallbackInterface()
+ }
+ this.callback = callback;
+ }
+
+ @Override
+ protected ReferenceParameters getReferenceParameters() {
+ ReferenceParameters parameters = super.getReferenceParameters();
+ if (callback != null) {
+ if (callback instanceof ServiceReference) {
+ EndpointReference callbackRef = ((CallableReferenceImpl)callback).getEndpointReference();
+ parameters.setCallbackReference(callbackRef);
+ } else {
+ EndpointReference callbackRef = getRuntimeWire().getSource().getCallbackEndpoint();
+ parameters.setCallbackReference(callbackRef);
+ parameters.setCallbackObjectID(callback);
+ }
+ }
+ return parameters;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationListener.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationListener.java
new file mode 100644
index 0000000000..efa362a929
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationListener.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.conversation;
+
+/**
+ * Listener for the events of a conversation
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ConversationListener {
+ /**
+ * The conversation is started
+ */
+ void conversationStarted(ExtendedConversation conversation);
+ /**
+ * The conversation is ended
+ */
+ void conversationEnded(ExtendedConversation conversation);
+ /**
+ * The conversation is expired
+ */
+ void conversationExpired(ExtendedConversation conversation);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManager.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManager.java
new file mode 100644
index 0000000000..28e22b4f2c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManager.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.conversation;
+
+/**
+ * The manager of conversations
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ConversationManager {
+ /**
+ * @param conversationID
+ * @return
+ */
+ ExtendedConversation startConversation(Object conversationID);
+
+ /**
+ * @param conversationID
+ */
+ void endConversation(Object conversationID);
+
+ /**
+ * @param conversationID
+ * @return
+ */
+ ExtendedConversation getConversation(Object conversationID);
+
+ /**
+ * @param conversationID
+ */
+ void expireConversation(Object conversationID);
+
+ /**
+ * Add a listener to this conversation
+ * @param listener
+ */
+ void addListener(ConversationListener listener);
+
+ /**
+ * Remove a listener from this conversation
+ * @param listener
+ */
+ void removeListener(ConversationListener listener);
+
+ /**
+ * @return the default max age for a conversation
+ */
+ long getMaxAge();
+
+ /**
+ * @return the default max idle time for a conversation
+ */
+ long getMaxIdleTime();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManagerImpl.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManagerImpl.java
new file mode 100644
index 0000000000..8a883f8e15
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationManagerImpl.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.sca.core.conversation;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConversationManagerImpl implements ConversationManager {
+
+ private List<ConversationListener> listeners = Collections.synchronizedList(new ArrayList<ConversationListener>());
+ private Map<Object, ExtendedConversation> conversations = new ConcurrentHashMap<Object, ExtendedConversation>();
+
+ /**
+ * the default max age. this is set to 1 hour
+ */
+ private static final long DEFAULT_MAX_AGE = 60 * 60 * 1000; ;
+
+ /**
+ * the default max idle time. this is set to 1 hour
+ */
+ private static final long DEFAULT_MAX_IDLE_TIME = 60 * 60 * 1000;
+
+ /**
+ * the globally used max age
+ */
+ private final long maxAge;
+
+ /**
+ * the globally used max idle time
+ */
+ private final long maxIdleTime;
+
+ /**
+ * the reaper thread
+ */
+ private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
+
+ /**
+ * constructor
+ */
+ public ConversationManagerImpl() {
+ long mit = DEFAULT_MAX_IDLE_TIME;
+ long ma = DEFAULT_MAX_AGE;
+
+ // Allow privileged access to read system property. Requires PropertyPermission in security
+ // policy.
+ String aProperty = AccessController.doPrivileged(new PrivilegedAction<String>() {
+ public String run() {
+ return System.getProperty("org.apache.tuscany.sca.core.scope.ConversationalScopeContainer.MaxIdleTime");
+ }
+ });
+ if (aProperty != null) {
+ try {
+ mit = (new Long(aProperty) * 1000);
+ } catch (NumberFormatException nfe) {
+ // Ignore
+ }
+ }
+
+ // Allow privileged access to read system property. Requires PropertyPermission in security
+ // policy.
+ aProperty = AccessController.doPrivileged(new PrivilegedAction<String>() {
+ public String run() {
+ return System.getProperty("org.apache.tuscany.sca.core.scope.ConversationalScopeContainer.MaxAge");
+ }
+ });
+ if (aProperty != null) {
+ try {
+ ma = (new Long(aProperty) * 1000);
+ } catch (NumberFormatException nfe) {
+ // Ignore
+ }
+ }
+
+ maxAge = ma;
+ maxIdleTime = mit;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.core.conversation.ConversationManager#addListener(org.apache.tuscany.sca.core.conversation.ConversationListener)
+ */
+ public void addListener(ConversationListener listener) {
+ listeners.add(listener);
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.core.conversation.ConversationManager#endConversation(org.apache.tuscany.sca.core.conversation.ExtendedConversation)
+ */
+ public void endConversation(Object conversationID) {
+ ExtendedConversation conv = getConversation(conversationID);
+ if (conv != null) {
+ conv.setState(ConversationState.ENDED);
+ for (ConversationListener listener : listeners) {
+ listener.conversationEnded(conv);
+ }
+ conv.setConversationID(null);
+ conversations.remove(conversationID);
+ } else {
+ throw new IllegalStateException("Conversation " + conversationID + " doesn't exist.");
+ }
+ }
+
+ public void expireConversation(Object conversationID) {
+ ExtendedConversation conv = getConversation(conversationID);
+ if (conv != null) {
+ for (ConversationListener listener : listeners) {
+ listener.conversationExpired(conv);
+ }
+ conversations.remove(conversationID);
+ } else {
+ throw new IllegalStateException("Conversation " + conversationID + " doesn't exist.");
+ }
+
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.core.conversation.ConversationManager#getConversation(java.lang.Object)
+ */
+ public ExtendedConversation getConversation(Object conversationID) {
+ // ConcurrentHashMap cannot take null key
+ return conversationID == null ? null : conversations.get(conversationID);
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.core.conversation.ConversationManager#removeListener(org.apache.tuscany.sca.core.conversation.ConversationListener)
+ */
+ public void removeListener(ConversationListener listener) {
+ listeners.remove(listener);
+ }
+
+ /**
+ * starts the reaper thread
+ */
+ public void scheduleConversation(ExtendedConversationImpl aConversation, long time)
+ {
+ this.scheduler.schedule(aConversation, time, TimeUnit.MILLISECONDS);
+ }
+
+ /**
+ * stops the reaper thread
+ */
+ public synchronized void stopReaper() {
+
+ // Prevent the scheduler from submitting any additional reapers,
+ // initiate an orderly shutdown if a reaper task is in progress.
+ this.scheduler.shutdown();
+ }
+
+
+ /**
+ * @see org.apache.tuscany.sca.core.conversation.ConversationManager#startConversation(java.lang.Object)
+ */
+ public ExtendedConversation startConversation(Object conversationID) {
+
+ if (conversationID == null) {
+ conversationID = UUID.randomUUID().toString();
+ }
+ ExtendedConversation conversation = getConversation(conversationID);
+ if (conversation != null && conversation.getState() != ConversationState.ENDED) {
+ throw new IllegalStateException(conversation + " already exists.");
+ }
+
+ conversation = new ExtendedConversationImpl(
+ this, conversationID, ConversationState.STARTED);
+ conversations.put(conversationID, conversation);
+ for (ConversationListener listener : listeners) {
+ listener.conversationStarted(conversation);
+ }
+ return conversation;
+ }
+
+ /**
+ * return the default max idle time
+ * @param impProvider the implementation Provider to extract any ConversationAttribute details
+ */
+ public long getMaxIdleTime() {
+ return maxIdleTime;
+ }
+
+ /**
+ * returns the default max age
+ * @param impProvider the implementation Provider to extract any ConversationAttribute details
+ */
+ public long getMaxAge(){
+ return maxAge;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationState.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationState.java
new file mode 100644
index 0000000000..692d6861ba
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ConversationState.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.conversation;
+
+/**
+ * The states of a conversation
+ *
+ * @version $Rev$ $Date$
+ */
+public enum ConversationState {
+ STARTED, ENDED, EXPIRED
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversation.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversation.java
new file mode 100644
index 0000000000..03c18c26b8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversation.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.conversation;
+
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.osoa.sca.Conversation;
+
+/**
+ * An extended interface over org.osoa.Conversation
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ExtendedConversation extends Conversation {
+ /**
+ * Get the state of a conversation
+ * @return The state
+ */
+ ConversationState getState();
+
+ /**
+ * @param state the state to set
+ */
+ void setState(ConversationState state);
+
+ /**
+ * @param conversationID the conversationID to set
+ */
+ void setConversationID(Object conversationID);
+
+
+ /**
+ * will check whether this conversation has expired and update state if it has
+ * @return true if it has expired
+ */
+ boolean isExpired();
+
+ /**
+ * updates the last time this conversation was referenced
+ */
+ void updateLastReferencedTime();
+
+ void initializeConversationAttributes(RuntimeComponent targetComponent);
+
+
+ /**
+ * @return true if the conversational attributes have been initialized
+ */
+ boolean conversationalAttributesInitialized();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversationImpl.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversationImpl.java
new file mode 100644
index 0000000000..0bf66b2817
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/conversation/ExtendedConversationImpl.java
@@ -0,0 +1,265 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.conversation;
+
+import org.apache.tuscany.sca.core.scope.ScopedImplementationProvider;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class ExtendedConversationImpl implements ExtendedConversation, Runnable {
+
+ private final ConversationManagerImpl manager;
+ private volatile Object conversationID;
+ private ConversationState state;
+
+ /**
+ * syncs access to the state
+ */
+ private final Object stateSync = new Object();
+
+ /**
+ * the maximum time a conversation can exist
+ */
+ private long expirationTime = 0;
+
+ /**
+ * the maximum time this conversation can be idle
+ */
+ private long maxIdleTime = 0;
+
+ /**
+ * the maximum age of this conversation
+ */
+ private long maxAge = 0;
+
+ /**
+ * the time that this object was created
+ */
+ private long creationTime;
+
+ /**
+ * the time that this object was last referenced
+ */
+ private long lastReferencedTime;
+
+ /**
+ * boolean to ensure expiry only occurs once
+ */
+ private boolean expired = false;
+
+ /**
+ * boolean to indicate if the conversation attributes have
+ * been set. In the case where a remote binding is used
+ * within a composite the JDKInvocationHandler can create the
+ * conversation but the conversationAttributes are not available
+ * until the conversation is retrieved by the RuntimeWireInvoker
+ */
+ private boolean conversationAttributesInitialized = false;
+
+ /**
+ * Constructor
+ * @param manager the conversation manager
+ * @param conversationID the conversation id associated with this conversation
+ * @param state the initial state of this conversation
+ * @param aMaxAge the maximum age of the conversation
+ * @param aMaxIdleTime the maximum idle time
+ */
+ public ExtendedConversationImpl(ConversationManagerImpl manager,
+ Object conversationID, ConversationState state) {
+ super();
+
+ this.creationTime = System.currentTimeMillis();
+ this.lastReferencedTime = creationTime;
+ this.manager = manager;
+ this.conversationID = conversationID;
+ this.state = state;
+ }
+
+ /**
+ * will check whether this conversation has expired and update state if it has
+ * @return true if it has expired
+ */
+ public boolean isExpired() {
+ long currentTime;
+ synchronized (stateSync) {
+
+ // if the attributes haven't been initialized then
+ // this conversation object can't expire
+ if (conversationAttributesInitialized == false) {
+ return false;
+ }
+
+ // check state first
+ if (state == ConversationState.EXPIRED) {
+ return true;
+ }
+
+ // check whether the time is finished
+ currentTime = System.currentTimeMillis();
+ if (((this.lastReferencedTime + this.maxIdleTime) <= currentTime)
+ || (this.expirationTime <= currentTime)) {
+ setState(ConversationState.EXPIRED);
+ return true;
+ }
+ }
+ scheduleNextExpiryTime(currentTime);
+ return false;
+ }
+
+ /**
+ * schedule next expiry time
+ */
+ public void scheduleNextExpiryTime(long currentTime) {
+ if ((lastReferencedTime + maxIdleTime) < expirationTime){
+ manager.scheduleConversation(this, (lastReferencedTime + maxIdleTime) - currentTime);
+ } else {
+ manager.scheduleConversation(this, expirationTime - currentTime);
+ }
+ }
+ /**
+ * updates the last time this conversation was referenced
+ */
+ public void updateLastReferencedTime() {
+ this.lastReferencedTime = System.currentTimeMillis();
+ if (conversationAttributesInitialized == true){
+ scheduleNextExpiryTime(lastReferencedTime);
+ }
+ }
+
+ public ConversationState getState() {
+ synchronized (stateSync){
+ return state;
+ }
+ }
+
+ public void end() {
+ manager.endConversation(conversationID);
+ }
+
+ public Object getConversationID() {
+ return conversationID;
+ }
+
+ /**
+ * @param state the state to set
+ */
+ public void setState(ConversationState state) {
+ synchronized (stateSync){
+ this.state = state;
+ }
+ }
+
+ /**
+ * @param conversationID the conversationID to set
+ */
+ public void setConversationID(Object conversationID) {
+ synchronized (stateSync){
+ if (state != ConversationState.ENDED) {
+ throw new IllegalStateException("The state of conversation " + conversationID + " " + state);
+ }
+ }
+ this.conversationID = conversationID;
+ }
+
+ /**
+ * @param maxAge the maximum age of this conversation
+ */
+ public void initializeConversationAttributes(RuntimeComponent targetComponent){
+ if (targetComponent != null){
+ this.maxAge = getMaxIdleTime(targetComponent.getImplementationProvider());
+ this.maxIdleTime = getMaxAge(targetComponent.getImplementationProvider());
+ this.expirationTime = creationTime + maxAge;
+ this.conversationAttributesInitialized = true;
+ }
+ }
+
+ /**
+ * @return true if the conversational attributes have been initialized
+ */
+ public boolean conversationalAttributesInitialized(){
+ return this.conversationAttributesInitialized;
+ }
+
+ /**
+ * return the max idle time
+ * @param impProvider the implementation Provider to extract any ConversationAttribute details
+ */
+ private long getMaxIdleTime(ImplementationProvider impProvider) {
+ // Check to see if the maxIdleTime has been specified using @ConversationAttributes.
+ // Implementation annotated attributes are honoured first.
+ if ((impProvider != null) &&
+ (impProvider instanceof ScopedImplementationProvider)) {
+ ScopedImplementationProvider aScopedImpl =
+ (ScopedImplementationProvider) impProvider;
+
+ long maxIdleTime = aScopedImpl.getMaxIdleTime();
+ if (maxIdleTime > 0) {
+ return maxIdleTime;
+ }
+ }
+ return manager.getMaxIdleTime();
+ }
+
+ /**
+ * returns the max age
+ * @param impProvider the implementation Provider to extract any ConversationAttribute details
+ */
+ private long getMaxAge(ImplementationProvider impProvider){
+
+ // Check to see if the maxAge has been specified using @ConversationAttributes.
+ // Implementation annotated attributes are honoured first.
+ if ((impProvider != null) &&
+ (impProvider instanceof ScopedImplementationProvider)) {
+ ScopedImplementationProvider aScopedImpl =
+ (ScopedImplementationProvider) impProvider;
+
+ long maxAge = aScopedImpl.getMaxAge();
+ if (maxAge > 0) {
+ return maxAge;
+ }
+ }
+ return manager.getMaxAge();
+ }
+
+ /**
+ * called when expiring
+ */
+ public void run() {
+ synchronized (stateSync){
+ if (!expired){
+ if (isExpired()) {
+ expired = true;
+ try {
+ manager.expireConversation(getConversationID());
+ } catch (IllegalStateException ise) {
+ // ignore this.. this can occur if another thread has subsequently ended
+ // the conversation
+ }
+ }
+ }
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/BaseEventPublisher.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/BaseEventPublisher.java
new file mode 100644
index 0000000000..517e5579a4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/BaseEventPublisher.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.event;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.tuscany.sca.event.Event;
+import org.apache.tuscany.sca.event.EventFilter;
+import org.apache.tuscany.sca.event.EventPublisher;
+import org.apache.tuscany.sca.event.RuntimeEventListener;
+import org.apache.tuscany.sca.event.TrueFilter;
+
+/**
+ * Base implementation of an <code>EventPublisher</code>
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class BaseEventPublisher 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/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStart.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStart.java
new file mode 100644
index 0000000000..45eab7da1b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStart.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.event;
+
+import java.net.URI;
+
+import org.apache.tuscany.sca.event.Event;
+
+/**
+ * Propagated when a component starts
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentStart implements Event {
+
+ private Object source;
+ private URI uri;
+
+ /**
+ * Creates a component start event
+ *
+ * @param source the source of the event
+ * @param componentURI the URI of the component being started
+ */
+ public ComponentStart(Object source, URI componentURI) {
+ this.source = source;
+ this.uri = componentURI;
+ }
+
+ public URI getComponentURI() {
+ return uri;
+ }
+
+ public Object getSource() {
+ return source;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStop.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStop.java
new file mode 100644
index 0000000000..4dc79c3844
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ComponentStop.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.event;
+
+import java.net.URI;
+
+import org.apache.tuscany.sca.event.Event;
+
+/**
+ * Propagated when a component stops
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentStop implements Event {
+
+ private Object source;
+ private URI uri;
+
+ /**
+ * Creates a component stop event
+ *
+ * @param source the source of the event
+ * @param componentUri the composite component associated the component being stopped
+ */
+ public ComponentStop(Object source, URI componentUri) {
+ this.source = source;
+ this.uri = componentUri;
+ }
+
+ public URI getComponentURI() {
+ return uri;
+ }
+
+ public Object getSource() {
+ return source;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationEnd.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationEnd.java
new file mode 100644
index 0000000000..d3106c7052
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationEnd.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.event;
+
+import org.apache.tuscany.sca.event.Event;
+
+
+
+/**
+ * Propagated when a conversation is expired
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConversationEnd implements Event {
+
+ private Object source;
+ private Object id;
+
+ /**
+ * Creates a new event
+ *
+ * @param source the source of the event
+ * @param id the id of the conversation being ended
+ */
+ public ConversationEnd(Object source, Object id) {
+ this.source = source;
+ this.id = id;
+ }
+
+ public Object getSource() {
+ return source;
+ }
+
+ public Object getConversationID() {
+ return id;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationStart.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationStart.java
new file mode 100644
index 0000000000..123400fbdd
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/ConversationStart.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.event;
+
+import org.apache.tuscany.sca.event.Event;
+
+
+/**
+ * Propagated when a conversation has started
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConversationStart implements Event {
+
+ private Object source;
+ private Object id;
+
+ /**
+ * Creates a new event
+ *
+ * @param source the source of the event
+ * @param id the id of the conversation being started
+ */
+ public ConversationStart(Object source, Object id) {
+ this.source = source;
+ this.id = id;
+ }
+
+ public Object getSource() {
+ return source;
+ }
+
+ public Object getConversationID() {
+ return id;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionEnd.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionEnd.java
new file mode 100644
index 0000000000..68cb5c2966
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionEnd.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.event;
+
+import org.apache.tuscany.sca.event.Event;
+
+
+
+/**
+ * Propagated when an HTTP-based session is expired
+ *
+ * @version $Rev$ $Date$
+ */
+public class HttpSessionEnd implements Event {
+
+ private Object source;
+ private Object id;
+
+ /**
+ * Creates a new event
+ *
+ * @param source the source of the event
+ * @param id the id of the HTTP session being ended
+ */
+ public HttpSessionEnd(Object source, Object id) {
+ this.source = source;
+ this.id = id;
+ }
+
+ public Object getSource() {
+ return source;
+ }
+
+ public Object getSessionID() {
+ return id;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionStart.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionStart.java
new file mode 100644
index 0000000000..38a4fb10d6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/HttpSessionStart.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.event;
+
+import org.apache.tuscany.sca.event.Event;
+
+
+/**
+ * Propagated when an HTTP-based session has started
+ *
+ * @version $Rev$ $Date$
+ */
+public class HttpSessionStart implements Event {
+
+ private Object source;
+ private Object id;
+
+ /**
+ * Creates a new event
+ *
+ * @param source the source of the event
+ * @param id the id of the HTTP session being started
+ */
+ public HttpSessionStart(Object source, Object id) {
+ this.source = source;
+ this.id = id;
+ }
+
+ public Object getSource() {
+ return source;
+ }
+
+ public Object getSessionID() {
+ return id;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestEnd.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestEnd.java
new file mode 100644
index 0000000000..d7e797bbb9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestEnd.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.event;
+
+import org.apache.tuscany.sca.event.Event;
+
+/**
+ * Propagated when a request completes or is ended
+ *
+ * @version $Rev$ $Date$
+ */
+public class RequestEnd implements Event {
+
+ private Object source;
+
+ /**
+ * Creates a new event
+ *
+ * @param source the source of the event
+ */
+ public RequestEnd(Object source) {
+ this.source = source;
+ }
+
+ public Object getSource() {
+ return source;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestStart.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestStart.java
new file mode 100644
index 0000000000..7530156b11
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/event/RequestStart.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.event;
+
+import org.apache.tuscany.sca.event.Event;
+
+/**
+ * Propagated when a request is started in the runtime
+ *
+ * @version $Rev$ $Date$
+ */
+public class RequestStart implements Event {
+
+ private Object source;
+
+ /**
+ * Creates a new event
+ *
+ * @param source the source of the event
+ */
+ public RequestStart(Object source) {
+ this.source = source;
+ }
+
+ public Object getSource() {
+ return source;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/factory/ObjectCreationException.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/factory/ObjectCreationException.java
new file mode 100644
index 0000000000..d35b27fd24
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/factory/ObjectCreationException.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.factory;
+
+
+/**
+ * Denotes an error creating a new object instance
+ *
+ * @version $Rev$ $Date$
+ */
+public class ObjectCreationException extends RuntimeException {
+ private static final long serialVersionUID = -6423113430265944499L;
+
+ public ObjectCreationException() {
+ super();
+ }
+
+ public ObjectCreationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ObjectCreationException(String message) {
+ super(message);
+ }
+
+ public ObjectCreationException(Throwable cause) {
+ super(cause);
+ }
+
+}
+
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/factory/ObjectFactory.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/factory/ObjectFactory.java
new file mode 100644
index 0000000000..3f64d2405b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/factory/ObjectFactory.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.factory;
+
+/**
+ * Implementations create new instances of a particular type
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ObjectFactory<T> {
+
+ /**
+ * Return a instance of the type that this factory creates.
+ *
+ * @return a instance from this factory
+ */
+ T getInstance() throws ObjectCreationException;
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java
new file mode 100644
index 0000000000..588c43b8b1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallableReferenceObjectFactory.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.invocation;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.osoa.sca.CallableReference;
+
+/**
+ * Uses a wire to return a CallableReference
+ *
+ * @version $Rev$ $Date$
+ */
+public class CallableReferenceObjectFactory implements ObjectFactory<CallableReference<?>> {
+ private Class<?> businessInterface;
+ private RuntimeComponent component;
+ private RuntimeComponentReference reference;
+ private Binding binding;
+
+ /**
+ * Constructor.
+ *
+ * To support the @Reference protected CallableReference<MyService> ref;
+ *
+ * @param businessInterface the interface to inject
+ * @param component the component defining the reference to be injected
+ * @param reference the reference to be injected
+ * @param binding the binding for the reference
+ */
+ public CallableReferenceObjectFactory(Class<?> businessInterface,
+ RuntimeComponent component,
+ RuntimeComponentReference reference,
+ Binding binding) {
+ this.businessInterface = businessInterface;
+ this.component = component;
+ this.reference = reference;
+ this.binding = binding;
+ }
+
+ public CallableReference<?> getInstance() throws ObjectCreationException {
+ return component.getComponentContext().getServiceReference(businessInterface, reference, binding);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java
new file mode 100644
index 0000000000..d19aa237cd
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackInterfaceInterceptor.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.invocation;
+
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.ReferenceParameters;
+import org.osoa.sca.NoRegisteredCallbackException;
+
+/**
+ * An interceptor applied to the forward direction of a wire that ensures the callback target implements the required
+ * service contract. This is required as callback targets may be set dynamically by service implementations.
+ *
+ * @version $Rev$ $Date$
+ */
+public class CallbackInterfaceInterceptor implements Interceptor {
+ private Invoker next;
+
+ public CallbackInterfaceInterceptor() {
+ }
+
+ public Message invoke(Message msg) {
+ ReferenceParameters parameters = msg.getFrom().getReferenceParameters();
+ if (parameters.getCallbackObjectID() != null || parameters.getCallbackReference() != msg.getFrom()
+ .getCallbackEndpoint()) {
+ return next.invoke(msg);
+ } else {
+ throw new NoRegisteredCallbackException("Callback target does not implement the callback interface");
+ }
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceImpl.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceImpl.java
new file mode 100644
index 0000000000..97c69c33cb
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceImpl.java
@@ -0,0 +1,268 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.invocation;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Contract;
+import org.apache.tuscany.sca.assembly.OptimizableBinding;
+import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl;
+import org.apache.tuscany.sca.core.assembly.RuntimeComponentReferenceImpl;
+import org.apache.tuscany.sca.core.assembly.RuntimeWireImpl;
+import org.apache.tuscany.sca.core.context.CallableReferenceImpl;
+import org.apache.tuscany.sca.core.context.ComponentContextHelper;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+
+/**
+ * Returns proxy instance for a wire callback
+ *
+ * @version $Rev: 576055 $ $Date: 2007-09-16 08:11:45 +0100 (Sun, 16 Sep 2007) $
+ */
+public class CallbackReferenceImpl<B> extends CallableReferenceImpl<B> {
+ private RuntimeWire wire;
+ private List<RuntimeWire> wires;
+ private EndpointReference resolvedEndpoint;
+ private Object convID;
+
+ public static CallbackReferenceImpl newInstance(Class interfaze,
+ ProxyFactory proxyFactory,
+ List<RuntimeWire> wires) {
+ if (getCallbackEndpoint(ThreadMessageContext.getMessageContext()) != null) {
+ return new CallbackReferenceImpl(interfaze, proxyFactory, wires);
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Public constructor for Externalizable serialization/deserialization.
+ */
+ public CallbackReferenceImpl() {
+ super();
+ }
+
+ private CallbackReferenceImpl(Class<B> interfaze, ProxyFactory proxyFactory, List<RuntimeWire> wires) {
+ super(interfaze, null, proxyFactory);
+ this.wires = wires;
+ init();
+ }
+
+ public void init() {
+ Message msgContext = ThreadMessageContext.getMessageContext();
+ wire = selectCallbackWire(msgContext);
+ if (wire == null) {
+ //FIXME: need better exception
+ throw new RuntimeException("No callback binding found for " + msgContext.getTo().getURI());
+ }
+ resolvedEndpoint = getCallbackEndpoint(msgContext);
+ convID = msgContext.getFrom().getReferenceParameters().getConversationID();
+ callbackID = msgContext.getFrom().getReferenceParameters().getCallbackID();
+ }
+
+ @Override
+ protected Object createProxy() throws Exception {
+ return proxyFactory.createCallbackProxy(this);
+ }
+
+ protected RuntimeWire getCallbackWire() {
+ if (resolvedEndpoint == null) {
+ return null;
+ } else {
+ return cloneAndBind(wire);
+ }
+ }
+
+ protected Object getConvID() {
+ return convID;
+ }
+
+ protected EndpointReference getResolvedEndpoint() {
+ return resolvedEndpoint;
+ }
+
+ private RuntimeWire selectCallbackWire(Message msgContext) {
+ // look for callback binding with same name as service binding
+ EndpointReference to = msgContext.getTo();
+ if (to == null) {
+ //FIXME: need better exception
+ throw new RuntimeException("Destination for forward call is not available");
+ }
+ for (RuntimeWire wire : wires) {
+ if (wire.getSource().getBinding().getName().equals(to.getBinding().getName())) {
+ return wire;
+ }
+ }
+
+ // if no match, look for callback binding with same type as service binding
+ for (RuntimeWire wire : wires) {
+ if (wire.getSource().getBinding().getClass() == to.getBinding().getClass()) {
+ return wire;
+ }
+ }
+
+ // no suitable callback wire was found
+ return null;
+ }
+
+ /**
+ * @param msgContext
+ */
+ private static EndpointReference getCallbackEndpoint(Message msgContext) {
+ EndpointReference from = msgContext.getFrom();
+ if (from == null) {
+ return null;
+ }
+ return from.getReferenceParameters().getCallbackReference();
+ }
+
+ private RuntimeWire cloneAndBind(RuntimeWire wire) {
+ RuntimeWire boundWire = null;
+ if (resolvedEndpoint != null) {
+ boundWire = ((RuntimeWireImpl)wire).lookupCache(resolvedEndpoint);
+ if (boundWire != null) {
+ return boundWire;
+ }
+ try {
+ Contract contract = resolvedEndpoint.getContract();
+ RuntimeComponentReference ref = null;
+ if (contract == null) {
+ boundWire = (RuntimeWire)wire.clone();
+
+ } else if (contract instanceof RuntimeComponentReference) {
+ ref = (RuntimeComponentReference)contract;
+ boundWire = ref.getRuntimeWire(resolvedEndpoint.getBinding());
+
+ } else { // contract instanceof RuntimeComponentService
+ ref = bind((RuntimeComponentReference)wire.getSource().getContract(),
+ resolvedEndpoint.getComponent(),
+ (RuntimeComponentService)contract);
+ boundWire = ref.getRuntimeWires().get(0);
+ }
+ configureWire(boundWire);
+ ((RuntimeWireImpl)wire).addToCache(resolvedEndpoint, boundWire);
+ } catch (CloneNotSupportedException e) {
+ // will not happen
+ }
+ }
+ return boundWire;
+ }
+
+ private static RuntimeComponentReference bind(RuntimeComponentReference reference,
+ RuntimeComponent component,
+ RuntimeComponentService service) throws CloneNotSupportedException {
+ RuntimeComponentReference ref = (RuntimeComponentReference)reference.clone();
+ ref.getTargets().add(service);
+ ref.getBindings().clear();
+ for (Binding binding : service.getBindings()) {
+ if (binding instanceof OptimizableBinding) {
+ OptimizableBinding optimizableBinding = (OptimizableBinding)((OptimizableBinding)binding).clone();
+ optimizableBinding.setTargetBinding(binding);
+ optimizableBinding.setTargetComponent(component);
+ optimizableBinding.setTargetComponentService(service);
+ ref.getBindings().add(optimizableBinding);
+ } else {
+ ref.getBindings().add(binding);
+ }
+ }
+ return ref;
+ }
+
+ private void configureWire(RuntimeWire wire) {
+ // need to set the endpoint on the binding also so that when the chains are created next
+ // the sca binding can decide whether to provide local or remote invokers.
+ // TODO - there is a problem here though in that I'm setting a target on a
+ // binding that may possibly be trying to point at two things in the multi threaded
+ // case. Need to confirm the general model here and how the clone and bind part
+ // is intended to work
+ Binding binding = wire.getSource().getBinding();
+ binding.setURI(resolvedEndpoint.getURI());
+
+ // also need to set the target contract as it varies for the sca binding depending on
+ // whether it is local or remote
+ RuntimeComponentReference ref = (RuntimeComponentReference)wire.getSource().getContract();
+ wire.getTarget().setInterfaceContract(ref.getBindingProvider(binding).getBindingInterfaceContract());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+ super.readExternal(in);
+ this.callbackID = in.readObject();
+ this.convID = in.readObject();
+
+ this.compositeActivator = ComponentContextHelper.getCurrentCompositeActivator();
+
+ // Get the target Component and Service from the URI
+ final String uri = in.readUTF();
+ final Component targetComponent = super.resolveComponentURI(uri);
+ final ComponentService targetService = super.resolveServiceURI(uri, targetComponent);
+ final InterfaceContract targetServiceIfaceContract = targetService.getInterfaceContract();
+
+ // Re-create the resolved Endpoint
+ this.resolvedEndpoint = new EndpointReferenceImpl(
+ (RuntimeComponent) targetComponent, targetService, null,
+ targetServiceIfaceContract);
+
+ // Copy the Java Interface from the Service
+ final JavaInterface ji = (JavaInterface) targetServiceIfaceContract.getInterface();
+ this.businessInterface = (Class<B>) ji.getJavaClass();
+
+ // We need to re-create the callback wire. We need to do this on a clone of the Service
+ // wire since we need to change some details on it.
+ // FIXME: Is this the best way to do this?
+ final RuntimeWire cbWire = ((RuntimeComponentService) targetService).getRuntimeWires().get(0);
+ try {
+ this.wire = (RuntimeWireImpl) cbWire.clone();
+ } catch (CloneNotSupportedException e) {
+ throw new IOException(e.toString());
+ }
+
+ // Setup the reference on the cloned wire
+ final RuntimeComponentReference ref = new RuntimeComponentReferenceImpl();
+ ref.setComponent((RuntimeComponent) targetComponent);
+ ref.setInterfaceContract(targetServiceIfaceContract);
+ ((EndpointReferenceImpl) this.wire.getSource()).setContract(ref);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void writeExternal(ObjectOutput out) throws IOException {
+ super.writeExternal(out);
+ out.writeObject(this.callbackID);
+ out.writeObject(this.convID);
+ out.writeUTF(this.resolvedEndpoint.getURI());
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceObjectFactory.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceObjectFactory.java
new file mode 100644
index 0000000000..b5b40811ad
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackReferenceObjectFactory.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.invocation;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.CallableReference;
+
+/**
+ * Uses a wire to return a CallableReference
+ *
+ * @version $Rev: 574648 $ $Date: 2007-09-11 18:45:36 +0100 (Tue, 11 Sep 2007) $
+ */
+public class CallbackReferenceObjectFactory implements ObjectFactory<CallableReference<?>> {
+ private Class<?> businessInterface;
+ private ProxyFactory proxyFactory;
+ private List<RuntimeWire> wires;
+
+ public CallbackReferenceObjectFactory(Class<?> interfaze, ProxyFactory proxyFactory, List<RuntimeWire> wires) {
+ this.businessInterface = interfaze;
+ this.proxyFactory = proxyFactory;
+ this.wires = wires;
+ }
+
+ public CallableReference<?> getInstance() throws ObjectCreationException {
+ return CallbackReferenceImpl.newInstance(businessInterface, proxyFactory, wires);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.java
new file mode 100644
index 0000000000..2b37c30451
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CallbackWireObjectFactory.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.invocation;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+
+/**
+ * Returns proxy instance for a wire callback
+ *
+ * @version $Rev$ $Date$
+ */
+public class CallbackWireObjectFactory<B> implements ObjectFactory<B> {
+ private Class<B> businessInterface;
+ private ProxyFactory proxyFactory;
+ private List<RuntimeWire> wires;
+
+ public CallbackWireObjectFactory(Class<B> interfaze, ProxyFactory proxyFactory, List<RuntimeWire> wires) {
+ this.businessInterface = interfaze;
+ this.proxyFactory = proxyFactory;
+ this.wires = wires;
+ }
+
+ public B getInstance() throws ObjectCreationException {
+ return proxyFactory.createCallbackProxy(businessInterface, wires);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java
new file mode 100644
index 0000000000..0fa1d27d2a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/CglibProxyFactory.java
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.invocation;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+import net.sf.cglib.proxy.Callback;
+import net.sf.cglib.proxy.Enhancer;
+import net.sf.cglib.proxy.Factory;
+import net.sf.cglib.proxy.MethodInterceptor;
+import net.sf.cglib.proxy.MethodProxy;
+
+import org.apache.tuscany.sca.core.context.CallableReferenceImpl;
+import org.apache.tuscany.sca.core.context.ServiceReferenceImpl;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ServiceReference;
+
+/**
+ * The implementation of a wire service that uses cglib dynamic proxies
+ *
+ * @version $Rev$ $Date$
+ */
+@SuppressWarnings("unused")
+public class CglibProxyFactory implements ProxyFactory {
+ private MessageFactory messageFactory;
+
+ public CglibProxyFactory(MessageFactory messageFactory, InterfaceContractMapper mapper) {
+ this.messageFactory = messageFactory;
+
+ }
+
+ public <T> T createProxy(Class<T> interfaze, RuntimeWire wire) throws ProxyCreationException {
+ ServiceReference<T> serviceReference = new ServiceReferenceImpl(interfaze, wire, this);
+ return createProxy(serviceReference);
+ }
+
+ /**
+ * create the proxy with cglib. use the same JDKInvocationHandler as
+ * JDKProxyService.
+ */
+ public <T> T createProxy(CallableReference<T> callableReference) throws ProxyCreationException {
+ Enhancer enhancer = new Enhancer();
+ Class<T> interfaze = callableReference.getBusinessInterface();
+ enhancer.setSuperclass(interfaze);
+ enhancer.setCallback(new CglibMethodInterceptor<T>(callableReference));
+ Object proxy = enhancer.create();
+ ((CallableReferenceImpl)callableReference).setProxy(proxy);
+ return interfaze.cast(proxy);
+ }
+
+ /**
+ * create the callback proxy with cglib. use the same
+ * JDKCallbackInvocationHandler as JDKProxyService.
+ */
+ public <T> T createCallbackProxy(Class<T> interfaze, final List<RuntimeWire> wires) throws ProxyCreationException {
+ CallbackReferenceImpl<T> callbackReference = CallbackReferenceImpl.newInstance(interfaze, this, wires);
+ return callbackReference != null ? createCallbackProxy(callbackReference) : null;
+ }
+
+ /**
+ * create the callback proxy with cglib. use the same
+ * JDKCallbackInvocationHandler as JDKProxyService.
+ */
+ public <T> T createCallbackProxy(CallbackReferenceImpl<T> callbackReference) throws ProxyCreationException {
+ Enhancer enhancer = new Enhancer();
+ Class<T> interfaze = callbackReference.getBusinessInterface();
+ enhancer.setSuperclass(interfaze);
+ enhancer.setCallback(new CglibMethodInterceptor<T>(callbackReference));
+ Object proxy = enhancer.create();
+ callbackReference.setProxy(proxy);
+ return interfaze.cast(proxy);
+ }
+
+ @SuppressWarnings("unchecked")
+ public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+ if (isProxyClass(target.getClass())) {
+ Factory factory = (Factory)target;
+ Callback[] callbacks = factory.getCallbacks();
+ if (callbacks.length != 1 || !(callbacks[0] instanceof CglibMethodInterceptor)) {
+ throw new IllegalArgumentException("The object is not a known proxy.");
+ }
+ CglibMethodInterceptor interceptor = (CglibMethodInterceptor)callbacks[0];
+ return (R)interceptor.invocationHandler.getCallableReference();
+ } else {
+ throw new IllegalArgumentException("The object is not a known proxy.");
+ }
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.core.invocation.ProxyFactory#isProxyClass(java.lang.Class)
+ */
+ public boolean isProxyClass(Class<?> clazz) {
+ return Factory.class.isAssignableFrom(clazz);
+ }
+
+ private class CglibMethodInterceptor<T> implements MethodInterceptor {
+ private JDKInvocationHandler invocationHandler;
+
+ public CglibMethodInterceptor(CallableReference<T> callableReference) {
+ invocationHandler = new JDKInvocationHandler(messageFactory, callableReference);
+ }
+
+ public CglibMethodInterceptor(CallbackReferenceImpl<T> callbackReference) {
+ invocationHandler = new JDKCallbackInvocationHandler(messageFactory, callbackReference);
+ }
+
+ /*
+ public CglibMethodInterceptor(Class<T> interfaze, RuntimeWire wire) {
+ ServiceReference<T> serviceRef = new ServiceReferenceImpl<T>(interfaze, wire, CglibProxyFactory.this);
+ invocationHandler = new JDKInvocationHandler(messageFactory, serviceRef);
+ }
+
+ public CglibMethodInterceptor(Class<T> interfaze, List<RuntimeWire> wires) {
+ CallbackReferenceImpl ref = new CallbackReferenceImpl(interfaze, CglibProxyFactory.this, wires);
+ invocationHandler = new JDKCallbackInvocationHandler(messageFactory, ref);
+ }
+ */
+
+ /**
+ * @see net.sf.cglib.proxy.MethodInterceptor#intercept(java.lang.Object, java.lang.reflect.Method, java.lang.Object[], net.sf.cglib.proxy.MethodProxy)
+ */
+ public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
+ Object result = invocationHandler.invoke(proxy, method, args);
+ return result;
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/DefaultProxyFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/DefaultProxyFactoryExtensionPoint.java
new file mode 100644
index 0000000000..9acb4be6f8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/DefaultProxyFactoryExtensionPoint.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.invocation;
+
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+
+/**
+ * Default implementation of a ProxyFactoryExtensionPoint.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultProxyFactoryExtensionPoint implements ProxyFactoryExtensionPoint {
+ private InterfaceContractMapper interfaceContractMapper;
+ private MessageFactory messageFactory;
+
+ private ProxyFactory interfaceFactory;
+ private ProxyFactory classFactory;
+
+ public DefaultProxyFactoryExtensionPoint(ExtensionPointRegistry extensionPoints) {
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ this.interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class);
+
+ ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ this.messageFactory = modelFactories.getFactory(MessageFactory.class);
+
+ interfaceFactory = new JDKProxyFactory(messageFactory, interfaceContractMapper);
+ }
+
+ public DefaultProxyFactoryExtensionPoint(MessageFactory messageFactory, InterfaceContractMapper mapper) {
+ this.interfaceContractMapper = mapper;
+ this.messageFactory = messageFactory;
+ interfaceFactory = new JDKProxyFactory(messageFactory, mapper);
+ }
+
+ public ProxyFactory getClassProxyFactory() {
+ return classFactory;
+ }
+
+ public ProxyFactory getInterfaceProxyFactory() {
+ return interfaceFactory;
+ }
+
+ public void setClassProxyFactory(ProxyFactory factory) {
+ this.classFactory = factory;
+
+ }
+
+ public void setInterfaceProxyFactory(ProxyFactory factory) {
+ this.interfaceFactory = factory;
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleProxyFactory.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleProxyFactory.java
new file mode 100644
index 0000000000..fcb48259b9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleProxyFactory.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.invocation;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.CallableReference;
+
+/**
+ * An extensible proxy factory.
+ *
+ * @version $Rev: $ $Date: $
+ */
+public class ExtensibleProxyFactory implements ProxyFactory {
+
+ private ProxyFactoryExtensionPoint proxyFactories;
+
+ public ExtensibleProxyFactory(ProxyFactoryExtensionPoint proxyFactories) {
+ this.proxyFactories = proxyFactories;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.core.invocation.ProxyFactory#cast(java.lang.Object)
+ */
+ @SuppressWarnings("unchecked")
+ public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+ ProxyFactory interfaceFactory = proxyFactories.getInterfaceProxyFactory();
+ ProxyFactory classFactory = proxyFactories.getClassProxyFactory();
+ if (interfaceFactory.isProxyClass(target.getClass())) {
+ return (R)interfaceFactory.cast(target);
+ } else if (classFactory != null && classFactory.isProxyClass(target.getClass())) {
+ return (R)classFactory.cast(target);
+ } else {
+ throw new IllegalArgumentException("The target is not a callable proxy");
+ }
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.core.invocation.ProxyFactory#createCallbackProxy(java.lang.Class,
+ * java.util.List)
+ */
+ public <T> T createCallbackProxy(Class<T> interfaze, List<RuntimeWire> wires) throws ProxyCreationException {
+ ProxyFactory interfaceFactory = proxyFactories.getInterfaceProxyFactory();
+ ProxyFactory classFactory = proxyFactories.getClassProxyFactory();
+ if (interfaze.isInterface()) {
+ return interfaceFactory.createCallbackProxy(interfaze, wires);
+ } else {
+ return classFactory.createCallbackProxy(interfaze, wires);
+ }
+ }
+
+ public <T> T createProxy(CallableReference<T> callableReference) throws ProxyCreationException {
+ ProxyFactory interfaceFactory = proxyFactories.getInterfaceProxyFactory();
+ ProxyFactory classFactory = proxyFactories.getClassProxyFactory();
+ if (callableReference.getBusinessInterface().isInterface()) {
+ return interfaceFactory.createProxy(callableReference);
+ } else {
+ return classFactory.createProxy(callableReference);
+ }
+ }
+
+ public <T> T createCallbackProxy(CallbackReferenceImpl<T> callbackReference) throws ProxyCreationException {
+ ProxyFactory interfaceFactory = proxyFactories.getInterfaceProxyFactory();
+ ProxyFactory classFactory = proxyFactories.getClassProxyFactory();
+ if (callbackReference.getBusinessInterface().isInterface()) {
+ return interfaceFactory.createCallbackProxy(callbackReference);
+ } else {
+ return classFactory.createCallbackProxy(callbackReference);
+ }
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.core.invocation.ProxyFactory#createProxy(java.lang.Class,
+ * org.apache.tuscany.sca.runtime.RuntimeWire)
+ */
+ public <T> T createProxy(Class<T> interfaze, RuntimeWire wire) throws ProxyCreationException {
+ ProxyFactory interfaceFactory = proxyFactories.getInterfaceProxyFactory();
+ ProxyFactory classFactory = proxyFactories.getClassProxyFactory();
+ if (interfaze.isInterface()) {
+ return interfaceFactory.createProxy(interfaze, wire);
+ } else {
+ return classFactory.createProxy(interfaze, wire);
+ }
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.core.invocation.ProxyFactory#isProxyClass(java.lang.Class)
+ */
+ public boolean isProxyClass(Class<?> clazz) {
+ ProxyFactory interfaceFactory = proxyFactories.getInterfaceProxyFactory();
+ ProxyFactory classFactory = proxyFactories.getClassProxyFactory();
+ return interfaceFactory.isProxyClass(clazz) || (classFactory != null && classFactory.isProxyClass(clazz));
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleWireProcessor.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleWireProcessor.java
new file mode 100644
index 0000000000..934f2f7aa0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ExtensibleWireProcessor.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.invocation;
+
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.apache.tuscany.sca.runtime.RuntimeWireProcessor;
+import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint;
+
+/**
+ * The default implementation of an extensible <code>WireProcessor</code>
+ *
+ * @version $Rev$ $Date$
+ */
+public class ExtensibleWireProcessor implements RuntimeWireProcessor {
+
+ private RuntimeWireProcessorExtensionPoint processors;
+
+ public ExtensibleWireProcessor(RuntimeWireProcessorExtensionPoint processors) {
+ this.processors = processors;
+ }
+
+ public void process(RuntimeWire wire) {
+ for (RuntimeWireProcessor processor : processors.getWireProcessors()) {
+ processor.process(wire);
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java
new file mode 100644
index 0000000000..c26501e7d7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/InvocationChainImpl.java
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.invocation;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.ListIterator;
+
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.DataExchangeSemantics;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Phase;
+
+/**
+ * Default implementation of an invocation chain
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvocationChainImpl implements InvocationChain {
+ private Operation sourceOperation;
+ private Operation targetOperation;
+ private List<Node> nodes = new ArrayList<Node>();
+
+ // FIXME: Not a good practice to use static reference
+ private static final PhaseManager phaseManager = new PhaseManager();
+ private boolean forReference;
+ private boolean allowsPassByReference;
+
+ public InvocationChainImpl(Operation sourceOperation, Operation targetOperation, boolean forReference) {
+ assert sourceOperation != null;
+ assert targetOperation != null;
+ this.targetOperation = targetOperation;
+ this.sourceOperation = sourceOperation;
+ this.forReference = forReference;
+ }
+
+ public Operation getTargetOperation() {
+ return targetOperation;
+ }
+
+ public void setTargetOperation(Operation operation) {
+ this.targetOperation = operation;
+ }
+
+ public void addInterceptor(Interceptor interceptor) {
+ String phase = forReference ? Phase.REFERENCE : Phase.SERVICE;
+ addInterceptor(phase, interceptor);
+ }
+
+ public void addInvoker(Invoker invoker) {
+ String phase = forReference ? Phase.REFERENCE_BINDING : Phase.IMPLEMENTATION;
+ addInvoker(phase, invoker);
+ }
+
+ public Invoker getHeadInvoker() {
+ return nodes.isEmpty() ? null : nodes.get(0).getInvoker();
+ }
+
+ public Invoker getTailInvoker() {
+ return nodes.isEmpty() ? null : nodes.get(nodes.size() - 1).getInvoker();
+ }
+
+ /**
+ * @return the sourceOperation
+ */
+ public Operation getSourceOperation() {
+ return sourceOperation;
+ }
+
+ /**
+ * @param sourceOperation the sourceOperation to set
+ */
+ public void setSourceOperation(Operation sourceOperation) {
+ this.sourceOperation = sourceOperation;
+ }
+
+ public void addInterceptor(int index, Interceptor interceptor) {
+ addInterceptor(interceptor);
+ }
+
+ public void addInterceptor(String phase, Interceptor interceptor) {
+ addInvoker(phase, interceptor);
+ }
+
+ private void addInvoker(String phase, Invoker invoker) {
+ int index = phaseManager.getAllPhases().indexOf(phase);
+ if (index == -1) {
+ throw new IllegalArgumentException("Invalid phase name: " + phase);
+ }
+ Node node = new Node(index, invoker);
+ ListIterator<Node> li = nodes.listIterator();
+ Node before = null, after = null;
+ boolean found = false;
+ while (li.hasNext()) {
+ before = after;
+ after = li.next();
+ if (after.getPhaseIndex() > index) {
+ // Move back
+ li.previous();
+ li.add(node);
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ // Add to the end
+ nodes.add(node);
+ before = after;
+ after = null;
+ }
+
+ // Relink the interceptors
+ if (before != null) {
+ if (before.getInvoker() instanceof Interceptor) {
+ ((Interceptor)before.getInvoker()).setNext(invoker);
+ }
+ }
+ if (after != null) {
+ if (invoker instanceof Interceptor) {
+ ((Interceptor)invoker).setNext(after.getInvoker());
+ }
+ }
+
+ }
+
+ public boolean allowsPassByReference() {
+ if (allowsPassByReference) {
+ // No need to check the invokers
+ return true;
+ }
+ // Check if any of the invokers allows pass-by-reference
+ boolean allowsPBR = false;
+ for (Node i : nodes) {
+ if (i.getInvoker() instanceof DataExchangeSemantics) {
+ if (((DataExchangeSemantics)i.getInvoker()).allowsPassByReference()) {
+ allowsPBR = true;
+ break;
+ }
+ }
+ }
+ return allowsPBR;
+ }
+
+ public void setAllowsPassByReference(boolean allowsPBR) {
+ this.allowsPassByReference = allowsPBR;
+ }
+
+ private static class Node {
+ private int phaseIndex;
+ private Invoker invoker;
+
+ public Node(int phaseIndex, Invoker invoker) {
+ super();
+ this.phaseIndex = phaseIndex;
+ this.invoker = invoker;
+ }
+
+ public int getPhaseIndex() {
+ return phaseIndex;
+ }
+
+ public Invoker getInvoker() {
+ return invoker;
+ }
+
+ @Override
+ public String toString() {
+ return "(" + phaseIndex + ")" + invoker;
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java
new file mode 100644
index 0000000000..cade0499d3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKCallbackInvocationHandler.java
@@ -0,0 +1,110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.invocation;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.sca.core.assembly.RuntimeWireImpl;
+import org.apache.tuscany.sca.core.context.CallableReferenceImpl;
+import org.apache.tuscany.sca.core.conversation.ConversationState;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.NoRegisteredCallbackException;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * Responsible for dispatching to a callback through a wire. <p/> TODO cache
+ * target invoker
+ *
+ * @version $Rev$ $Date$
+ */
+public class JDKCallbackInvocationHandler extends JDKInvocationHandler {
+ private static final long serialVersionUID = -3350283555825935609L;
+
+ public JDKCallbackInvocationHandler(MessageFactory messageFactory, CallbackReferenceImpl ref) {
+ super(messageFactory, ref);
+ this.fixedWire = false;
+ }
+
+ @Override
+ @SuppressWarnings( {"unchecked"})
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ if (Object.class == method.getDeclaringClass()) {
+ return invokeObjectMethod(method, args);
+ }
+
+ // obtain a dedicated wire to be used for this callback invocation
+ RuntimeWire wire = ((CallbackReferenceImpl)callableReference).getCallbackWire();
+ if (wire == null) {
+ //FIXME: need better exception
+ throw new ServiceRuntimeException("No callback wire found");
+ }
+
+ // set the conversational state based on the interface that
+ // is specified for the reference that this wire belongs to
+ initConversational(wire);
+
+ // set the conversation id into the conversation object. This is
+ // a special case for callbacks as, unless otherwise set manually,
+ // the callback should use the same conversation id as was received
+ // on the incoming call to this component
+ if (conversational) {
+
+ if (conversation == null || conversation.getState() == ConversationState.ENDED) {
+ conversation = null;
+ }
+ Object convID = conversation == null ? null : conversation.getConversationID();
+
+ // create a conversation id if one doesn't exist
+ // already, i.e. the conversation is just starting
+ if (convID == null) {
+ convID = ((CallbackReferenceImpl)callableReference).getConvID();
+ if (convID != null) {
+ conversation = ((RuntimeWireImpl)wire).getConversationManager().getConversation(convID);
+ if (callableReference != null) {
+ ((CallableReferenceImpl)callableReference).attachConversation(conversation);
+ }
+ }
+ }
+ }
+
+ setEndpoint(((CallbackReferenceImpl)callableReference).getResolvedEndpoint());
+
+ InvocationChain chain = getInvocationChain(method, wire);
+ if (chain == null) {
+ throw new IllegalArgumentException("No matching operation is found: " + method);
+ }
+
+ try {
+ return invoke(chain, args, wire, wire.getSource());
+ } catch (InvocationTargetException e) {
+ Throwable t = e.getCause();
+ if (t instanceof NoRegisteredCallbackException) {
+ throw t;
+ }
+ throw e;
+ } finally {
+ // allow the cloned wire to be reused by subsequent callbacks
+ ((RuntimeWireImpl)wire).releaseWire();
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java
new file mode 100644
index 0000000000..a23b9af9ad
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKInvocationHandler.java
@@ -0,0 +1,516 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.invocation;
+
+import java.io.Serializable;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+
+import org.apache.tuscany.sca.core.assembly.RuntimeWireImpl;
+import org.apache.tuscany.sca.core.context.CallableReferenceImpl;
+import org.apache.tuscany.sca.core.context.InstanceWrapper;
+import org.apache.tuscany.sca.core.conversation.ConversationManager;
+import org.apache.tuscany.sca.core.conversation.ConversationState;
+import org.apache.tuscany.sca.core.conversation.ExtendedConversation;
+import org.apache.tuscany.sca.core.scope.Scope;
+import org.apache.tuscany.sca.core.scope.ScopeContainer;
+import org.apache.tuscany.sca.core.scope.ScopedRuntimeComponent;
+import org.apache.tuscany.sca.core.scope.TargetDestructionException;
+import org.apache.tuscany.sca.core.scope.TargetResolutionException;
+import org.apache.tuscany.sca.interfacedef.ConversationSequence;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.JavaOperation;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.apache.tuscany.sca.runtime.ReferenceParameters;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ConversationEndedException;
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JDKInvocationHandler implements InvocationHandler, Serializable {
+ private static final long serialVersionUID = -3366410500152201371L;
+
+ protected boolean conversational;
+ protected ExtendedConversation conversation;
+ protected MessageFactory messageFactory;
+ protected EndpointReference source;
+ protected EndpointReference target;
+ protected RuntimeWire wire;
+ protected CallableReference<?> callableReference;
+ protected Class<?> businessInterface;
+
+ protected boolean fixedWire = true;
+
+ protected transient Map<Method, InvocationChain> chains = new HashMap<Method, InvocationChain>();
+
+ public JDKInvocationHandler(MessageFactory messageFactory, Class<?> businessInterface, RuntimeWire wire) {
+ this.messageFactory = messageFactory;
+ this.wire = wire;
+ this.businessInterface = businessInterface;
+ init(this.wire);
+ }
+
+ public JDKInvocationHandler(MessageFactory messageFactory, CallableReference<?> callableReference) {
+ this.messageFactory = messageFactory;
+ this.callableReference = callableReference;
+ if (callableReference != null) {
+ this.businessInterface = callableReference.getBusinessInterface();
+ this.conversation = (ExtendedConversation)callableReference.getConversation();
+ this.wire = ((CallableReferenceImpl<?>)callableReference).getRuntimeWire();
+ if (wire != null) {
+ init(wire);
+ }
+ }
+ }
+
+ protected void init(RuntimeWire wire) {
+ if (wire != null) {
+ try {
+ // Clone the endpoint reference so that reference parameters can be changed
+ source = (EndpointReference)wire.getSource().clone();
+ } catch (CloneNotSupportedException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ initConversational(wire);
+ }
+ }
+
+ protected void initConversational(RuntimeWire wire) {
+ InterfaceContract contract = wire.getSource().getInterfaceContract();
+ this.conversational = contract.getInterface().isConversational();
+ }
+
+ protected Object getCallbackID() {
+ if (callableReference != null) {
+ return callableReference.getCallbackID();
+ } else {
+ return null;
+ }
+ }
+
+ protected Object getConversationID() {
+ if (callableReference != null && callableReference instanceof ServiceReference) {
+ return ((ServiceReference)callableReference).getConversationID();
+ } else {
+ return null;
+ }
+ }
+
+ protected Object getCallbackObject() {
+ if (callableReference != null && callableReference instanceof ServiceReference) {
+ return ((ServiceReference)callableReference).getCallback();
+ } else {
+ return null;
+ }
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
+ if (Object.class == method.getDeclaringClass()) {
+ return invokeObjectMethod(method, args);
+ }
+ if (wire == null) {
+ throw new ServiceRuntimeException("No runtime wire is available");
+ }
+ InvocationChain chain = getInvocationChain(method, wire);
+ if (chain == null) {
+ throw new IllegalArgumentException("No matching operation is found: " + method);
+ }
+
+ // send the invocation down the wire
+ Object result = invoke(chain, args, wire, source);
+
+ return result;
+ }
+
+ /**
+ * Handle the methods on the Object.class
+ * @param method
+ * @param args
+ */
+ protected Object invokeObjectMethod(Method method, Object[] args) throws Throwable {
+ String name = method.getName();
+ if ("toString".equals(name)) {
+ return "[Proxy - " + toString() + "]";
+ } else if ("equals".equals(name)) {
+ Object obj = args[0];
+ if (obj == null) {
+ return false;
+ }
+ if (!Proxy.isProxyClass(obj.getClass())) {
+ return false;
+ }
+ return equals(Proxy.getInvocationHandler(obj));
+ } else if ("hashCode".equals(name)) {
+ return hashCode();
+ } else {
+ return method.invoke(this);
+ }
+ }
+
+ /**
+ * Determines if the given operation matches the given method
+ *
+ * @return true if the operation matches, false if does not
+ */
+ // FIXME: Should it be in the InterfaceContractMapper?
+ @SuppressWarnings("unchecked")
+ private static boolean match(Operation operation, Method method) {
+ if (operation instanceof JavaOperation) {
+ JavaOperation javaOp = (JavaOperation)operation;
+ Method m = javaOp.getJavaMethod();
+ if (!method.getName().equals(m.getName())) {
+ return false;
+ }
+ if (method.equals(m)) {
+ return true;
+ }
+ } else {
+ if (!method.getName().equals(operation.getName())) {
+ return false;
+ }
+ }
+
+ // For remotable interface, operation is not overloaded.
+ if (operation.getInterface().isRemotable()) {
+ return true;
+ }
+
+ Class<?>[] params = method.getParameterTypes();
+
+ DataType<List<DataType>> inputType = null;
+ if (operation.isWrapperStyle()) {
+ inputType = operation.getWrapper().getUnwrappedInputType();
+ } else {
+ inputType = operation.getInputType();
+ }
+ List<DataType> types = inputType.getLogical();
+ boolean matched = true;
+ if (types.size() == params.length && method.getName().equals(operation.getName())) {
+ for (int i = 0; i < params.length; i++) {
+ Class<?> clazz = params[i];
+ Class<?> type = types.get(i).getPhysical();
+ // Object.class.isAssignableFrom(int.class) returns false
+ if (type != Object.class && (!type.isAssignableFrom(clazz))) {
+ matched = false;
+ }
+ }
+ } else {
+ matched = false;
+ }
+ return matched;
+
+ }
+
+ protected synchronized InvocationChain getInvocationChain(Method method, RuntimeWire wire) {
+ if (fixedWire && chains.containsKey(method)) {
+ return chains.get(method);
+ }
+ InvocationChain found = null;
+ for (InvocationChain chain : wire.getInvocationChains()) {
+ Operation operation = chain.getSourceOperation();
+ if (operation.isDynamic()) {
+ operation.setName(method.getName());
+ found = chain;
+ break;
+ } else if (match(operation, method)) {
+ found = chain;
+ break;
+ }
+ }
+ if (fixedWire) {
+ chains.put(method, found);
+ }
+ return found;
+ }
+
+ protected void setEndpoint(EndpointReference endpoint) {
+ this.target = endpoint;
+ }
+
+ protected Object invoke(InvocationChain chain, Object[] args, RuntimeWire wire, EndpointReference source)
+ throws Throwable {
+ Message msg = messageFactory.createMessage();
+ msg.setFrom(source);
+ if (target != null) {
+ msg.setTo(target);
+ } else {
+ msg.setTo(wire.getTarget());
+ }
+ Invoker headInvoker = chain.getHeadInvoker();
+ Operation operation = chain.getTargetOperation();
+ msg.setOperation(operation);
+ msg.setBody(args);
+
+ Message msgContext = ThreadMessageContext.getMessageContext();
+ Object currentConversationID = msgContext.getFrom().getReferenceParameters().getConversationID();
+
+ conversationPreinvoke(msg, wire);
+ handleCallback(msg, wire, currentConversationID);
+ ThreadMessageContext.setMessageContext(msg);
+ boolean abnormalEndConversation = false;
+ try {
+ // dispatch the wire down the chain and get the response
+ Message resp = headInvoker.invoke(msg);
+ Object body = resp.getBody();
+ if (resp.isFault()) {
+ // mark the conversation as ended if the exception is not a business exception
+ if (currentConversationID != null ){
+ try {
+ boolean businessException = false;
+
+ for (DataType dataType : operation.getFaultTypes()){
+ if (dataType.getPhysical() == ((Throwable)body).getClass()){
+ businessException = true;
+ break;
+ }
+ }
+
+ if (businessException == false){
+ abnormalEndConversation = true;
+ }
+ } catch (Exception ex){
+ // TODO - sure what the best course of action is here. We have
+ // a system exception in the middle of a business exception
+ }
+ }
+ throw (Throwable)body;
+ }
+ return body;
+ } finally {
+ conversationPostInvoke(msg, wire, abnormalEndConversation);
+ ThreadMessageContext.setMessageContext(msgContext);
+ }
+ }
+
+ /**
+ * @param msg
+ * @param wire
+ * @param interfaze
+ * @throws TargetResolutionException
+ */
+ private void handleCallback(Message msg, RuntimeWire wire, Object currentConversationID)
+ throws TargetResolutionException {
+ ReferenceParameters parameters = msg.getFrom().getReferenceParameters();
+ parameters.setCallbackID(getCallbackID());
+ if (msg.getFrom() == null || msg.getFrom().getCallbackEndpoint() == null) {
+ return;
+ }
+
+ parameters.setCallbackReference(msg.getFrom().getCallbackEndpoint());
+
+ // If we are passing out a callback target
+ // register the calling component instance against this
+ // new conversation id so that stateful callbacks will be
+ // able to find it
+ Object callbackObject = getCallbackObject();
+ if (conversational && callbackObject == null) {
+ // the component instance is already registered
+ // so add another registration
+ ScopeContainer<Object> scopeContainer = getConversationalScopeContainer(wire);
+
+ if (scopeContainer != null && currentConversationID != null) {
+ scopeContainer.addWrapperReference(currentConversationID, conversation.getConversationID());
+ }
+ }
+
+ Interface interfaze = msg.getFrom().getCallbackEndpoint().getInterfaceContract().getInterface();
+ if (callbackObject != null) {
+ if (callbackObject instanceof ServiceReference) {
+ EndpointReference callbackRef = ((CallableReferenceImpl)callbackObject).getEndpointReference();
+ parameters.setCallbackReference(callbackRef);
+ } else {
+ if (interfaze != null) {
+ if (!interfaze.isConversational()) {
+ throw new IllegalArgumentException(
+ "Callback object for stateless callback is not a ServiceReference");
+ } else {
+ if (!(callbackObject instanceof Serializable)) {
+ throw new IllegalArgumentException(
+ "Callback object for stateful callback is not Serializable");
+ }
+ ScopeContainer scopeContainer = getConversationalScopeContainer(wire);
+ if (scopeContainer != null) {
+ InstanceWrapper wrapper = new CallbackObjectWrapper(callbackObject);
+ scopeContainer.registerWrapper(wrapper, conversation.getConversationID());
+ }
+ parameters.setCallbackObjectID(callbackObject);
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Pre-invoke for the conversation handling
+ * @param msg
+ * @throws TargetResolutionException
+ */
+ private void conversationPreinvoke(Message msg, RuntimeWire wire) {
+ if (!conversational) {
+ // Not conversational or the conversation has been started
+ return;
+ }
+
+ ConversationManager conversationManager = ((RuntimeWireImpl)wire).getConversationManager();
+
+ if (conversation == null || conversation.getState() == ConversationState.ENDED) {
+
+ conversation = conversationManager.startConversation(getConversationID());
+
+ // if this is a local wire then set up the conversation timeouts here based on the
+ // parameters from the component
+ if (wire.getTarget().getComponent() != null){
+ conversation.initializeConversationAttributes(wire.getTarget().getComponent());
+ }
+
+ // connect the conversation to the CallableReference so it can be retrieve in the future
+ if (callableReference != null) {
+ ((CallableReferenceImpl)callableReference).attachConversation(conversation);
+ }
+ } else if (conversation.isExpired()) {
+ throw new ConversationEndedException("Conversation " + conversation.getConversationID() + " has expired.");
+ }
+
+ // if this is a local wire then schedule conversation timeouts based on the timeout
+ // parameters from the service implementation. If this isn't a local wire then
+ // the RuntimeWireInvoker will take care of this
+ if (wire.getTarget().getComponent() != null){
+ conversation.updateLastReferencedTime();
+ }
+
+ msg.getFrom().getReferenceParameters().setConversationID(conversation.getConversationID());
+
+ }
+
+ /**
+ * Post-invoke for the conversation handling
+ * @param wire
+ * @param operation
+ * @throws TargetDestructionException
+ */
+ @SuppressWarnings("unchecked")
+ private void conversationPostInvoke(Message msg, RuntimeWire wire, boolean abnormalEndConversation)
+ throws TargetDestructionException {
+ Operation operation = msg.getOperation();
+ ConversationSequence sequence = operation.getConversationSequence();
+ // We check that conversation has not already ended as there is only one
+ // conversation manager in the runtime and so, in the case of remote bindings,
+ // the conversation will already have been stopped when we get back to the client
+ if ((sequence == ConversationSequence.CONVERSATION_END || abnormalEndConversation) &&
+ (conversation.getState() != ConversationState.ENDED)) {
+
+ // remove conversation id from scope container
+ ScopeContainer scopeContainer = getConversationalScopeContainer(wire);
+
+ if (scopeContainer != null) {
+ scopeContainer.remove(conversation.getConversationID());
+ }
+
+ conversation.end();
+ }
+ }
+
+ private ScopeContainer<Object> getConversationalScopeContainer(RuntimeWire wire) {
+ ScopeContainer<Object> scopeContainer = null;
+
+ RuntimeComponent runtimeComponent = wire.getSource().getComponent();
+
+ if (runtimeComponent instanceof ScopedRuntimeComponent) {
+ ScopedRuntimeComponent scopedRuntimeComponent = (ScopedRuntimeComponent)runtimeComponent;
+ ScopeContainer<Object> tmpScopeContainer = scopedRuntimeComponent.getScopeContainer();
+
+ if ((tmpScopeContainer != null) && (tmpScopeContainer.getScope() == Scope.CONVERSATION)) {
+ scopeContainer = tmpScopeContainer;
+ }
+ }
+
+ return scopeContainer;
+ }
+
+ /**
+ * Creates a new conversation id
+ *
+ * @return the conversation id
+ */
+ private Object createConversationID() {
+ if (getConversationID() != null) {
+ return getConversationID();
+ } else {
+ return UUID.randomUUID().toString();
+ }
+ }
+
+ /**
+ * @return the callableReference
+ */
+ public CallableReference<?> getCallableReference() {
+ return callableReference;
+ }
+
+ /**
+ * @param callableReference the callableReference to set
+ */
+ public void setCallableReference(CallableReference<?> callableReference) {
+ this.callableReference = callableReference;
+ }
+
+ /**
+ * Minimal wrapper for a callback object contained in a ServiceReference
+ */
+ private static class CallbackObjectWrapper<T> implements InstanceWrapper<T> {
+
+ private T instance;
+
+ private CallbackObjectWrapper(T instance) {
+ this.instance = instance;
+ }
+
+ public T getInstance() {
+ return instance;
+ }
+
+ public void start() {
+ // do nothing
+ }
+
+ public void stop() {
+ // do nothing
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyFactory.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyFactory.java
new file mode 100644
index 0000000000..0992638318
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/JDKProxyFactory.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.invocation;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Proxy;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.List;
+
+import org.apache.tuscany.sca.core.context.CallableReferenceImpl;
+import org.apache.tuscany.sca.core.context.ServiceReferenceImpl;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ServiceReference;
+
+/**
+ * the default implementation of a wire service that uses JDK dynamic proxies
+ *
+ * @version $Rev$ $Date$
+ */
+public class JDKProxyFactory implements ProxyFactory {
+ protected InterfaceContractMapper contractMapper;
+ private MessageFactory messageFactory;
+
+ public JDKProxyFactory(MessageFactory messageFactory, InterfaceContractMapper mapper) {
+ this.contractMapper = mapper;
+ this.messageFactory = messageFactory;
+ }
+
+ /**
+ * The original createProxy method assumes that the proxy doesn't want to
+ * share conversation state so sets the conversation object to null
+ */
+ public <T> T createProxy(Class<T> interfaze, RuntimeWire wire) throws ProxyCreationException {
+ ServiceReference<T> serviceReference = new ServiceReferenceImpl(interfaze, wire, this);
+ return createProxy(serviceReference);
+ }
+
+ public <T> T createProxy(CallableReference<T> callableReference) throws ProxyCreationException {
+ assert callableReference != null;
+ final Class<T> interfaze = callableReference.getBusinessInterface();
+ InvocationHandler handler = new JDKInvocationHandler(messageFactory, callableReference);
+ // Allow privileged access to class loader. Requires RuntimePermission in security policy.
+ ClassLoader cl = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+ public ClassLoader run() {
+ return interfaze.getClassLoader();
+ }
+ });
+ Object proxy = Proxy.newProxyInstance(cl, new Class[] {interfaze}, handler);
+ ((CallableReferenceImpl)callableReference).setProxy(proxy);
+ return interfaze.cast(proxy);
+ }
+
+ public <T> T createCallbackProxy(Class<T> interfaze, List<RuntimeWire> wires) throws ProxyCreationException {
+ CallbackReferenceImpl<T> callbackReference = CallbackReferenceImpl.newInstance(interfaze, this, wires);
+ return callbackReference != null ? createCallbackProxy(callbackReference) : null;
+ }
+
+ public <T> T createCallbackProxy(CallbackReferenceImpl<T> callbackReference) throws ProxyCreationException {
+ assert callbackReference != null;
+ Class<T> interfaze = callbackReference.getBusinessInterface();
+ InvocationHandler handler = new JDKCallbackInvocationHandler(messageFactory, callbackReference);
+ ClassLoader cl = interfaze.getClassLoader();
+ Object proxy = Proxy.newProxyInstance(cl, new Class[] {interfaze}, handler);
+ callbackReference.setProxy(proxy);
+ return interfaze.cast(proxy);
+ }
+
+ public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+ InvocationHandler handler = Proxy.getInvocationHandler(target);
+ if (handler instanceof JDKInvocationHandler) {
+ return (R)((JDKInvocationHandler)handler).getCallableReference();
+ } else {
+ throw new IllegalArgumentException("The object is not a known proxy.");
+ }
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.core.invocation.ProxyFactory#isProxyClass(java.lang.Class)
+ */
+ public boolean isProxyClass(Class<?> clazz) {
+ return Proxy.isProxyClass(clazz);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageFactoryImpl.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageFactoryImpl.java
new file mode 100644
index 0000000000..6e182a6a14
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageFactoryImpl.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.invocation;
+
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+
+/**
+ * Implementation of MessageFactory.
+ *
+ * @version $Rev$ $Date$
+ */
+public class MessageFactoryImpl implements MessageFactory {
+
+ public Message createMessage() {
+ return new MessageImpl();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java
new file mode 100644
index 0000000000..7d7fc583c3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/MessageImpl.java
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.invocation;
+
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+
+/**
+ * The default implementation of a message flowed through a wire during an invocation
+ *
+ * @version $Rev $Date$
+ */
+public class MessageImpl implements Message {
+ private Map<String, Object> header = new Hashtable<String, Object>();
+ private Object body;
+ private Object messageID;
+ private boolean isFault;
+ private Operation operation;
+ private Map<String, Object> qosContext = new Hashtable<String, Object>();
+
+ private EndpointReference from;
+ private EndpointReference to;
+
+ public MessageImpl() {
+ this.from = new EndpointReferenceImpl("/");
+ this.to = new EndpointReferenceImpl("/");
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T> T getBody() {
+ return (T)body;
+ }
+
+ public <T> void setBody(T body) {
+ this.isFault = false;
+ this.body = body;
+ }
+
+ public Object getMessageID() {
+ return messageID;
+ }
+
+ public void setMessageID(Object messageId) {
+ this.messageID = messageId;
+ }
+
+ public boolean isFault() {
+ return isFault;
+ }
+
+ public void setFaultBody(Object fault) {
+ this.isFault = true;
+ this.body = fault;
+ }
+
+ public EndpointReference getFrom() {
+ return from;
+ }
+
+ public void setFrom(EndpointReference from) {
+ this.from = from;
+ }
+
+ public EndpointReference getTo() {
+ return to;
+ }
+
+ public void setTo(EndpointReference to) {
+ this.to = to;
+ }
+
+ public Operation getOperation() {
+ return operation;
+ }
+
+ public void setOperation(Operation op) {
+ this.operation = op;
+ }
+
+ public Map<String, Object> getQoSContext() {
+ return qosContext;
+ }
+
+ public Map<String, Object> getHeader() {
+ return qosContext;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NoMethodForOperationException.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NoMethodForOperationException.java
new file mode 100644
index 0000000000..733544d387
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NoMethodForOperationException.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.invocation;
+
+
+/**
+ * Thrown when an {@link org.apache.tuscany.sca.core.factory.model.Operation} cannot be mapped to a method on an interface
+ * @version $Rev$ $Date$
+ */
+public class NoMethodForOperationException extends ProxyCreationException {
+ private static final long serialVersionUID = 5116536602309483679L;
+
+ public NoMethodForOperationException() {
+ }
+
+ public NoMethodForOperationException(String message) {
+ super(message);
+ }
+
+ public NoMethodForOperationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public NoMethodForOperationException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.java
new file mode 100644
index 0000000000..60f90fb6b5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/NonBlockingInterceptor.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.core.invocation;
+
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.apache.tuscany.sca.work.WorkScheduler;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * Adds non-blocking behavior to an invocation chain
+ *
+ * @version $Rev$ $Date$
+ */
+public class NonBlockingInterceptor implements Interceptor {
+
+ private static final Message RESPONSE = new ImmutableMessage();
+
+ /**
+ * The JDK logger that will be used to log messages.
+ */
+ private static final Logger LOGGER = Logger.getLogger(NonBlockingInterceptor.class.getName());
+
+ private WorkScheduler workScheduler;
+ private Invoker next;
+
+ public NonBlockingInterceptor(WorkScheduler workScheduler) {
+ this.workScheduler = workScheduler;
+ }
+
+ public NonBlockingInterceptor(WorkScheduler workScheduler, Interceptor next) {
+ this.workScheduler = workScheduler;
+ this.next = next;
+ }
+
+ /**
+ * Sets desired workScheduler to NonBlockingInterceptor. This is a useful function for the extension framework
+ * to set desired workmanager on the InvocationChain, other than default workmanager which is set per Tuscany runtime.
+ * Using this function, extension framework can set desired workmanager on InvocationChain during post wire processing.
+ * @param workScheduler workScheduler which contains workmanager
+ */
+ public void setWorkScheduler(WorkScheduler workScheduler){
+ this.workScheduler = workScheduler;
+ }
+
+ public Message invoke(final Message msg) {
+ // Schedule the invocation of the next interceptor in a new Work instance
+ try {
+ workScheduler.scheduleWork(new Runnable() {
+ public void run() {
+ Message context = ThreadMessageContext.setMessageContext(msg);
+ try {
+ Message response = null;
+
+ Throwable ex = null;
+ try {
+ response = next.invoke(msg);
+ } catch (Throwable t) {
+ ex = t;
+ }
+
+ // Tuscany-2225 - Did the @OneWay method complete successfully?
+ // (i.e. no exceptions)
+ if (response != null && response.isFault()) {
+ // The @OneWay method threw an Exception. Lets log it and
+ // then pass it on to the WorkScheduler so it can notify any
+ // listeners
+ ex = (Throwable)response.getBody();
+ }
+ if (ex != null) {
+ LOGGER.log(Level.SEVERE, "Exception from @OneWay invocation", ex);
+ throw new ServiceRuntimeException("Exception from @OneWay invocation", ex);
+ }
+ } finally {
+ ThreadMessageContext.setMessageContext(context);
+ }
+ }
+ });
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ return RESPONSE;
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ /**
+ * A dummy message passed back on an invocation
+ */
+ private static class ImmutableMessage implements Message {
+
+ @SuppressWarnings("unchecked")
+ public Object getBody() {
+ return null;
+ }
+
+ public void setBody(Object body) {
+ if (body != null) {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ public void setCallbackWires(LinkedList<RuntimeWire> wires) {
+
+ }
+
+ public Object getMessageID() {
+ return null;
+ }
+
+ public void setMessageID(Object messageId) {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean isFault() {
+ return false;
+ }
+
+ public void setFaultBody(Object fault) {
+ throw new UnsupportedOperationException();
+ }
+
+ public EndpointReference getFrom() {
+ return null;
+ }
+
+ public EndpointReference getTo() {
+ return null;
+ }
+
+ public void setFrom(EndpointReference from) {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setTo(EndpointReference to) {
+ throw new UnsupportedOperationException();
+ }
+
+ public Operation getOperation() {
+ return null;
+ }
+
+ public void setOperation(Operation op) {
+ throw new UnsupportedOperationException();
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.invocation.Message#getReplyTo()
+ */
+ public EndpointReference getReplyTo() {
+ return null;
+ }
+
+ public Map<String, Object> getQoSContext() {
+ return null;
+ }
+
+ public Map<String, Object> getHeader() {
+ return null;
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseManager.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseManager.java
new file mode 100644
index 0000000000..94d67bffcc
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseManager.java
@@ -0,0 +1,248 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.invocation;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PhaseManager {
+ private static final Logger log = Logger.getLogger(PhaseManager.class.getName());
+
+ public static final String STAGE_REFERENCE = "reference";
+ public static final String STAGE_SERVICE = "service";
+ public static final String STAGE_IMPLEMENTATION = "implementation";
+ private static final String[] SYSTEM_REFERENCE_PHASES =
+ {Phase.REFERENCE, Phase.REFERENCE_INTERFACE, Phase.REFERENCE_POLICY, Phase.REFERENCE_BINDING};
+
+ private static final String[] SYSTEM_SERVICE_PHASES =
+ {Phase.SERVICE_BINDING, Phase.SERVICE_POLICY, Phase.SERVICE_INTERFACE, Phase.SERVICE};
+
+ private static final String[] SYSTEM_IMPLEMENTATION_PHASES = {Phase.IMPLEMENTATION_POLICY, Phase.IMPLEMENTATION};
+
+ private String pattern = Phase.class.getName();
+ private Map<String, Stage> stages;
+ private List<String> phases;
+
+ public class Stage {
+ private String name;
+ private PhaseSorter<String> sorter = new PhaseSorter<String>();
+ private Set<String> firstSet = new HashSet<String>();
+ private Set<String> lastSet = new HashSet<String>();
+ private List<String> phases = new ArrayList<String>();
+
+ public Stage(String name) {
+ super();
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public PhaseSorter<String> getSorter() {
+ return sorter;
+ }
+
+ public Set<String> getFirstSet() {
+ return firstSet;
+ }
+
+ public Set<String> getLastSet() {
+ return lastSet;
+ }
+
+ public List<String> getPhases() {
+ return phases;
+ }
+
+ @Override
+ public String toString() {
+ return name + phases;
+ }
+ }
+
+ // For unit test purpose
+ PhaseManager(String pattern) {
+ super();
+ this.pattern = pattern;
+ }
+
+ public PhaseManager() {
+ }
+
+ private List<String> getPhases(String stage) {
+ Stage s = getStages().get(stage);
+ return s == null ? null : s.getPhases();
+ }
+
+ public List<String> getReferencePhases() {
+ return getPhases(STAGE_REFERENCE);
+ }
+
+ public List<String> getServicePhases() {
+ return getPhases(STAGE_SERVICE);
+ }
+
+ public List<String> getImplementationPhases() {
+ return getPhases(STAGE_IMPLEMENTATION);
+ }
+
+ public synchronized List<String> getAllPhases() {
+ if (phases == null) {
+ phases = new ArrayList<String>();
+ phases.addAll(getReferencePhases());
+ phases.addAll(getServicePhases());
+ phases.addAll(getImplementationPhases());
+ }
+ return phases;
+ }
+
+ public synchronized Map<String, Stage> getStages() {
+ if (stages != null) {
+ return stages;
+ }
+ init();
+
+ Set<ServiceDeclaration> services;
+ try {
+ services = ServiceDiscovery.getInstance().getServiceDeclarations(pattern);
+ } catch (IOException e) {
+ throw new ServiceRuntimeException(e);
+ }
+
+ for (ServiceDeclaration d : services) {
+ if (log.isLoggable(Level.FINE)) {
+ log.fine(d.getLocation() + ": " + d.getAttributes());
+ }
+ String name = d.getAttributes().get("name");
+ if (name == null) {
+ throw new ServiceRuntimeException("Required attribute 'name' is missing.");
+ }
+ String stageName = d.getAttributes().get("stage");
+ if (stageName == null) {
+ throw new ServiceRuntimeException("Required attribute 'stage' is missing.");
+ }
+ Stage stage = stages.get(stageName);
+ if (stage == null) {
+ throw new ServiceRuntimeException("Invalid stage: " + stage);
+ }
+ PhaseSorter<String> graph = stage.getSorter();
+ Set<String> firstSet = stage.getFirstSet(), lastSet = stage.getLastSet();
+
+ String before = d.getAttributes().get("before");
+ String after = d.getAttributes().get("after");
+ if (before != null) {
+ StringTokenizer tokenizer = new StringTokenizer(before);
+ while (tokenizer.hasMoreTokens()) {
+ String p = tokenizer.nextToken();
+ if (!"*".equals(p)) {
+ graph.addEdge(name, p);
+ } else {
+ firstSet.add(name);
+ }
+ }
+ }
+ if (after != null) {
+ StringTokenizer tokenizer = new StringTokenizer(after);
+ while (tokenizer.hasMoreTokens()) {
+ String p = tokenizer.nextToken();
+ if (!"*".equals(p)) {
+ graph.addEdge(p, name);
+ } else {
+ lastSet.add(name);
+ }
+ }
+ }
+ graph.addVertext(name);
+ if(firstSet.size()>1) {
+ log.warning("More than one phases are declared to be first: "+firstSet);
+ }
+ for (String s : firstSet) {
+ for (String v : new HashSet<String>(graph.getVertices().keySet())) {
+ if (!firstSet.contains(v)) {
+ graph.addEdge(s, v);
+ }
+ }
+ }
+ if(lastSet.size()>1) {
+ log.warning("More than one phases are declared to be the last: "+lastSet);
+ }
+ for (String s : lastSet) {
+ for (String v : new HashSet<String>(graph.getVertices().keySet())) {
+ if (!lastSet.contains(v)) {
+ graph.addEdge(v, s);
+ }
+ }
+ }
+
+ }
+
+ for (Stage s : stages.values()) {
+ List<String> phases = s.getSorter().topologicalSort(false);
+ s.getPhases().clear();
+ s.getPhases().addAll(phases);
+ }
+ if (log.isLoggable(Level.FINE)) {
+ log.fine("Stages: " + stages);
+ }
+ return stages;
+ }
+
+ private void init() {
+ stages = new HashMap<String, Stage>();
+
+ Stage referenceStage = new Stage(STAGE_REFERENCE);
+ for (int i = 1; i < SYSTEM_REFERENCE_PHASES.length; i++) {
+ referenceStage.getSorter().addEdge(SYSTEM_REFERENCE_PHASES[i - 1], SYSTEM_REFERENCE_PHASES[i]);
+ }
+ referenceStage.getLastSet().add(Phase.REFERENCE_BINDING);
+ stages.put(referenceStage.getName(), referenceStage);
+
+ Stage serviceStage = new Stage(STAGE_SERVICE);
+ for (int i = 1; i < SYSTEM_SERVICE_PHASES.length; i++) {
+ serviceStage.getSorter().addEdge(SYSTEM_SERVICE_PHASES[i - 1], SYSTEM_SERVICE_PHASES[i]);
+ }
+ stages.put(serviceStage.getName(), serviceStage);
+
+ Stage implementationStage = new Stage(STAGE_IMPLEMENTATION);
+ for (int i = 1; i < SYSTEM_IMPLEMENTATION_PHASES.length; i++) {
+ implementationStage.getSorter().addEdge(SYSTEM_IMPLEMENTATION_PHASES[i - 1],
+ SYSTEM_IMPLEMENTATION_PHASES[i]);
+ }
+ implementationStage.getLastSet().add(Phase.IMPLEMENTATION);
+ stages.put(implementationStage.getName(), implementationStage);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseSorter.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseSorter.java
new file mode 100644
index 0000000000..fc4bea3d9f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/PhaseSorter.java
@@ -0,0 +1,236 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.invocation;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Directed, weighted graph
+ *
+ * @param <V> The type of vertex object
+ * @param <E> The type of edge object
+ *
+ * @version $Rev$ $Date$
+ */
+public class PhaseSorter<V> implements Cloneable {
+ private final Map<V, Vertex> vertices = new HashMap<V, Vertex>();
+
+ /**
+ * 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 Map<Vertex, Edge> inEdges = new HashMap<Vertex, Edge>();
+
+ private Vertex(V value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return "(" + value + ")";
+ }
+
+ public V getValue() {
+ return value;
+ }
+
+ public Map<Vertex, Edge> getOutEdges() {
+ return outEdges;
+ }
+
+ public Map<Vertex, Edge> getInEdges() {
+ return inEdges;
+ }
+
+ }
+
+ /**
+ * An Edge connects two vertices in one direction
+ */
+ public final class Edge {
+ private Vertex sourceVertex;
+
+ private Vertex targetVertex;
+
+ public Edge(Vertex source, Vertex target) {
+ this.sourceVertex = source;
+ this.targetVertex = target;
+ }
+
+ @Override
+ public String toString() {
+ return sourceVertex + "->" + targetVertex;
+ }
+
+ public Vertex getTargetVertex() {
+ return targetVertex;
+ }
+
+ public void setTargetVertex(Vertex vertex) {
+ this.targetVertex = vertex;
+ }
+
+ public Vertex getSourceVertex() {
+ return sourceVertex;
+ }
+
+ public void setSourceVertex(Vertex sourceVertex) {
+ this.sourceVertex = sourceVertex;
+ }
+ }
+
+ public void addEdge(V source, V target) {
+ Vertex s = getVertex(source);
+ if (s == null) {
+ s = new Vertex(source);
+ vertices.put(source, s);
+ }
+ Vertex t = getVertex(target);
+ if (t == null) {
+ t = new Vertex(target);
+ vertices.put(target, t);
+ }
+ Edge edge = new Edge(s, t);
+ s.outEdges.put(t, edge);
+ t.inEdges.put(s, edge);
+ }
+
+ public void addVertext(V source) {
+ Vertex s = getVertex(source);
+ if (s == null) {
+ s = new Vertex(source);
+ vertices.put(source, s);
+ }
+ }
+
+ public Vertex getVertex(V source) {
+ Vertex s = vertices.get(source);
+ return s;
+ }
+
+ public boolean removeEdge(V source, V target) {
+ Vertex s = getVertex(source);
+ if (s == null) {
+ return false;
+ }
+
+ Vertex t = getVertex(target);
+ if (t == null) {
+ return false;
+ }
+
+ return s.outEdges.remove(t) != null && t.inEdges.remove(s) != null;
+
+ }
+
+ public void removeEdge(Edge edge) {
+ edge.sourceVertex.outEdges.remove(edge.targetVertex);
+ edge.targetVertex.inEdges.remove(edge.sourceVertex);
+ }
+
+ public void removeVertex(Vertex vertex) {
+ vertices.remove(vertex.getValue());
+ for (Edge e : new ArrayList<Edge>(vertex.outEdges.values())) {
+ removeEdge(e);
+ }
+ for (Edge e : new ArrayList<Edge>(vertex.inEdges.values())) {
+ removeEdge(e);
+ }
+ }
+
+ public Edge getEdge(Vertex source, Vertex target) {
+ return source.outEdges.get(target);
+ }
+
+ public Edge getEdge(V source, V target) {
+ Vertex sv = getVertex(source);
+ if (sv == null) {
+ return null;
+ }
+ Vertex tv = getVertex(target);
+ if (tv == null) {
+ return null;
+ }
+ return getEdge(getVertex(source), getVertex(target));
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ for (Vertex v : vertices.values()) {
+ sb.append(v.outEdges.values()).append("\n");
+ }
+ return sb.toString();
+ }
+
+ public Map<V, Vertex> getVertices() {
+ return vertices;
+ }
+
+ public void addGraph(PhaseSorter<V> otherGraph) {
+ for (Vertex v : otherGraph.vertices.values()) {
+ for (Edge e : v.outEdges.values()) {
+ addEdge(e.sourceVertex.value, e.targetVertex.value);
+ }
+ }
+ }
+
+ private Vertex getFirst() {
+ for (Vertex v : vertices.values()) {
+ if (v.inEdges.isEmpty()) {
+ return v;
+ }
+ }
+ if (!vertices.isEmpty()) {
+ throw new IllegalArgumentException("Circular ordering has been detected: " + toString());
+ } else {
+ return null;
+ }
+ }
+
+ public List<V> topologicalSort(boolean readOnly) {
+ PhaseSorter<V> graph = (!readOnly) ? this : (PhaseSorter<V>)clone();
+ List<V> list = new ArrayList<V>();
+ while (true) {
+ Vertex v = graph.getFirst();
+ if (v == null) {
+ break;
+ }
+ list.add(v.getValue());
+ graph.removeVertex(v);
+ }
+
+ return list;
+ }
+
+ @Override
+ public Object clone() {
+ PhaseSorter<V> copy = new PhaseSorter<V>();
+ copy.addGraph(this);
+ return copy;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyCreationException.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyCreationException.java
new file mode 100644
index 0000000000..0b36b178f3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyCreationException.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.invocation;
+
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+
+
+/**
+ * Denotes an error creating a proxy
+ *
+ * @version $Rev$ $Date$
+ */
+public class ProxyCreationException extends ObjectCreationException {
+ private static final long serialVersionUID = 8002454344828513781L;
+
+ public ProxyCreationException() {
+ super();
+ }
+
+ public ProxyCreationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ProxyCreationException(String message) {
+ super(message);
+ }
+
+ public ProxyCreationException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java
new file mode 100644
index 0000000000..cb836e42c1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactory.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.invocation;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.CallableReference;
+
+/**
+ * Creates proxies that implement Java interfaces and invocation handlers for fronting wires
+ *
+ * @version $Rev$ $Date$
+ */
+
+public interface ProxyFactory {
+
+ /**
+ * Creates a Java proxy for the given wire
+ *
+ * @param interfaze the interface the proxy implements
+ * @param wire the wire to proxy
+ * @return the proxy
+ * @throws ProxyCreationException
+ */
+ <T> T createProxy(Class<T> interfaze, RuntimeWire wire) throws ProxyCreationException;
+
+ /**
+ * Creates a Java proxy for the given CallableReference
+ *
+ * @param callableReference The CallableReference
+ * @return the proxy
+ * @throws ProxyCreationException
+ */
+ <T> T createProxy(CallableReference<T> callableReference) throws ProxyCreationException;
+
+ /**
+ * Creates a Java proxy for the service contract callback
+ *
+ * @param interfaze the interface the proxy should implement
+ * @return the proxy
+ * @throws ProxyCreationException
+ */
+ <T> T createCallbackProxy(Class<T> interfaze, List<RuntimeWire> wires) throws ProxyCreationException;
+
+ /**
+ * Creates a Java proxy for the given callback reference
+ *
+ * @param callableReference The CallableReference
+ * @return the proxy
+ * @throws ProxyCreationException
+ */
+ <T> T createCallbackProxy(CallbackReferenceImpl<T> callbackReference) throws ProxyCreationException;
+
+ /**
+ * Cast a proxy to a CallableReference.
+ *
+ * @param target a proxy generated by this implementation
+ * @return a CallableReference (or subclass) equivalent to this proxy
+ * @throws IllegalArgumentException if the object supplied is not a proxy
+ */
+ <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException;
+
+ /**
+ * Test if a given class is a generated proxy class by this factory
+ * @param clazz A java class or interface
+ * @return true if the class is a generated proxy class by this factory
+ */
+ boolean isProxyClass(Class<?> clazz);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactoryExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactoryExtensionPoint.java
new file mode 100644
index 0000000000..875a252798
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ProxyFactoryExtensionPoint.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.invocation;
+
+
+/**
+ * The extension point to plug in proxy factories
+ * @version $Rev$ $Date$
+ */
+public interface ProxyFactoryExtensionPoint {
+
+ /**
+ * Get the proxy factory for java interfaces
+ * @return
+ */
+ ProxyFactory getInterfaceProxyFactory();
+
+ /**
+ * Get the proxy factory for java classes
+ * @return
+ */
+ ProxyFactory getClassProxyFactory();
+
+ /**
+ * Set the proxy factory for java interfaces
+ * @param factory
+ */
+ void setInterfaceProxyFactory(ProxyFactory factory);
+
+ /**
+ * Set the proxy factory for java classes
+ * @param factory
+ */
+ void setClassProxyFactory(ProxyFactory factory);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java
new file mode 100644
index 0000000000..c007669bdf
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/RuntimeWireInvoker.java
@@ -0,0 +1,245 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.invocation;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.tuscany.sca.core.context.InstanceWrapper;
+import org.apache.tuscany.sca.core.conversation.ConversationManager;
+import org.apache.tuscany.sca.core.conversation.ConversationState;
+import org.apache.tuscany.sca.core.conversation.ExtendedConversation;
+import org.apache.tuscany.sca.core.scope.Scope;
+import org.apache.tuscany.sca.core.scope.ScopeContainer;
+import org.apache.tuscany.sca.core.scope.ScopedRuntimeComponent;
+import org.apache.tuscany.sca.core.scope.TargetDestructionException;
+import org.apache.tuscany.sca.core.scope.TargetResolutionException;
+import org.apache.tuscany.sca.interfacedef.ConversationSequence;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.apache.tuscany.sca.runtime.ReferenceParameters;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.ConversationEndedException;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class RuntimeWireInvoker {
+ protected ConversationManager conversationManager;
+ protected boolean conversational;
+ protected ExtendedConversation conversation;
+ protected MessageFactory messageFactory;
+ protected Object conversationID;
+ protected Object callbackID;
+ protected Object callbackObject;
+ protected RuntimeWire wire;
+
+ public RuntimeWireInvoker(MessageFactory messageFactory, ConversationManager conversationManager, RuntimeWire wire) {
+ this.messageFactory = messageFactory;
+ this.wire = wire;
+ this.conversationManager = conversationManager;
+ init(wire);
+ }
+
+ protected void init(RuntimeWire wire) {
+ if (wire != null) {
+ ReferenceParameters parameters = wire.getSource().getReferenceParameters();
+ this.callbackID = parameters.getCallbackID();
+ this.callbackObject = parameters.getCallbackReference();
+ this.conversationID = parameters.getConversationID();
+ InterfaceContract contract = wire.getSource().getInterfaceContract();
+ this.conversational = contract.getInterface().isConversational();
+ }
+ }
+
+ public Object invoke(Operation operation, Message msg) throws InvocationTargetException {
+ return invoke(wire, operation, msg);
+ }
+
+ public Object invoke(RuntimeWire wire, Operation operation, Message msg) throws InvocationTargetException {
+ RuntimeWire runtimeWire = wire == null ? this.wire : wire;
+ InvocationChain chain = runtimeWire.getInvocationChain(operation);
+ return invoke(chain, msg, runtimeWire);
+ }
+
+ protected Object invoke(InvocationChain chain, Message msg, RuntimeWire wire) throws InvocationTargetException {
+ EndpointReference from = msg.getFrom();
+ EndpointReference epFrom = wire.getSource();
+ if (from != null) {
+ from.mergeEndpoint(epFrom);
+ } else {
+ msg.setFrom(epFrom);
+ }
+ msg.setTo(wire.getTarget());
+
+ Invoker headInvoker = chain.getHeadInvoker();
+ Operation operation = chain.getTargetOperation();
+ msg.setOperation(operation);
+
+ Message msgContext = ThreadMessageContext.getMessageContext();
+ Object currentConversationID = msgContext.getFrom().getReferenceParameters().getConversationID();
+
+ ThreadMessageContext.setMessageContext(msg);
+ try {
+ conversationPreinvoke(msg);
+ // handleCallback(msg, currentConversationID);
+ // dispatch the wire down the chain and get the response
+ Message resp = headInvoker.invoke(msg);
+ Object body = resp.getBody();
+ if (resp.isFault()) {
+ throw new InvocationTargetException((Throwable)body);
+ }
+ return body;
+ } catch (InvocationTargetException e) {
+ throw e;
+ } catch (Throwable e) {
+ throw new ServiceRuntimeException(e);
+ } finally {
+ try {
+ conversationPostInvoke(msg);
+ } catch (TargetDestructionException e) {
+ throw new ServiceRuntimeException(e);
+ } finally {
+ ThreadMessageContext.setMessageContext(msgContext);
+ }
+ }
+ }
+
+ /**
+ * @param msgContext
+ */
+ protected EndpointReference getCallbackEndpoint(Message msgContext) {
+ EndpointReference from = msgContext.getFrom();
+ return from == null ? null : from.getReferenceParameters().getCallbackReference();
+ }
+
+ /**
+ * Pre-invoke for the conversation handling
+ * @param msg
+ * @throws TargetResolutionException
+ */
+ private void conversationPreinvoke(Message msg) {
+ if (conversational) {
+ ReferenceParameters parameters = msg.getFrom().getReferenceParameters();
+ // in some cases the ConversationID that should be used comes in with the
+ // message, e.g. when ws binding is in use.
+ Object convID = parameters.getConversationID();
+ if (convID != null) {
+ conversationID = convID;
+ }
+ conversation = conversationManager.getConversation(conversationID);
+
+ if (conversation == null || conversation.getState() == ConversationState.ENDED) {
+ conversation = conversationManager.startConversation(conversationID);
+ conversation.initializeConversationAttributes(wire.getTarget().getComponent());
+ } else if (conversation.conversationalAttributesInitialized() == false) {
+ conversation.initializeConversationAttributes(wire.getTarget().getComponent());
+ } else if (conversation.isExpired()){
+ throw new ConversationEndedException("Conversation has expired.");
+ }
+
+ conversation.updateLastReferencedTime();
+
+ parameters.setConversationID(conversation.getConversationID());
+ }
+ }
+
+ /**
+ * Post-invoke for the conversation handling
+ * @param wire
+ * @param operation
+ * @throws TargetDestructionException
+ */
+ @SuppressWarnings("unchecked")
+ private void conversationPostInvoke(Message msg) throws TargetDestructionException {
+ if (conversational) {
+ Operation operation = msg.getOperation();
+ ConversationSequence sequence = operation.getConversationSequence();
+ if (sequence == ConversationSequence.CONVERSATION_END) {
+ // in some cases the ConversationID that should be used comes in with the
+ // message, e.g. when ws binding is in use.
+ Object convID = msg.getFrom().getReferenceParameters().getConversationID();
+ if (convID != null) {
+ conversationID = convID;
+ }
+ conversation = conversationManager.getConversation(conversationID);
+
+ // remove conversation id from scope container
+ ScopeContainer scopeContainer = getConversationalScopeContainer(msg);
+
+ if (scopeContainer != null) {
+ scopeContainer.remove(conversation.getConversationID());
+ }
+
+ conversation.end();
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private ScopeContainer getConversationalScopeContainer(Message msg) {
+ ScopeContainer scopeContainer = null;
+
+ RuntimeComponent component = msg.getTo().getComponent();
+
+ if (component instanceof ScopedRuntimeComponent) {
+ ScopedRuntimeComponent scopedRuntimeComponent = (ScopedRuntimeComponent)component;
+ ScopeContainer container = scopedRuntimeComponent.getScopeContainer();
+
+ if ((container != null) && (container.getScope() == Scope.CONVERSATION)) {
+ scopeContainer = container;
+ }
+ }
+
+ return scopeContainer;
+ }
+
+
+ /**
+ * Minimal wrapper for a callback object contained in a ServiceReference
+ */
+ private static class CallbackObjectWrapper<T> implements InstanceWrapper<T> {
+
+ private T instance;
+
+ private CallbackObjectWrapper(T instance) {
+ this.instance = instance;
+ }
+
+ public T getInstance() {
+ return instance;
+ }
+
+ public void start() {
+ // do nothing
+ }
+
+ public void stop() {
+ // do nothing
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/TargetInvocationException.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/TargetInvocationException.java
new file mode 100644
index 0000000000..2c4d657882
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/TargetInvocationException.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.invocation;
+
+/**
+ * Raised when an error is encountered during a target invocation
+ *
+ * @version $Rev$ $Date$
+ */
+public class TargetInvocationException extends Exception {
+
+ private static final long serialVersionUID = -6553427708442761743L;
+
+ public TargetInvocationException() {
+ super();
+ }
+
+ public TargetInvocationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public TargetInvocationException(String message) {
+ super(message);
+ }
+
+ public TargetInvocationException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java
new file mode 100644
index 0000000000..504bd9b036
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/ThreadMessageContext.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.invocation;
+
+import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl;
+import org.apache.tuscany.sca.invocation.Message;
+
+/**
+ * Class for tunnelling a WorkContext through the invocation of a user class.
+ *
+ * @version $Rev$ $Date$
+ */
+public final class ThreadMessageContext {
+
+ private static final ThreadLocal<Message> CONTEXT = new ThreadLocal<Message>() {
+ @Override
+ protected synchronized Message initialValue() {
+ Message msg = new MessageImpl();
+ msg.setFrom(new EndpointReferenceImpl("/"));
+ return msg;
+ }
+ };
+
+ private ThreadMessageContext() {
+ }
+
+ /**
+ * Set the WorkContext for the current thread.
+ * The current work context is returned and must be restored after the invocation is complete.
+ * Typical usage would be:
+ * <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 Message setMessageContext(Message context) {
+ Message old = CONTEXT.get();
+ CONTEXT.set(context);
+ return old;
+ }
+
+ /**
+ * Returns the WorkContext for the current thread.
+ *
+ * @return the WorkContext for the current thread
+ */
+ public static Message getMessageContext() {
+ return CONTEXT.get();
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.java
new file mode 100644
index 0000000000..246f9c45d6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/invocation/WireObjectFactory.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.invocation;
+
+import org.apache.tuscany.sca.core.context.ServiceReferenceImpl;
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+
+/**
+ * Uses a wire to return an object instance
+ *
+ * @version $Rev$ $Date$
+ */
+public class WireObjectFactory<T> implements ObjectFactory<T> {
+ private Class<T> interfaze;
+ private RuntimeWire wire;
+ private ProxyFactory proxyService;
+
+ /**
+ * Constructor.
+ *
+ * @param interfaze the interface to inject on the client
+ * @param wire the backing wire
+ * @param proxyService the wire service to create the proxy
+ * @throws NoMethodForOperationException
+ */
+ public WireObjectFactory(Class<T> interfaze, RuntimeWire wire, ProxyFactory proxyService) {
+ this.interfaze = interfaze;
+ this.wire = wire;
+ this.proxyService = proxyService;
+ }
+
+ public T getInstance() throws ObjectCreationException {
+ return new ServiceReferenceImpl<T>(interfaze, wire, proxyService).getProxy();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java
new file mode 100644
index 0000000000..1168d1d0dd
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainer.java
@@ -0,0 +1,200 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.scope;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.tuscany.sca.core.context.InstanceWrapper;
+import org.apache.tuscany.sca.event.Event;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * Implements functionality common to scope contexts.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractScopeContainer<KEY> implements ScopeContainer<KEY> {
+ protected Map<KEY, InstanceWrapper<?>> wrappers = new ConcurrentHashMap<KEY, InstanceWrapper<?>>();
+ protected final Scope scope;
+
+ protected RuntimeComponent component;
+ protected volatile int lifecycleState = UNINITIALIZED;
+
+
+ public AbstractScopeContainer(Scope scope, RuntimeComponent component) {
+ this.scope = scope;
+ this.component = component;
+ }
+
+ protected void checkInit() {
+ if (getLifecycleState() != RUNNING) {
+ throw new IllegalStateException("Scope container not running [" + getLifecycleState() + "]");
+ }
+ }
+
+ /**
+ * Creates a new physical instance of a component, wrapped in an
+ * InstanceWrapper.
+ *
+ * @param component the component whose instance should be created
+ * @return a wrapped instance that has been injected but not yet started
+ * @throws TargetResolutionException if there was a problem creating the
+ * instance
+ */
+ protected InstanceWrapper createInstanceWrapper() throws TargetResolutionException {
+ ImplementationProvider implementationProvider = component.getImplementationProvider();
+ if (implementationProvider instanceof ScopedImplementationProvider) {
+ return ((ScopedImplementationProvider)implementationProvider).createInstanceWrapper();
+ }
+ return null;
+ }
+
+ public InstanceWrapper getAssociatedWrapper(KEY contextId) throws TargetResolutionException {
+ return getWrapper(contextId); // TODO: what is this method supposed to do diff than getWrapper?
+ }
+
+ public Scope getScope() {
+ return scope;
+ }
+
+ public InstanceWrapper getWrapper(KEY contextId) throws TargetResolutionException {
+ return wrappers.get(contextId);
+ }
+
+ public void addWrapperReference(KEY existingContextId, KEY newContextId)
+ throws TargetResolutionException {
+ // do nothing here. the conversational scope container implements this
+ }
+
+ public void registerWrapper(InstanceWrapper wrapper, KEY contextId) throws TargetResolutionException {
+ // do nothing here. the conversational scope container implements this
+ }
+
+ public void onEvent(Event event) {
+ }
+
+ protected boolean isEagerInit() {
+ ImplementationProvider implementationProvider = ((RuntimeComponent)component).getImplementationProvider();
+ if (implementationProvider instanceof ScopedImplementationProvider) {
+ return ((ScopedImplementationProvider)implementationProvider).isEagerInit();
+ }
+ return false;
+ }
+
+ public void returnWrapper(InstanceWrapper wrapper, KEY contextId) throws TargetDestructionException {
+ }
+
+ /**
+ * Default implementation of remove which does nothing
+ *
+ * @param contextId the identifier of the context to remove.
+ */
+ public void remove(KEY contextId)
+ throws TargetDestructionException {
+ }
+
+ public synchronized void start() {
+ int lifecycleState = getLifecycleState();
+ if (lifecycleState != UNINITIALIZED && lifecycleState != STOPPED) {
+ throw new IllegalStateException("Scope must be in UNINITIALIZED or STOPPED state [" + lifecycleState + "]");
+ }
+ setLifecycleState(RUNNING);
+ }
+
+ public void startContext(KEY contextId) {
+ if(isEagerInit()) {
+ try {
+ getWrapper(contextId);
+ } catch (TargetResolutionException e) {
+ //
+ }
+ }
+ }
+
+ public synchronized void stop() {
+ int lifecycleState = getLifecycleState();
+ if (lifecycleState != RUNNING) {
+ throw new IllegalStateException("Scope in wrong state [" + lifecycleState + "]");
+ }
+ setLifecycleState(STOPPED);
+ }
+
+ public void stopContext(KEY contextId) {
+ wrappers.remove(contextId);
+ }
+
+ @Override
+ public String toString() {
+ String s;
+ switch (lifecycleState) {
+ case ScopeContainer.CONFIG_ERROR:
+ s = "CONFIG_ERROR";
+ break;
+ case ScopeContainer.ERROR:
+ s = "ERROR";
+ break;
+ case ScopeContainer.INITIALIZING:
+ s = "INITIALIZING";
+ break;
+ case ScopeContainer.INITIALIZED:
+ s = "INITIALIZED";
+ break;
+ case ScopeContainer.RUNNING:
+ s = "RUNNING";
+ break;
+ case ScopeContainer.STOPPING:
+ s = "STOPPING";
+ break;
+ case ScopeContainer.STOPPED:
+ s = "STOPPED";
+ break;
+ case ScopeContainer.UNINITIALIZED:
+ s = "UNINITIALIZED";
+ break;
+ default:
+ s = "UNKNOWN";
+ break;
+ }
+ return "In state [" + s + ']';
+ }
+
+ public RuntimeComponent getComponent() {
+ return component;
+ }
+
+ public void setComponent(RuntimeComponent component) {
+ this.component = component;
+ }
+
+ public int getLifecycleState() {
+ return lifecycleState;
+ }
+
+ /**
+ * Set the current state of the Lifecycle.
+ *
+ * @param lifecycleState the new state
+ */
+ protected void setLifecycleState(int lifecycleState) {
+ this.lifecycleState = lifecycleState;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java
new file mode 100644
index 0000000000..7e7ab7a9e4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainer.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.scope;
+
+import org.apache.tuscany.sca.core.context.InstanceWrapper;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * A scope context which manages atomic component instances keyed by composite
+ *
+ * @version $Rev$ $Date$
+ */
+public class CompositeScopeContainer<KEY> extends AbstractScopeContainer<KEY> {
+ private InstanceWrapper<?> wrapper;
+
+ public CompositeScopeContainer(RuntimeComponent component) {
+ super(Scope.COMPOSITE, component);
+ }
+
+ @Override
+ public synchronized void stop() {
+ super.stop();
+ if (wrapper != null) {
+ try {
+ wrapper.stop();
+ } catch (TargetDestructionException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ wrapper = null;
+ }
+
+ @Override
+ public synchronized InstanceWrapper getWrapper(KEY contextId) throws TargetResolutionException {
+ if (wrapper == null) {
+ wrapper = createInstanceWrapper();
+ wrapper.start();
+ }
+ return wrapper;
+ }
+
+ @Override
+ public InstanceWrapper getAssociatedWrapper(KEY contextId) throws TargetResolutionException {
+ if (wrapper == null) {
+ throw new TargetNotFoundException(component.getURI());
+ }
+ return wrapper;
+ }
+
+ @Override
+ public synchronized void start() {
+ super.start();
+ if (isEagerInit()) {
+ try {
+ getWrapper(null);
+ } catch (TargetResolutionException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainerFactory.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainerFactory.java
new file mode 100644
index 0000000000..786988613b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/CompositeScopeContainerFactory.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.scope;
+
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CompositeScopeContainerFactory implements ScopeContainerFactory {
+
+ public ScopeContainer createScopeContainer(RuntimeComponent component) {
+ return new CompositeScopeContainer(component);
+ }
+
+ public Scope getScope() {
+ return Scope.COMPOSITE;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java
new file mode 100644
index 0000000000..3ae1ca51c5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainer.java
@@ -0,0 +1,290 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.scope;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.tuscany.sca.core.context.InstanceWrapper;
+import org.apache.tuscany.sca.core.conversation.ConversationListener;
+import org.apache.tuscany.sca.core.conversation.ConversationManager;
+import org.apache.tuscany.sca.core.conversation.ExtendedConversation;
+import org.apache.tuscany.sca.core.invocation.ThreadMessageContext;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.store.Store;
+
+/**
+ * A scope context which manages atomic component instances keyed on ConversationID
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConversationalScopeContainer extends AbstractScopeContainer<Object> implements ConversationListener {
+ private ConversationManager conversationManager;
+ private Map<Object, InstanceLifeCycleWrapper> instanceLifecycleCollection =
+ new ConcurrentHashMap<Object, InstanceLifeCycleWrapper>();
+
+ public ConversationalScopeContainer(Store aStore, RuntimeComponent component) {
+ super(Scope.CONVERSATION, component);
+
+ // Note: aStore is here to preserve the original factory interface. It is not currently used in this
+ // implementation since we do not support instance persistence.
+
+ // Check System properties to see if timeout values have been specified. All timeout values
+ // will be specified in seconds.
+ //
+
+ }
+
+
+ protected InstanceWrapper getInstanceWrapper(boolean create, Object contextId) throws TargetResolutionException {
+
+ // we might get a null context if the target service has
+ // conversational scope but only its callback interface
+ // is conversational. In this case we need to invent a
+ // conversation Id here to store the service against
+ // and populate the thread context
+ if (contextId == null) {
+ contextId = UUID.randomUUID().toString();
+ Message msgContext = ThreadMessageContext.getMessageContext();
+
+ if (msgContext != null) {
+ msgContext.getFrom().getReferenceParameters().setConversationID(contextId);
+ }
+ }
+
+ InstanceLifeCycleWrapper anInstanceWrapper = this.instanceLifecycleCollection.get(contextId);
+
+ if (anInstanceWrapper == null && !create)
+ return null;
+
+ if (anInstanceWrapper == null) {
+ anInstanceWrapper = new InstanceLifeCycleWrapper(contextId);
+ this.instanceLifecycleCollection.put(contextId, anInstanceWrapper);
+ }
+
+ return anInstanceWrapper.getInstanceWrapper(contextId);
+
+ }
+
+ @Override
+ public InstanceWrapper getWrapper(Object contextId) throws TargetResolutionException {
+ return getInstanceWrapper(true, contextId);
+ }
+
+ /**
+ * This method allows a new context id to be registered alongside an existing one. This happens in
+ * one case, when a conversation includes a stateful callback. The client component instance
+ * must be registered against all outgoing conversation ids so that the component instance
+ * can be found when the callback arrives
+ *
+ * @param existingContextId the context id against which the component is already registered
+ * @param context this should be a conversation object so that the conversation can b stored
+ * and reset when the component instance is removed
+ */
+ @Override
+ public void addWrapperReference(Object existingContextId, Object contextId) throws TargetResolutionException {
+
+
+ // get the instance wrapper via the existing id
+ InstanceLifeCycleWrapper existingInstanceWrapper = this.instanceLifecycleCollection.get(existingContextId);
+ InstanceLifeCycleWrapper newInstanceWrapper = this.instanceLifecycleCollection.get(contextId);
+
+ // only add the extra reference once
+ if (newInstanceWrapper == null) {
+ // add the id to the list of ids that the wrapper holds. Used for reference
+ // counting and conversation resetting on destruction.
+ existingInstanceWrapper.addCallbackConversation(contextId);
+
+ // add the reference to the collection
+ this.instanceLifecycleCollection.put(contextId, existingInstanceWrapper);
+ }
+ }
+
+ @Override
+ public void registerWrapper(InstanceWrapper wrapper, Object contextId) throws TargetResolutionException {
+ // if a wrapper for a different instance is already registered for this contextId, remove it
+ InstanceLifeCycleWrapper anInstanceWrapper = this.instanceLifecycleCollection.get(contextId);
+ if (anInstanceWrapper != null) {
+ if (anInstanceWrapper.getInstanceWrapper(contextId).getInstance() != wrapper.getInstance()) {
+ remove(contextId);
+ } else {
+ return;
+ }
+ }
+
+ anInstanceWrapper = new InstanceLifeCycleWrapper(wrapper, contextId);
+ this.instanceLifecycleCollection.put(contextId, anInstanceWrapper);
+ }
+
+ // The remove is invoked when a conversation is explicitly ended. This can occur by using the @EndsConversation or API.
+ // In this case the instance is immediately removed. A new conversation will be started on the next operation
+ // associated with this conversationId's service reference.
+ //
+ @Override
+ public void remove(Object contextId) throws TargetDestructionException {
+ if (contextId != null) {
+ if (this.instanceLifecycleCollection.containsKey(contextId)) {
+ InstanceLifeCycleWrapper anInstanceLifeCycleWrapper = this.instanceLifecycleCollection.get(contextId);
+ this.instanceLifecycleCollection.remove(contextId);
+ anInstanceLifeCycleWrapper.removeInstanceWrapper(contextId);
+ }
+ }
+ }
+
+ /*
+ * This is an inner class that keeps track of the lifecycle of a conversation scoped
+ * implementation instance.
+ *
+ */
+
+ private class InstanceLifeCycleWrapper {
+ private Object clientConversationId;
+ private List<Object> callbackConversations = new ArrayList<Object>();
+
+ private InstanceLifeCycleWrapper(Object contextId) throws TargetResolutionException {
+ this.clientConversationId = contextId;
+ this.createInstance(contextId);
+ }
+
+ private InstanceLifeCycleWrapper(InstanceWrapper wrapper, Object contextId) throws TargetResolutionException {
+ this.clientConversationId = contextId;
+ wrappers.put(contextId, wrapper);
+ }
+
+
+ // Associates a callback conversation with this instance. Each time the scope container
+ // is asked to remove an object given a ontextId an associated conversation object will
+ // have its conversationId reset to null. When the list of ids is empty the component instance
+ // will be removed from the scope container
+ private void addCallbackConversation(Object conversationID) {
+ InstanceWrapper ctx = getInstanceWrapper(clientConversationId);
+ callbackConversations.add(conversationID);
+ wrappers.put(conversationID, ctx);
+ }
+
+ //
+ // Return the backing implementation instance
+ //
+ private InstanceWrapper getInstanceWrapper(Object contextId) {
+ InstanceWrapper ctx = wrappers.get(contextId);
+ return ctx;
+ }
+
+ private void removeInstanceWrapper(Object contextId) throws TargetDestructionException {
+ InstanceWrapper ctx = getInstanceWrapper(contextId);
+ wrappers.remove(contextId);
+
+ // find out if we are dealing with the original client conversation id
+ // and reset accordingly
+ if ( ( clientConversationId != null ) && ( clientConversationId.equals(contextId)) ) {
+ clientConversationId = null;
+ } else {
+ // reset the conversationId in the conversation object if present
+ // so that and ending callback causes the conversation in the originating
+ // service reference in the client to be reset
+ callbackConversations.remove(contextId);
+ }
+
+ // stop the component if this removes the last reference
+ if (clientConversationId == null && callbackConversations.isEmpty()) {
+ ctx.stop();
+ }
+ }
+
+ private void createInstance(Object contextId) throws TargetResolutionException {
+ InstanceWrapper instanceWrapper = createInstanceWrapper();
+ instanceWrapper.start();
+ wrappers.put(contextId, instanceWrapper);
+ }
+
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.core.conversation.ConversationListener#conversationEnded(org.apache.tuscany.sca.core.conversation.ExtendedConversation)
+ */
+ public void conversationEnded(ExtendedConversation conversation) {
+ try {
+ remove(conversation.getConversationID());
+ } catch (Exception ex) {
+
+ }
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.core.conversation.ConversationListener#conversationExpired(org.apache.tuscany.sca.core.conversation.ExtendedConversation)
+ */
+ public void conversationExpired(ExtendedConversation conversation) {
+
+ Object conversationId = conversation.getConversationID();
+ InstanceLifeCycleWrapper ilcw = instanceLifecycleCollection.get(conversationId);
+ if (ilcw != null) {
+ // cycle through all the references to this instance and
+ // remove them from the underlying wrappers collection and
+ // from the lifecycle wrappers collection
+
+ for (Object conversationID : ilcw.callbackConversations) {
+ try{
+ ilcw.removeInstanceWrapper(conversationID);
+ remove(conversationID);
+ } catch(TargetDestructionException tde) {
+ System.out.println("Could not remove conversation id " + conversationID);
+ }
+ }
+
+
+ if (ilcw.clientConversationId != null) {
+ try{
+ ilcw.removeInstanceWrapper(ilcw.clientConversationId);
+ remove(ilcw.clientConversationId);
+ } catch(TargetDestructionException tde) {
+ System.out.println("Could not remove conversation id " + ilcw.clientConversationId);
+ }
+ }
+
+ }
+
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.core.conversation.ConversationListener#conversationStarted(org.apache.tuscany.sca.core.conversation.ExtendedConversation)
+ */
+ public void conversationStarted(ExtendedConversation conversation) {
+ startContext(conversation.getConversationID());
+ }
+
+ /**
+ * @return the conversationManager
+ */
+ public ConversationManager getConversationManager() {
+ return conversationManager;
+ }
+
+ /**
+ * @param conversationManager the conversationManager to set
+ */
+ public void setConversationManager(ConversationManager conversationManager) {
+ this.conversationManager = conversationManager;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainerFactory.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainerFactory.java
new file mode 100644
index 0000000000..a6663aba09
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ConversationalScopeContainerFactory.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.scope;
+
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.store.Store;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConversationalScopeContainerFactory implements ScopeContainerFactory {
+ private Store store;
+
+ public ConversationalScopeContainerFactory(Store store) {
+ super();
+ this.store = store;
+ }
+
+ public ScopeContainer createScopeContainer(RuntimeComponent component) {
+ return new ConversationalScopeContainer(store, component);
+ }
+
+ public Scope getScope() {
+ return Scope.CONVERSATION;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainer.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainer.java
new file mode 100644
index 0000000000..5ae8b94647
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainer.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.scope;
+
+import org.apache.tuscany.sca.core.context.InstanceWrapper;
+import org.apache.tuscany.sca.core.event.HttpSessionEnd;
+import org.apache.tuscany.sca.event.Event;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * A scope context which manages atomic component instances keyed on HTTP
+ * session
+ *
+ * @version $Rev$ $Date$
+ */
+public class HttpSessionScopeContainer extends AbstractScopeContainer<Object> {
+
+ public HttpSessionScopeContainer(RuntimeComponent component) {
+ super(Scope.SESSION, component);
+ }
+
+ @Override
+ public void onEvent(Event event) {
+ checkInit();
+ if (event instanceof HttpSessionEnd) {
+ //FIXME key is not used
+ //Object key = ((HttpSessionEnd)event).getSessionID();
+ // FIXME: Remove the session id
+ }
+ }
+
+ @Override
+ public synchronized void start() {
+ if (lifecycleState != UNINITIALIZED && lifecycleState != STOPPED) {
+ throw new IllegalStateException("Scope must be in UNINITIALIZED or STOPPED state [" + lifecycleState + "]");
+ }
+ lifecycleState = RUNNING;
+ }
+
+ @Override
+ public synchronized void stop() {
+ lifecycleState = STOPPED;
+ }
+
+ protected InstanceWrapper getInstanceWrapper(boolean create) throws TargetResolutionException {
+// Object key = workContext.getIdentifier(Scope.SESSION);
+ // FIXME: Need to fix this
+ Object key ="http-session-id";
+ assert key != null : "HTTP session key not bound in work context";
+ InstanceWrapper ctx = wrappers.get(key);
+ if (ctx == null && !create) {
+ return null;
+ }
+ if (ctx == null) {
+ ctx = super.createInstanceWrapper();
+ ctx.start();
+ wrappers.put(key, ctx);
+ }
+ return ctx;
+ }
+
+ @Override
+ public InstanceWrapper getWrapper(Object contextId) throws TargetResolutionException {
+ return getInstanceWrapper(true);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainerFactory.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainerFactory.java
new file mode 100644
index 0000000000..49f89661b1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/HttpSessionScopeContainerFactory.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.scope;
+
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class HttpSessionScopeContainerFactory implements ScopeContainerFactory {
+
+ public HttpSessionScopeContainerFactory() {
+ super();
+ }
+
+ public ScopeContainer createScopeContainer(RuntimeComponent component) {
+ return new HttpSessionScopeContainer(component);
+ }
+
+ public Scope getScope() {
+ return Scope.SESSION;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.java
new file mode 100644
index 0000000000..f11a61e662
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainer.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.scope;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.tuscany.sca.core.context.InstanceWrapper;
+import org.apache.tuscany.sca.core.event.RequestEnd;
+import org.apache.tuscany.sca.event.Event;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * A scope context which manages atomic component instances keyed on the current
+ * request context
+ *
+ * @version $Rev$ $Date$
+ */
+public class RequestScopeContainer extends AbstractScopeContainer<Thread> {
+ private final Map<Thread, InstanceWrapper> contexts;
+
+ public RequestScopeContainer(RuntimeComponent component) {
+ super(Scope.REQUEST, component);
+ contexts = new ConcurrentHashMap<Thread, InstanceWrapper>();
+ }
+
+ @Override
+ public void onEvent(Event event) {
+ checkInit();
+ if (event instanceof RequestEnd) {
+ // shutdownInstances(Thread.currentThread());
+ }
+ }
+
+ @Override
+ public synchronized void start() {
+ if (lifecycleState != UNINITIALIZED && lifecycleState != STOPPED) {
+ throw new IllegalStateException("Scope must be in UNINITIALIZED or STOPPED state [" + lifecycleState + "]");
+ }
+ lifecycleState = RUNNING;
+ }
+
+ @Override
+ public synchronized void stop() {
+ contexts.clear();
+ // synchronized (destroyQueues) {
+ // destroyQueues.clear();
+ // }
+ lifecycleState = STOPPED;
+ }
+
+ protected InstanceWrapper getInstanceWrapper(boolean create) throws TargetResolutionException {
+ InstanceWrapper ctx = wrappers.get(Thread.currentThread());
+ if (ctx == null && !create) {
+ return null;
+ }
+ if (ctx == null) {
+ ctx = super.createInstanceWrapper();
+ ctx.start();
+ wrappers.put(Thread.currentThread(), ctx);
+ }
+ return ctx;
+ }
+
+ @Override
+ public InstanceWrapper getWrapper(Thread contextId) throws TargetResolutionException {
+ return getInstanceWrapper(true);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainerFactory.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainerFactory.java
new file mode 100644
index 0000000000..1cfb6b06a4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/RequestScopeContainerFactory.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.scope;
+
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class RequestScopeContainerFactory implements ScopeContainerFactory {
+
+ public ScopeContainer createScopeContainer(RuntimeComponent component) {
+ return new RequestScopeContainer(component);
+ }
+
+ public Scope getScope() {
+ return Scope.REQUEST;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/Scope.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/Scope.java
new file mode 100644
index 0000000000..0a20d793f7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/Scope.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.scope;
+
+/**
+ * The default implementation scopes supported by assemblies.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Scope {
+ public static final Scope STATELESS = new Scope("STATELESS");
+ public static final Scope REQUEST = new Scope("REQUEST");
+ public static final Scope SESSION = new Scope("SESSION");
+ public static final Scope CONVERSATION = new Scope("CONVERSATION");
+ public static final Scope COMPOSITE = new Scope("COMPOSITE");
+ public static final Scope SYSTEM = new Scope("SYSTEM");
+ public static final Scope UNDEFINED = new Scope("UNDEFINED");
+
+ private String scope;
+
+ public Scope(String scope) {
+ this.scope = scope.toUpperCase().intern();
+ }
+
+ public String getScope() {
+ return scope;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ final Scope scope1 = (Scope) o;
+ return !(scope != null ? scope != scope1.scope.intern() : scope1.scope != null);
+ }
+
+ @Override
+ public int hashCode() {
+ return scope != null ? scope.hashCode() : 0;
+ }
+
+ @Override
+ public String toString() {
+ return scope;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeContainer.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeContainer.java
new file mode 100644
index 0000000000..6b2980b989
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeContainer.java
@@ -0,0 +1,159 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.scope;
+
+import org.apache.tuscany.sca.core.context.InstanceWrapper;
+import org.apache.tuscany.sca.event.RuntimeEventListener;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+
+/**
+ * Manages the lifecycle and visibility of instances associated with a an {@link RuntimeComponent}.
+ *
+ * @version $Rev$ $Date$
+ * @param <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 RuntimeEventListener {
+
+ /**
+ * Returns the Scope that this container supports.
+ *
+ * @return the Scope that this container supports
+ */
+ Scope getScope();
+
+ /**
+ * Start a new context with the supplied ID.
+ *
+ * @param contextId an ID that uniquely identifies the context.
+ */
+ void startContext(KEY contextId);
+
+ /**
+ * Stop the context with the supplied ID.
+ *
+ * @param contextId an ID that uniquely identifies the context.
+ */
+ void stopContext(KEY contextId);
+
+ /**
+ * Returns an instance wrapper associated with the current scope context, creating one if necessary
+ * @param contextId the id for the scope context
+ *
+ * @return the wrapper for the target instance
+ * @throws TargetResolutionException if there was a problem instantiating the target instance
+ */
+ InstanceWrapper getWrapper(KEY contextId) throws TargetResolutionException;
+
+ /**
+ * Allows a component to be registered against more than one context id. This is required in the
+ * case of stateful callbacks where we want to identify the originating client component instance
+ * as the callback target but we don't want to reuse the clients original conversation id
+ *
+ * @param existingContextId an id that identifies an existing component instance
+ * @param newContextId a new id against which this component will also be registered
+ * @throws TargetResolutionException
+ */
+ void addWrapperReference(KEY existingContextId, KEY newContextId)
+ throws TargetResolutionException;
+
+ /**
+ * Register an existing instance against a context id. This is needed
+ * for a stateful callback where the service reference for the forward call
+ * contains a callback object that is not a service reference.
+ *
+ * @param wrapper the instance wrapper for the instance to be registered
+ * @param contextId the id for the scope context
+ * @throws TargetResolutionException
+ */
+ void registerWrapper(InstanceWrapper wrapper, KEY contextId)
+ throws TargetResolutionException;
+
+ /**
+ * Returns an implementation instance associated with the current scope context.
+ * If no instance is found, a {@link TargetNotFoundException} is thrown.
+ * @param contextId the id for the scope context
+ *
+ * @return the wrapper for the target instance
+ * @throws TargetResolutionException if there was a problem instantiating the target instance
+ */
+ InstanceWrapper getAssociatedWrapper(KEY contextId)
+ throws TargetResolutionException;
+
+ /**
+ * Return a wrapper after use (for example, after invoking the instance).
+ * @param wrapper the wrapper for the target instance being returned
+ * @param contextId the id for the scope context
+ *
+ * @throws TargetDestructionException if there was a problem returning the target instance
+ */
+ void returnWrapper(InstanceWrapper wrapper, KEY contextId)
+ throws TargetDestructionException;
+
+ /**
+ * Removes an identified component implementation instance associated with the current
+ * context from persistent storage
+ *
+ * @param contextId the identifier of the context to remove.
+ */
+ void remove(KEY contextId)
+ throws TargetDestructionException;
+
+ /* A configuration error state */
+ int CONFIG_ERROR = -1;
+ /* Has not been initialized */
+ int UNINITIALIZED = 0;
+ /* In the process of being configured and initialized */
+ int INITIALIZING = 1;
+ /* Instantiated and configured */
+ int INITIALIZED = 2;
+ /* Configured and initialized */
+ int RUNNING = 4;
+ /* In the process of being shutdown */
+ int STOPPING = 5;
+ /* Has been shutdown and removed from the composite */
+ int STOPPED = 6;
+ /* In an error state */
+ int ERROR = 7;
+
+ /**
+ * Returns the lifecycle state
+ *
+ * @see #UNINITIALIZED
+ * @see #INITIALIZING
+ * @see #INITIALIZED
+ * @see #RUNNING
+ * @see #STOPPING
+ * @see #STOPPED
+ */
+ int getLifecycleState();
+
+ /**
+ * Starts the Lifecycle.
+ */
+ void start();
+
+ /**
+ * Stops the Lifecycle.
+ */
+ void stop();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeContainerFactory.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeContainerFactory.java
new file mode 100644
index 0000000000..b19c14b3e0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeContainerFactory.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.scope;
+
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * Factory to create ScopeContainer for components
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ScopeContainerFactory {
+ ScopeContainer createScopeContainer(RuntimeComponent component);
+ Scope getScope();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistry.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistry.java
new file mode 100644
index 0000000000..842ed4c547
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistry.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.scope;
+
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+
+/**
+ * Manages {@link ScopeContainer}s in the runtime
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ScopeRegistry {
+
+ /**
+ * Returns the scope container for the given scope or null if one not found
+ *
+ * @param scope the scope
+ * @return the scope container for the given scope or null if one not found
+ */
+ ScopeContainer getScopeContainer(RuntimeComponent component);
+
+ /**
+ * @param factory
+ */
+ void register(ScopeContainerFactory factory);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistryImpl.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistryImpl.java
new file mode 100644
index 0000000000..75261e11a8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopeRegistryImpl.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.scope;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * The default implementation of a scope registry
+ *
+ * @version $Rev$ $Date$
+ */
+public class ScopeRegistryImpl implements ScopeRegistry {
+ private final Map<Scope, ScopeContainerFactory> scopeCache = new ConcurrentHashMap<Scope, ScopeContainerFactory>();
+
+ public void register(ScopeContainerFactory factory) {
+ scopeCache.put(factory.getScope(), factory);
+ }
+
+ public ScopeContainer getScopeContainer(RuntimeComponent runtimeComponent) {
+ if (!(runtimeComponent instanceof ScopedRuntimeComponent)) {
+ return null;
+ }
+ ScopedRuntimeComponent component = (ScopedRuntimeComponent)runtimeComponent;
+ if (component.getScopeContainer() != null) {
+ return component.getScopeContainer();
+ }
+ ImplementationProvider implementationProvider = component.getImplementationProvider();
+ if (implementationProvider instanceof ScopedImplementationProvider) {
+ ScopedImplementationProvider provider = (ScopedImplementationProvider)implementationProvider;
+ Scope scope = provider.getScope();
+ if (scope == null) {
+ scope = Scope.STATELESS;
+ }
+ ScopeContainerFactory factory = scopeCache.get(scope);
+ ScopeContainer container = factory.createScopeContainer(component);
+ component.setScopeContainer(container);
+ return container;
+ }
+ return null;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopedImplementationProvider.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopedImplementationProvider.java
new file mode 100644
index 0000000000..85a6626cdd
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopedImplementationProvider.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.scope;
+
+import org.apache.tuscany.sca.core.context.InstanceWrapper;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+
+/**
+ * A component implementation can implement this interface to provide scope
+ * management for the components
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ScopedImplementationProvider extends ImplementationProvider {
+ /**
+ * Get the scope for the component implementation
+ *
+ * @return The scope for the component implementation, if null is returned,
+ * STATELESS will be used
+ */
+ Scope getScope();
+
+ /**
+ * Indicate if the component needs to be eagerly initialized
+ *
+ * @return true if the component is marked to be eagerly initialized, false
+ * otherwise
+ */
+ boolean isEagerInit();
+
+ /**
+ * @return the maxAge
+ */
+ long getMaxAge();
+
+ /**
+ * @return the maxIdleTime
+ */
+ long getMaxIdleTime();
+
+ /**
+ * Create a wrapper for the component instance for the scope management
+ *
+ * @return A wrapper for the component instance
+ */
+ InstanceWrapper createInstanceWrapper();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopedRuntimeComponent.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopedRuntimeComponent.java
new file mode 100644
index 0000000000..c27b112f8a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/ScopedRuntimeComponent.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.scope;
+
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * Scoped runtime component
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ScopedRuntimeComponent extends RuntimeComponent {
+ /**
+ * Set the associated scope container
+ * @param scopeContainer
+ */
+ void setScopeContainer(ScopeContainer scopeContainer);
+ /**
+ * Get the assoicated scope container
+ * @return
+ */
+ ScopeContainer getScopeContainer();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.java
new file mode 100644
index 0000000000..a2c0edb9b4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainer.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.scope;
+
+import org.apache.tuscany.sca.core.context.InstanceWrapper;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * A scope context which manages stateless atomic component instances in a non-pooled fashion.
+ *
+ * @version $Rev$ $Date$
+ */
+public class StatelessScopeContainer<KEY> extends AbstractScopeContainer<KEY> {
+
+ public StatelessScopeContainer(RuntimeComponent component) {
+ super(Scope.STATELESS, component);
+ }
+
+ @Override
+ public InstanceWrapper getWrapper(KEY contextId)
+ throws TargetResolutionException {
+ InstanceWrapper ctx = createInstanceWrapper();
+ ctx.start();
+ return ctx;
+ }
+
+ @Override
+ public InstanceWrapper getAssociatedWrapper(KEY contextId)
+ throws TargetResolutionException {
+ return getWrapper(contextId);
+ }
+
+ @Override
+ public void returnWrapper(InstanceWrapper wrapper, KEY contextId)
+ throws TargetDestructionException {
+ wrapper.stop();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainerFactory.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainerFactory.java
new file mode 100644
index 0000000000..0471b2c52e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/StatelessScopeContainerFactory.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.scope;
+
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class StatelessScopeContainerFactory implements ScopeContainerFactory {
+
+ public ScopeContainer createScopeContainer(RuntimeComponent component) {
+ return new StatelessScopeContainer(component);
+ }
+
+ public Scope getScope() {
+ return Scope.STATELESS;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetDestructionException.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetDestructionException.java
new file mode 100644
index 0000000000..0f83dad97d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetDestructionException.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.scope;
+
+/**
+ * Denotes an error destroying a target
+ *
+ * @version $Rev$ $Date$
+ */
+public class TargetDestructionException extends TargetResolutionException {
+ private static final long serialVersionUID = -6126684147851674709L;
+
+ public TargetDestructionException() {
+ super();
+ }
+
+ public TargetDestructionException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public TargetDestructionException(String message) {
+ super(message);
+ }
+
+ public TargetDestructionException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetInitializationException.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetInitializationException.java
new file mode 100644
index 0000000000..15959c0608
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetInitializationException.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.scope;
+
+/**
+ * Denotes an error initializing a target
+ *
+ * @version $Rev$ $Date$
+ */
+public class TargetInitializationException extends TargetResolutionException {
+ private static final long serialVersionUID = -6228778208649752698L;
+
+ public TargetInitializationException() {
+ super();
+ }
+
+ public TargetInitializationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public TargetInitializationException(String message) {
+ super(message);
+ }
+
+ public TargetInitializationException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetNotFoundException.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetNotFoundException.java
new file mode 100644
index 0000000000..bb46a2499b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetNotFoundException.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.scope;
+
+/**
+ * Thrown when a target of an operation cannot be found
+ *
+ * @version $Rev$ $Date$
+ */
+public class TargetNotFoundException extends TargetResolutionException {
+ private static final long serialVersionUID = 5541830480658471186L;
+
+ public TargetNotFoundException() {
+ super();
+ }
+
+ public TargetNotFoundException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public TargetNotFoundException(String message) {
+ super(message);
+ }
+
+ public TargetNotFoundException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetResolutionException.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetResolutionException.java
new file mode 100644
index 0000000000..ea8d0e876c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/scope/TargetResolutionException.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.scope;
+
+/**
+ * Denotes an error retrieving a target instance
+ *
+ * @version $Rev$ $Date$
+ */
+public class TargetResolutionException extends Exception {
+ private static final long serialVersionUID = 2912513650522019405L;
+
+ public TargetResolutionException() {
+ super();
+ }
+
+ public TargetResolutionException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public TargetResolutionException(String message) {
+ super(message);
+ }
+
+ public TargetResolutionException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/store/MemoryStore.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/store/MemoryStore.java
new file mode 100644
index 0000000000..5b838116c5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/store/MemoryStore.java
@@ -0,0 +1,195 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.store;
+
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.tuscany.sca.core.event.BaseEventPublisher;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.store.DuplicateRecordException;
+import org.apache.tuscany.sca.store.RecoveryListener;
+import org.apache.tuscany.sca.store.Store;
+import org.apache.tuscany.sca.store.StoreExpirationEvent;
+import org.apache.tuscany.sca.store.StoreMonitor;
+import org.apache.tuscany.sca.store.StoreWriteException;
+import org.osoa.sca.annotations.Destroy;
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Init;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * Implements a non-durable, non-transactional store using a simple in-memory map
+ *
+ * @version $Rev$ $Date$
+ */
+@Service(Store.class)
+@EagerInit
+public class MemoryStore extends BaseEventPublisher implements Store {
+ private Map<RuntimeComponent, 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(StoreMonitor monitor) {
+ this.monitor = monitor;
+ this.store = new ConcurrentHashMap<RuntimeComponent, 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(RuntimeComponent 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("Duplicate record: " + owner.getURI() +" : " + id);
+ }
+ map.put(id, new Record(object, expiration));
+ }
+
+ public void updateRecord(RuntimeComponent owner, String id, Object object, long expiration) throws StoreWriteException {
+ Map<String, Record> map = store.get(owner);
+ if (map == null) {
+ throw new StoreWriteException("Record not found: " + owner.getURI() +" : " + id);
+ }
+ Record record = map.get(id);
+ if (record == null) {
+ throw new StoreWriteException("Record not found: " + owner.getURI() +" : " + id);
+ }
+ record.data = object;
+ }
+
+ public Object readRecord(RuntimeComponent owner, String id) {
+ Map<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(RuntimeComponent owner, String id) throws StoreWriteException {
+ Map<String, Record> map = store.get(owner);
+ if (map == null) {
+ throw new StoreWriteException("Owner not found: " + owner.getURI() +" : " + id);
+ }
+ if (map.remove(id) == null) {
+ throw new StoreWriteException("Owner not found: " + owner.getURI() +" : " + id);
+ }
+ }
+
+ public void recover(RecoveryListener listener) {
+ throw new UnsupportedOperationException();
+ }
+
+ private class Record {
+ private Object data;
+ private long expiration = NEVER;
+
+ public Record(Object data, long expiration) {
+ this.data = data;
+ this.expiration = expiration;
+ }
+
+ public Object getData() {
+ return data;
+ }
+
+ public long getExpiration() {
+ return expiration;
+ }
+ }
+
+ private class Reaper implements Runnable {
+
+ public void run() {
+ long now = System.currentTimeMillis();
+ for (Map.Entry<RuntimeComponent, 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) {
+ RuntimeComponent owner = entries.getKey();
+ Object instance = entry.getValue().getData();
+ // notify listeners of the expiration
+ StoreExpirationEvent event = new StoreExpirationEvent(this, owner, instance);
+ publish(event);
+ entries.getValue().remove(entry.getKey());
+ }
+ }
+ }
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237Work.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237Work.java
new file mode 100644
index 0000000000..adeb667277
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237Work.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.work;
+
+/**
+ * JCA work wrapper.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Jsr237Work<T extends Runnable> implements commonj.work.Work {
+
+ // Work that is being executed.
+ private T work;
+
+ /*
+ * Initializes the work instance.
+ */
+ public Jsr237Work(T work) {
+ this.work = work;
+ }
+
+ /*
+ * Returns the completed work.
+ */
+ public T getWork() {
+ return work;
+ }
+
+ /*
+ * Release the work.
+ */
+ public void release() {
+ }
+
+ /*
+ * Work attributes are not daemon.
+ */
+ public boolean isDaemon() {
+ return false;
+ }
+
+ /*
+ * Runs the work.
+ */
+ public void run() {
+ work.run();
+ }
+} \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237WorkScheduler.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237WorkScheduler.java
new file mode 100644
index 0000000000..90c13e6da8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/work/Jsr237WorkScheduler.java
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.work;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.apache.tuscany.sca.work.NotificationListener;
+import org.apache.tuscany.sca.work.WorkScheduler;
+import org.apache.tuscany.sca.work.WorkSchedulerException;
+
+import commonj.work.WorkEvent;
+import commonj.work.WorkListener;
+import commonj.work.WorkManager;
+
+/**
+ * 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 implementation available. For example, if the managed environment supports work manager the runtime can use
+ * the appropriate lookup mechanism to inject the work manager implementation. </p>
+ *
+ * @version $Rev$ $Date$
+ */
+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() {
+ }
+
+ private synchronized WorkManager getWorkManager() {
+ if (jsr237WorkManager != null) {
+ return jsr237WorkManager;
+ }
+ try {
+ InitialContext ctx = new InitialContext();
+ jsr237WorkManager = (WorkManager)ctx.lookup("java:comp/env/wm/TuscanyWorkManager");
+ } catch (NamingException e) {
+ // ignore
+ }
+ if (jsr237WorkManager == null) {
+ jsr237WorkManager = new ThreadPoolWorkManager(10);
+ }
+ return jsr237WorkManager;
+ }
+
+ /**
+ * Schedules a unit of work for future execution. The notification listener is used to register interest in
+ * callbacks regarding the status of the work.
+ *
+ * @param work The unit of work that needs to be asynchronously executed.
+ */
+ public <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) {
+ getWorkManager().schedule(jsr237Work);
+ } else {
+ Jsr237WorkListener<T> jsr237WorkListener = new Jsr237WorkListener<T>(listener, work);
+ getWorkManager().schedule(jsr237Work, jsr237WorkListener);
+ }
+ } catch (IllegalArgumentException ex) {
+ if (listener != null) {
+ listener.workRejected(work);
+ } else {
+ throw new WorkSchedulerException(ex);
+ }
+ } catch (Exception ex) {
+ throw new WorkSchedulerException(ex);
+ }
+
+ }
+
+ public void destroy() {
+ if (jsr237WorkManager instanceof ThreadPoolWorkManager) {
+ // Allow privileged access to modify threads. Requires RuntimePermission in security
+ // policy.
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ ((ThreadPoolWorkManager)jsr237WorkManager).destroy();
+ return null;
+ }
+ });
+ }
+ }
+
+ /*
+ * 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;
+ }
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java
new file mode 100644
index 0000000000..fb47a65edf
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManager.java
@@ -0,0 +1,235 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.work;
+
+import java.rmi.server.UID;
+import java.util.Collection;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.RejectedExecutionException;
+import java.util.concurrent.ThreadFactory;
+
+import org.osoa.sca.annotations.Destroy;
+
+import commonj.work.Work;
+import commonj.work.WorkEvent;
+import commonj.work.WorkException;
+import commonj.work.WorkItem;
+import commonj.work.WorkListener;
+import commonj.work.WorkManager;
+
+/**
+ * A thread-pool based implementation for the JSR-237 work manager.
+ * <p/>
+ * <p/>
+ * This implementation supports only local work.
+ * <p/>
+ * TODO Elaborate the implementation. </p>
+ *
+ * @version $Rev$ $Date$
+ */
+public class ThreadPoolWorkManager implements WorkManager {
+
+ // Map of work items currently handled by the work manager
+ private Map<WorkItemImpl, WorkListener> workItems = new ConcurrentHashMap<WorkItemImpl, WorkListener>();
+
+ // Thread-pool
+ private ExecutorService executor;
+
+ /**
+ * Initializes the thread-pool.
+ *
+ * @param threadPoolSize Thread-pool size.
+ * @throws IllegalArgumentException if threadPoolSize < 1
+ */
+ public ThreadPoolWorkManager(int threadPoolSize) {
+ if (threadPoolSize < 1) {
+ throw new IllegalArgumentException("Invalid threadPoolSize of "
+ + threadPoolSize + ". It must be >= 1");
+ }
+
+ // Creates a new Executor, use a custom ThreadFactory that
+ // creates daemon threads.
+ executor = Executors.newFixedThreadPool(threadPoolSize, new ThreadFactory() {
+ public Thread newThread(Runnable r) {
+ Thread thread = new Thread(r);
+ thread.setDaemon(true);
+ return thread;
+ }
+ });
+ }
+
+ /**
+ * Schedules a unit of work asynchronously.
+ *
+ * @param work Work that needs to be scheduled.
+ * @return Work Work item representing the asynchronous work
+ */
+ public WorkItem schedule(Work work) throws IllegalArgumentException {
+ return schedule(work, null);
+ }
+
+ /**
+ * Schedules a unit of work asynchronously.
+ *
+ * @param work Work that needs to be scheduled.
+ * @param workListener Work listener for callbacks.
+ * @return Work Work item representing the asynchronous work
+ */
+ public WorkItem schedule(Work work, WorkListener workListener) throws IllegalArgumentException {
+
+ WorkItemImpl workItem = new WorkItemImpl(new UID().toString(), work);
+ if (workListener != null) {
+ workItems.put(workItem, workListener);
+ }
+ workAccepted(workItem, work);
+ if (scheduleWork(work, workItem)) {
+ return workItem;
+ } else {
+ workItem.setStatus(WorkEvent.WORK_REJECTED);
+ if (workListener != null) {
+ workListener.workRejected(new WorkEventImpl(workItem));
+ }
+ throw new IllegalArgumentException("Unable to schedule work");
+ }
+ }
+
+ /**
+ * Wait for all the specified units of work to finish.
+ *
+ * @param works Units of the work that need to finish.
+ * @param timeout Timeout for waiting for the units of work to finish.
+ */
+ public boolean waitForAll(Collection works, long timeout) {
+ throw new UnsupportedOperationException("waitForAll not supported");
+ }
+
+ /**
+ * Wait for any of the specified units of work to finish.
+ *
+ * @param works Units of the work that need to finish.
+ * @param timeout Timeout for waiting for the units of work to finish.
+ */
+ public Collection waitForAny(Collection works, long timeout) {
+ throw new UnsupportedOperationException("waitForAny not supported");
+ }
+
+ /**
+ * Method provided for subclasses to indicate a work acceptance.
+ *
+ * @param workItem Work item representing the work that was accepted.
+ * @param work Work that was accepted.
+ */
+ private void workAccepted(final WorkItemImpl workItem, final Work work) {
+ WorkListener listener = workItems.get(workItem);
+ if (listener != null) {
+ workItem.setStatus(WorkEvent.WORK_ACCEPTED);
+ WorkEvent event = new WorkEventImpl(workItem);
+ listener.workAccepted(event);
+ }
+ }
+
+ /*
+ * Method to indicate a work start.
+ */
+ private void workStarted(final WorkItemImpl workItem, final Work work) {
+ WorkListener listener = workItems.get(workItem);
+ if (listener != null) {
+ workItem.setStatus(WorkEvent.WORK_STARTED);
+ WorkEvent event = new WorkEventImpl(workItem);
+ listener.workStarted(event);
+ }
+ }
+
+ /*
+ * Method to indicate a work completion.
+ */
+ private void workCompleted(final WorkItemImpl workItem, final Work work) {
+ workCompleted(workItem, work, null);
+ }
+
+ /*
+ * Method to indicate a work completion.
+ */
+ private void workCompleted(final WorkItemImpl workItem, final Work work, final WorkException exception) {
+ WorkListener listener = workItems.get(workItem);
+ if (listener != null) {
+ workItem.setStatus(WorkEvent.WORK_COMPLETED);
+ workItem.setResult(work);
+ workItem.setException(exception);
+ WorkEvent event = new WorkEventImpl(workItem);
+ listener.workCompleted(event);
+ workItems.remove(workItem);
+ }
+ }
+
+ /*
+ * Schedules the work using the ThreadPool.
+ */
+ private boolean scheduleWork(final Work work, final WorkItemImpl workItem) {
+ try {
+ executor.execute(new DecoratingWork(workItem, work));
+ return true;
+ } catch (RejectedExecutionException ex) {
+ return false;
+ }
+ }
+
+ /*
+ * Class that decorates the original worker so that it can get callbacks when work is done.
+ */
+ private final class DecoratingWork implements Runnable {
+
+ // Work item for this work.
+ private WorkItemImpl workItem;
+
+ // The original work.
+ private Work decoratedWork;
+
+ /*
+ * Initializes the work item and underlying work.
+ */
+ private DecoratingWork(final WorkItemImpl workItem, final Work decoratedWork) {
+ this.workItem = workItem;
+ this.decoratedWork = decoratedWork;
+ }
+
+ /*
+ * Overrides the run method.
+ */
+ public void run() {
+ workStarted(workItem, decoratedWork);
+ try {
+ decoratedWork.run();
+ workCompleted(workItem, decoratedWork);
+ } catch (Throwable th) {
+ workCompleted(workItem, decoratedWork, new WorkException(th.getMessage(), th));
+ }
+ }
+
+ }
+
+ @Destroy
+ public void destroy() {
+ executor.shutdown();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEventImpl.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEventImpl.java
new file mode 100644
index 0000000000..67d2b66f84
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkEventImpl.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.work;
+
+
+import commonj.work.WorkEvent;
+import commonj.work.WorkException;
+import commonj.work.WorkItem;
+
+/**
+ * Default immutable implementation of the <code>WorkEvent</code> class.
+ *
+ * @version $Rev$ $Date$
+ */
+class WorkEventImpl implements WorkEvent {
+
+ // Work item for this event
+ private WorkItem workItem;
+
+ // Exception if something has gone wrong
+ private WorkException exception;
+
+ /**
+ * Instantiates the event.
+ *
+ * @param workItem Work item for this event.
+ */
+ public WorkEventImpl(final WorkItemImpl workItem) {
+ this.workItem = workItem;
+ this.exception = workItem.getException();
+ }
+
+ /**
+ * Returns the work type based on whether the work was accepted, started,
+ * rejected or completed.
+ *
+ * @return Work type.
+ */
+ public int getType() {
+ return workItem.getStatus();
+ }
+
+ /**
+ * Returns the work item associated with this work type.
+ *
+ * @return Work item.
+ */
+ public WorkItem getWorkItem() {
+ return workItem;
+ }
+
+ /**
+ * Returns the exception if the work completed with an exception.
+ *
+ * @return Work exception.
+ */
+ public WorkException getException() {
+ return exception;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItemImpl.java b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItemImpl.java
new file mode 100644
index 0000000000..170319b6e6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/java/org/apache/tuscany/sca/core/work/WorkItemImpl.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.sca.core.work;
+
+import commonj.work.Work;
+import commonj.work.WorkException;
+import commonj.work.WorkItem;
+
+/**
+ * An identity based immutable implementation of the <code>WorkItem</code>
+ * interface.
+ *
+ * @version $Rev$ $Date$
+ */
+class WorkItemImpl implements WorkItem {
+
+ // Id scoped for the VM
+ private String id;
+
+ // Status
+ private int status = -1;
+
+ // Result
+ private Work result;
+
+ // Original work
+ private Work originalWork;
+
+ // Exception
+ private WorkException exception;
+
+ /**
+ * Instantiates an id for this item.
+ *
+ * @param id of this work event.
+ */
+ protected WorkItemImpl(final String id, final Work orginalWork) {
+ this.id = id;
+ this.originalWork = orginalWork;
+ }
+
+ /**
+ * Returns the id.
+ *
+ * @return Id of this item.
+ */
+ public String getId() {
+ return id;
+ }
+
+ /**
+ * Returns the original work.
+ *
+ * @return Original work.
+ */
+ public Work getOriginalWork() {
+ return originalWork;
+ }
+
+ /**
+ * Returns the work result if the work completed.
+ *
+ * @return Work.
+ * @throws WorkException If the work completed with an exception.
+ */
+ public Work getResult() {
+ return result;
+ }
+
+ /**
+ * Sets the result.
+ *
+ * @param result Result.
+ */
+ protected void setResult(final Work result) {
+ this.result = result;
+ }
+
+ /**
+ * Returns the exception if work completed with an exception.
+ *
+ * @return Work exception.
+ */
+ protected WorkException getException() {
+ return exception;
+ }
+
+ /**
+ * Sets the exception.
+ *
+ * @param exception Exception.
+ */
+ protected void setException(final WorkException exception) {
+ this.exception = exception;
+ }
+
+ /**
+ * Returns the work type based on whether the work was accepted, started,
+ * rejected or completed.
+ *
+ * @return Work status.
+ */
+ public int getStatus() {
+ return status;
+ }
+
+ /**
+ * Sets the status.
+ *
+ * @param status Status.
+ */
+ protected void setStatus(final int status) {
+ this.status = status;
+ }
+
+ /**
+ * @see Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ return id.hashCode();
+ }
+
+ /**
+ * Indicates whether some other object is "equal to" this one.
+ *
+ * @param obj Object to be compared.
+ * @return true if this object is the same as the obj argument; false
+ * otherwise..
+ */
+ @Override
+ public boolean equals(final Object obj) {
+ return (obj != null) && (obj.getClass() == WorkItemImpl.class) && ((WorkItemImpl) obj).id.equals(id);
+ }
+
+ /**
+ * Compares this object with the specified object for order. Returns a
+ * negative integer, zero, or a positive integer as this object is less
+ * than, equal to, or greater than the specified object.
+ *
+ * @param o Object to be compared.
+ * @return A negative integer, zero, or a positive integer as this object
+ * is less than, equal to, or greater than the specified object.
+ * @throws ClassCastException needs better documentation.
+ */
+ public int compareTo(final Object o) {
+ if (o.getClass() != WorkItemImpl.class) {
+ throw new ClassCastException(o.getClass().getName());
+ } else {
+ return ((WorkItemImpl) o).getId().compareTo(getId());
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-android/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
new file mode 100644
index 0000000000..5f54178483
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for the artifact processor extension
+org.apache.tuscany.sca.core.assembly.ReferenceParameterProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#referenceParameters,model=org.apache.tuscany.sca.runtime.ReferenceParameters
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.conversation.ConversationManager b/sca-java-1.x/branches/sca-android/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.conversation.ConversationManager
new file mode 100644
index 0000000000..898054509b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.conversation.ConversationManager
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.core.conversation.ConversationManagerImpl
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint b/sca-java-1.x/branches/sca-android/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint
new file mode 100644
index 0000000000..af281d8f4d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.core.invocation.DefaultProxyFactoryExtensionPoint
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.invocation.MessageFactory b/sca-java-1.x/branches/sca-android/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.invocation.MessageFactory
new file mode 100644
index 0000000000..bcbd5b0abf
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.invocation.MessageFactory
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.core.invocation.MessageFactoryImpl
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.work.WorkScheduler b/sca-java-1.x/branches/sca-android/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.work.WorkScheduler
new file mode 100644
index 0000000000..56e99be0f2
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/main/resources/META-INF/services/org.apache.tuscany.sca.work.WorkScheduler
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.core.work.Jsr237WorkScheduler
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistryTestCase.java b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistryTestCase.java
new file mode 100644
index 0000000000..7b44736d4b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistryTestCase.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core;
+
+import junit.framework.TestCase;
+
+public class DefaultExtensionPointRegistryTestCase extends TestCase {
+ private ExtensionPointRegistry registry;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ registry = new DefaultExtensionPointRegistry();
+ }
+
+ public void testRegistry() {
+ MyRegistry service = new MyREgistryImpl();
+ registry.addExtensionPoint(service);
+ assertSame(service, registry.getExtensionPoint(MyRegistry.class));
+ registry.removeExtensionPoint(service);
+ assertNull(registry.getExtensionPoint(MyRegistry.class));
+ }
+
+ public static interface MyRegistry {
+ void doSomething();
+ }
+
+ private static class MyREgistryImpl implements MyRegistry {
+
+ public void doSomething() {
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/event/BaseEventPublisherTestCase.java b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/event/BaseEventPublisherTestCase.java
new file mode 100644
index 0000000000..2bc78c3d35
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/event/BaseEventPublisherTestCase.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.event;
+
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.event.Event;
+import org.apache.tuscany.sca.event.EventFilter;
+import org.apache.tuscany.sca.event.EventPublisher;
+import org.apache.tuscany.sca.event.RuntimeEventListener;
+import org.apache.tuscany.sca.event.TrueFilter;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class BaseEventPublisherTestCase extends TestCase {
+ EventPublisher publisher;
+
+ public void testFireListener() {
+ Event event = new TestEvent();
+ RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class);
+ listener.onEvent(EasyMock.same(event));
+ EasyMock.expectLastCall();
+ EasyMock.replay(listener);
+ publisher.addListener(listener);
+ publisher.publish(event);
+ EasyMock.verify(listener);
+ }
+
+ public void testRemoveListener() {
+ Event event = new TestEvent();
+ RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class);
+ EasyMock.replay(listener);
+ publisher.addListener(listener);
+ publisher.removeListener(listener);
+ publisher.publish(event);
+ EasyMock.verify(listener);
+ }
+
+ public void testFalseFilterListener() {
+ Event event = new TestEvent();
+ RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class);
+ EasyMock.replay(listener);
+ publisher.addListener(new FalseFilter(), listener);
+ publisher.publish(event);
+ EasyMock.verify(listener);
+ }
+
+ public void testTrueFilterListener() {
+ Event event = new TestEvent();
+ RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class);
+ listener.onEvent(EasyMock.same(event));
+ EasyMock.expectLastCall();
+ EasyMock.replay(listener);
+ publisher.addListener(new TrueFilter(), listener);
+ publisher.publish(event);
+ EasyMock.verify(listener);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ publisher = new BaseEventPublisher() {
+ };
+ }
+
+ private class TestEvent implements Event {
+ public Object getSource() {
+ return null;
+ }
+ }
+
+ private class FalseFilter implements EventFilter {
+
+ public boolean match(Event event) {
+ return false;
+ }
+ }
+
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/event/EventTestCase.java b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/event/EventTestCase.java
new file mode 100644
index 0000000000..48dcf8df07
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/event/EventTestCase.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.event;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class EventTestCase extends TestCase {
+ private URI uri = URI.create("foo");
+
+ public void testCompositeStart() {
+ ComponentStart event = new ComponentStart(this, uri);
+ assertEquals(uri, event.getComponentURI());
+ }
+
+ public void testCompositeStop() {
+ ComponentStop event = new ComponentStop(this, uri);
+ assertEquals(uri, event.getComponentURI());
+ }
+
+ public void testHttpSessionStart() {
+ Object id = new Object();
+ HttpSessionStart event = new HttpSessionStart(this, id);
+ assertEquals(this, event.getSource());
+ assertEquals(id, event.getSessionID());
+ }
+
+ public void testHttpSessionEnd() {
+ Object id = new Object();
+ HttpSessionEnd event = new HttpSessionEnd(this, id);
+ assertEquals(this, event.getSource());
+ assertEquals(id, event.getSessionID());
+ }
+
+ public void testRequestStart() {
+ RequestStart event = new RequestStart(this);
+ assertEquals(this, event.getSource());
+ }
+
+ public void testReequestEnd() {
+ RequestEnd event = new RequestEnd(this);
+ assertEquals(this, event.getSource());
+ }
+
+
+ @Override
+ protected void setUp() throws Exception {
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseManagerTestCase.java b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseManagerTestCase.java
new file mode 100644
index 0000000000..99d5ec7bc9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseManagerTestCase.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core.invocation;
+
+import java.util.List;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PhaseManagerTestCase {
+
+ @Test
+ public void testDiscovery() {
+ PhaseManager pm = new PhaseManager("org.apache.tuscany.sca.invocation.PhaseTest");
+ List<String> phases = pm.getAllPhases();
+ System.out.println(phases.size());
+ System.out.println(phases);
+ // Assert.assertEquals(15, phases.size());
+ Assert.assertEquals("reference.first", phases.get(0));
+
+ int rt = phases.indexOf("reference.transaction");
+ Assert.assertTrue(rt > phases.indexOf("reference.interface"));
+
+ int st = phases.indexOf("service.transaction");
+ Assert.assertTrue(st > phases.indexOf("service.binding"));
+
+ int it = phases.indexOf("implementation.transaction");
+ Assert.assertTrue(it < phases.indexOf("implementation.policy"));
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseSorterTestCase.java b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseSorterTestCase.java
new file mode 100644
index 0000000000..61164fa2de
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/invocation/PhaseSorterTestCase.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.invocation;
+
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+public class PhaseSorterTestCase extends TestCase {
+ private PhaseSorter<String> graph;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ graph = new PhaseSorter<String>();
+ }
+
+ public void testSort() {
+ graph.addEdge("a", "b");
+ graph.addEdge("a", "c");
+ graph.addEdge("c", "d");
+ graph.addEdge("b", "c");
+ List<String> order = graph.topologicalSort(true);
+ assertEquals(Arrays.asList("a", "b", "c", "d"), order);
+ assertTrue(!graph.getVertices().isEmpty());
+
+ graph.addEdge("d", "a");
+ try {
+ order = graph.topologicalSort(true);
+ assertTrue("Should have failed", false);
+ } catch (IllegalArgumentException e) {
+ assertTrue(true);
+ }
+
+ graph.removeEdge("d", "a");
+ order = graph.topologicalSort(false);
+ assertEquals(Arrays.asList("a", "b", "c", "d"), order);
+ assertTrue(graph.getVertices().isEmpty());
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainerTestCase.java b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainerTestCase.java
new file mode 100644
index 0000000000..64114f7fb2
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/scope/AbstractScopeContainerTestCase.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.scope;
+
+import java.net.URI;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.core.context.InstanceWrapper;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.easymock.EasyMock;
+import org.easymock.IMocksControl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractScopeContainerTestCase<T, KEY> extends TestCase {
+ protected IMocksControl control;
+ protected ScopeContainer<KEY> scopeContainer;
+ protected URI groupId;
+ protected KEY contextId;
+ protected RuntimeComponent component;
+ protected ScopedImplementation implementation;
+ protected InstanceWrapper<T> wrapper;
+
+ @SuppressWarnings("unchecked")
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ control = EasyMock.createStrictControl();
+ component = control.createMock(RuntimeComponent.class);
+ wrapper = control.createMock(InstanceWrapper.class);
+ implementation = control.createMock(ScopedImplementation.class);
+ EasyMock.expect(component.getImplementation()).andReturn(implementation).anyTimes();
+ }
+
+ protected void preRegisterComponent() throws Exception {
+ scopeContainer.start();
+ EasyMock.expect(implementation.isEagerInit()).andStubReturn(false);
+ }
+
+ protected void expectCreateWrapper() throws Exception {
+ EasyMock.expect(implementation.createInstanceWrapper()).andReturn(wrapper);
+ wrapper.start();
+ }
+
+ protected static interface ScopedImplementation extends ScopedImplementationProvider, Implementation {
+
+ }
+
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/store/MemoryStoreTestCase.java b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/store/MemoryStoreTestCase.java
new file mode 100644
index 0000000000..d46d77b4b8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/store/MemoryStoreTestCase.java
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.store;
+
+import java.util.UUID;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.event.RuntimeEventListener;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.store.DuplicateRecordException;
+import org.apache.tuscany.sca.store.Store;
+import org.apache.tuscany.sca.store.StoreExpirationEvent;
+import org.apache.tuscany.sca.store.StoreMonitor;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class MemoryStoreTestCase extends TestCase {
+ private StoreMonitor monitor;
+
+ public void testEviction() throws Exception {
+ MemoryStore store = new MemoryStore(monitor);
+ store.setReaperInterval(10);
+ store.init();
+ RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class);
+ EasyMock.replay(component);
+ String id = UUID.randomUUID().toString();
+ Object value = new Object();
+ store.insertRecord(component, id, value, 1);
+ Thread.sleep(200);
+ assertNull(store.readRecord(component, id));
+ store.destroy();
+ }
+
+ public void testNotifyOnEviction() throws Exception {
+ final CountDownLatch latch = new CountDownLatch(1);
+ RuntimeEventListener listener = EasyMock.createMock(RuntimeEventListener.class);
+ listener.onEvent(EasyMock.isA(StoreExpirationEvent.class));
+ EasyMock.expectLastCall().andStubAnswer(new IAnswer<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();
+ RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class);
+ EasyMock.replay(component);
+ String id = UUID.randomUUID().toString();
+ Object value = new Object();
+ store.insertRecord(component, id, value, 1);
+ if (!latch.await(1000, TimeUnit.MILLISECONDS)) {
+ // failed to notify listener
+ fail();
+ }
+ EasyMock.verify(listener);
+ }
+
+ public void testNoEviction() throws Exception {
+ MemoryStore store = new MemoryStore(monitor);
+ store.setReaperInterval(10);
+ store.init();
+ RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class);
+ EasyMock.replay(component);
+ String id = UUID.randomUUID().toString();
+ Object value = new Object();
+ store.insertRecord(component, id, value, Store.NEVER);
+ Thread.sleep(100);
+ assertNotNull(store.readRecord(component, id));
+ store.destroy();
+ }
+
+ public void testInsertRecord() throws Exception {
+ MemoryStore store = new MemoryStore(monitor);
+ store.setReaperInterval(10);
+ store.init();
+ RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class);
+ EasyMock.replay(component);
+ String id = UUID.randomUUID().toString();
+ Object value = new Object();
+ store.insertRecord(component, id, value, Store.NEVER);
+ store.destroy();
+ }
+
+ public void testInsertAlreadyExists() throws Exception {
+ MemoryStore store = new MemoryStore(monitor);
+ store.setReaperInterval(10);
+ store.init();
+ RuntimeComponent component = EasyMock.createMock(RuntimeComponent.class);
+ EasyMock.expect(component.getURI()).andReturn("component");
+ EasyMock.replay(component);
+ String id = UUID.randomUUID().toString();
+ Object value = new Object();
+ store.insertRecord(component, id, value, Store.NEVER);
+ try {
+ store.insertRecord(component, id, value, Store.NEVER);
+ fail();
+ } catch (DuplicateRecordException e) {
+ //expected
+ }
+ store.destroy();
+ }
+
+ public void testUpdateRecord() throws Exception {
+ MemoryStore store = new MemoryStore(monitor);
+ store.setReaperInterval(10);
+ store.init();
+ RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class);
+ EasyMock.replay(component);
+ String id = UUID.randomUUID().toString();
+ Object value = new Object();
+ Object newValue = new Object();
+
+ store.insertRecord(component, id, value, Store.NEVER);
+ store.updateRecord(component, id, newValue, 1L);
+ assertEquals(newValue, store.readRecord(component, id));
+ store.destroy();
+ }
+
+ public void testDeleteRecord() throws Exception {
+ MemoryStore store = new MemoryStore(monitor);
+ store.setReaperInterval(10);
+ store.init();
+ RuntimeComponent component = EasyMock.createNiceMock(RuntimeComponent.class);
+ EasyMock.replay(component);
+ String id = UUID.randomUUID().toString();
+ Object value = new Object();
+
+ store.insertRecord(component, id, value, Store.NEVER);
+ store.removeRecord(component, id);
+ assertNull(store.readRecord(component, id));
+ store.destroy();
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ monitor = EasyMock.createNiceMock(StoreMonitor.class);
+ EasyMock.replay(monitor);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java
new file mode 100644
index 0000000000..1aba9656d8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/CallbackInterfaceInterceptorTestCase.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.wire;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.core.assembly.EndpointReferenceImpl;
+import org.apache.tuscany.sca.core.invocation.CallbackInterfaceInterceptor;
+import org.apache.tuscany.sca.core.invocation.MessageFactoryImpl;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Message;
+import org.easymock.EasyMock;
+import org.osoa.sca.NoRegisteredCallbackException;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CallbackInterfaceInterceptorTestCase extends TestCase {
+
+ public void testHasCallbackObject() {
+ CallbackInterfaceInterceptor interceptor = new CallbackInterfaceInterceptor();
+ Interceptor next = EasyMock.createMock(Interceptor.class);
+ EasyMock.expect(next.invoke(EasyMock.isA(Message.class))).andReturn(null);
+ EasyMock.replay(next);
+ interceptor.setNext(next);
+ Message msg = new MessageFactoryImpl().createMessage();
+ msg.setFrom(new EndpointReferenceImpl("uri"));
+ msg.getFrom().getReferenceParameters().setCallbackObjectID("ABC");
+ interceptor.invoke(msg);
+ EasyMock.verify(next);
+ }
+
+ public void testNoCallbackObject() {
+ CallbackInterfaceInterceptor interceptor = new CallbackInterfaceInterceptor();
+ Message msg = new MessageFactoryImpl().createMessage();
+ msg.setFrom(new EndpointReferenceImpl("uri"));
+ msg.getFrom().getReferenceParameters().setCallbackObjectID(null);
+ try {
+ interceptor.invoke(msg);
+ fail();
+ } catch (NoRegisteredCallbackException e) {
+ // expected
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java
new file mode 100644
index 0000000000..1ad0927d16
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/InvocationChainImplTestCase.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.wire;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.core.invocation.InvocationChainImpl;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.impl.OperationImpl;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.Phase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InvocationChainImplTestCase extends TestCase {
+
+ public void testInsertAtEnd() throws Exception {
+ Operation op = newOperation("foo");
+ InvocationChain chain = new InvocationChainImpl(op, op, true);
+ Interceptor inter2 = new MockInterceptor();
+ Interceptor inter1 = new MockInterceptor();
+ chain.addInterceptor(inter1);
+ chain.addInterceptor(inter2);
+ Interceptor head = (Interceptor)chain.getHeadInvoker();
+ assertEquals(inter1, head);
+ assertEquals(inter2, head.getNext());
+ assertEquals(inter2, chain.getTailInvoker());
+
+ }
+
+ public void testAddByPhase() throws Exception {
+ Operation op = newOperation("foo");
+ InvocationChain chain = new InvocationChainImpl(op, op, false);
+ Interceptor inter1 = new MockInterceptor();
+ Interceptor inter2 = new MockInterceptor();
+ Interceptor inter3 = new MockInterceptor();
+ Interceptor inter4 = new MockInterceptor();
+ chain.addInterceptor(inter3); // SERVICE
+ chain.addInterceptor(Phase.IMPLEMENTATION_POLICY, inter4);
+ chain.addInterceptor(Phase.SERVICE_POLICY, inter2);
+ chain.addInterceptor(Phase.SERVICE_BINDING, inter1);
+ Interceptor head = (Interceptor)chain.getHeadInvoker();
+ assertEquals(inter1, head);
+ assertEquals(inter2, inter1.getNext());
+ assertEquals(inter3, inter2.getNext());
+ assertEquals(inter4, inter3.getNext());
+ assertEquals(inter4, chain.getTailInvoker());
+ }
+
+ private class MockInterceptor implements Interceptor {
+
+ private Invoker next;
+
+ public Message invoke(Message msg) {
+ return null;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ }
+
+ private static Operation newOperation(String name) {
+ Operation operation = new OperationImpl();
+ operation.setName(name);
+ return operation;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.java b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.java
new file mode 100644
index 0000000000..b8150d4edc
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/wire/NonBlockingInterceptorTestCase.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.wire;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.getCurrentArguments;
+import static org.easymock.EasyMock.isA;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.core.invocation.NonBlockingInterceptor;
+import org.apache.tuscany.sca.core.invocation.ThreadMessageContext;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.work.WorkScheduler;
+import org.easymock.EasyMock;
+import org.easymock.IAnswer;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class NonBlockingInterceptorTestCase extends TestCase {
+
+ public void testInvoke() throws Exception {
+ WorkScheduler scheduler = createMock(WorkScheduler.class);
+ scheduler.scheduleWork(isA(Runnable.class));
+ expectLastCall().andStubAnswer(new IAnswer<Object>() {
+ public Object answer() throws Throwable {
+ Runnable runnable = (Runnable) getCurrentArguments()[0];
+ runnable.run();
+ return null;
+ }
+ });
+ replay(scheduler);
+ Message context = createMock(Message.class);
+ //String convID = "convID";
+ //TODO port to the new way of dealing with conversation IDs later
+ //EasyMock.expect(context.getConversationID()).andReturn(convID);
+ EasyMock.replay(context);
+ ThreadMessageContext.setMessageContext(context);
+ Message msg = createMock(Message.class);
+ //TODO port to the new way of dealing with conversation IDs later
+ //msg.setConversationID(convID);
+ Interceptor next = EasyMock.createMock(Interceptor.class);
+ EasyMock.expect(next.invoke(EasyMock.eq(msg))).andReturn(msg);
+ EasyMock.expect(msg.isFault()).andReturn(false);
+ EasyMock.replay(next);
+ EasyMock.replay(msg);
+ Interceptor interceptor = new NonBlockingInterceptor(scheduler, next);
+ interceptor.invoke(msg);
+ verify(context);
+ verify(next);
+ verify(msg);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/FailingWork.java b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/FailingWork.java
new file mode 100644
index 0000000000..3184c3de92
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/FailingWork.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.work;
+
+import commonj.work.Work;
+
+/**
+ * Simple Work item that will throw an exception
+ *
+ * @version $Rev$ $Date$
+ */
+public class FailingWork implements Work {
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isDaemon() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void release() {
+ }
+
+ /**
+ * Throws an IllegalArgumentException
+ */
+ public void run() {
+ System.out.println("Starting " + this + " and throwing an Exception");
+ throw new IllegalArgumentException("Sample exception from " + this);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyFailingRunnable.java b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyFailingRunnable.java
new file mode 100644
index 0000000000..91b45dfbcb
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyFailingRunnable.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.work;
+
+/**
+ * Simple Runnable that throws an IllegalArgumentException
+ *
+ * @version $Rev$ $Date$
+ */
+public class JSR237MyFailingRunnable extends JSR237MyRunnable {
+
+ /**
+ * Constructor
+ */
+ public JSR237MyFailingRunnable() {
+ super(-1);
+ }
+
+ /**
+ * Sleeps for a period of time defined by sleepTime
+ */
+ @Override
+ public void run() {
+ System.out.println("Starting " + this + " and throwing an Exception");
+ throw new IllegalArgumentException("Sample exception from " + this);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyRunnable.java b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyRunnable.java
new file mode 100644
index 0000000000..a7617f7a70
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyRunnable.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.work;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Simple Runnable that is used for testing Jsr237WorkScheduler
+ *
+ * @version $Rev$ $Date$
+ */
+public class JSR237MyRunnable implements Runnable {
+
+ /**
+ * Count of workAccepted() method calls
+ */
+ private AtomicInteger runCompletedCount = new AtomicInteger();
+
+ /**
+ * The amount of time to sleep in the Run loop
+ */
+ private final long sleepTime;
+
+ /**
+ * Constructor
+ *
+ * @param sleepTime The amount of time to sleep (in milliseconds) in the run() method
+ */
+ public JSR237MyRunnable(long sleepTime) {
+ this.sleepTime = sleepTime;
+ }
+
+ /**
+ * Sleeps for a period of time defined by sleepTime
+ */
+ public void run() {
+ System.out.println("Starting " + this);
+ try {
+ Thread.sleep(sleepTime);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ System.out.println("Done " + this);
+ runCompletedCount.incrementAndGet();
+ }
+
+ /**
+ * Returns the number of completed calls to run()
+ *
+ * @return The number of completed calls to run()
+ */
+ public int getRunCompletedCount() {
+ return runCompletedCount.get();
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyRunnerListener.java b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyRunnerListener.java
new file mode 100644
index 0000000000..75840efef4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/JSR237MyRunnerListener.java
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.work;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.tuscany.sca.work.NotificationListener;
+
+/**
+ * Simple NotificationListener that is used for testing Jsr237WorkScheduler
+ *
+ * @version $Rev$ $Date$
+ */
+public class JSR237MyRunnerListener implements NotificationListener<JSR237MyRunnable> {
+
+ /**
+ * Count of workAccepted() method calls
+ */
+ private AtomicInteger workAcceptedCallCount = new AtomicInteger();
+
+ /**
+ * Count of workStarted() method calls
+ */
+ private AtomicInteger workStartedCallCount = new AtomicInteger();
+
+ /**
+ * Count of workCompleted() method calls
+ */
+ private AtomicInteger workCompletedCallCount = new AtomicInteger();
+
+ /**
+ * Count of workFailed() method calls
+ */
+ private AtomicInteger workFailedCallCount = new AtomicInteger();
+
+ /**
+ * Count of workRejected() method calls
+ */
+ private AtomicInteger workRejectedCallCount = new AtomicInteger();
+
+ /**
+ * List of all exceptions thrown by Work items
+ */
+ private List<Throwable> workExceptions = Collections.synchronizedList(new ArrayList<Throwable>());
+
+ /**
+ * {@inheritDoc}
+ */
+ public void workAccepted(JSR237MyRunnable work) {
+ workAcceptedCallCount.incrementAndGet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void workCompleted(JSR237MyRunnable work) {
+ workCompletedCallCount.incrementAndGet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void workFailed(JSR237MyRunnable work, Throwable error) {
+ workExceptions.add(error);
+ workFailedCallCount.incrementAndGet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void workRejected(JSR237MyRunnable work) {
+ workRejectedCallCount.incrementAndGet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void workStarted(JSR237MyRunnable work) {
+ workStartedCallCount.incrementAndGet();
+ }
+
+ /**
+ * Returns the number of calls to workAccepted()
+ *
+ * @return The number of calls to workAccepted()
+ */
+ public int getWorkAcceptedCallCount() {
+ return workAcceptedCallCount.get();
+ }
+
+ /**
+ * Returns the number of calls to workStarted()
+ *
+ * @return The number of calls to workStarted()
+ */
+ public int getWorkStartedCallCount() {
+ return workStartedCallCount.get();
+ }
+
+ /**
+ * Returns the number of calls to workCompleted()
+ *
+ * @return The number of calls to workCompleted()
+ */
+ public int getWorkCompletedCallCount() {
+ return workCompletedCallCount.get();
+ }
+
+ /**
+ * Returns the number of calls to workFailed()
+ *
+ * @return The number of calls to workFailed()
+ */
+ public int getWorkFailedCallCount() {
+ return workFailedCallCount.get();
+ }
+
+ /**
+ * Returns the number of calls to workRejected()
+ *
+ * @return The number of calls to workRejected()
+ */
+ public int getWorkRejectedCallCount() {
+ return workRejectedCallCount.get();
+ }
+
+ /**
+ * Returns a List of all exceptions that are thrown by the Work items
+ *
+ * @return A List of all exceptions that are thrown by the Work items
+ */
+ public List<Throwable> getWorkExceptions() {
+ return Collections.unmodifiableList(workExceptions);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/Jsr237WorkSchedulerTestCase.java b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/Jsr237WorkSchedulerTestCase.java
new file mode 100644
index 0000000000..225f23cb93
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/Jsr237WorkSchedulerTestCase.java
@@ -0,0 +1,240 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.work;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test case for Jsr237WorkScheduler
+ *
+ * @version $Rev$ $Date$
+ */
+public class Jsr237WorkSchedulerTestCase {
+
+ /**
+ * Wait up to 20 seconds for the Work units to complete
+ */
+ private static final long WAIT_TIMEOUT = 20000;
+
+ /**
+ * This is the shared instance of the ThreadPoolWorkManager used by the tests
+ */
+ private static Jsr237WorkScheduler workSchedular = null;
+
+ /**
+ * Setup the Jsr237WorkScheduler
+ */
+ @BeforeClass
+ public static void setup() {
+ workSchedular = new Jsr237WorkScheduler();
+ }
+
+ /**
+ * Make sure that the Jsr237WorkScheduler is stopped after running the tests
+ */
+ @AfterClass
+ public static void destroy() {
+ if (workSchedular != null) {
+ workSchedular.destroy();
+ }
+ }
+
+ /**
+ * Tests running a single fast job on the Jsr237WorkScheduler
+ */
+ @Test
+ public void testSingleFastJob() {
+ // Create the work and register it
+ JSR237MyRunnable fast = new JSR237MyRunnable(10);
+ JSR237MyRunnerListener listener = new JSR237MyRunnerListener();
+ workSchedular.scheduleWork(fast, listener);
+
+ // Wait for the 1 job to complete
+ waitForWorkToComplete(listener, 1);
+
+ // Test that the job completed successfully.
+ Assert.assertEquals(1, listener.getWorkAcceptedCallCount());
+ Assert.assertEquals(0, listener.getWorkRejectedCallCount());
+ Assert.assertEquals(1, listener.getWorkStartedCallCount());
+ Assert.assertEquals(1, listener.getWorkCompletedCallCount());
+ Assert.assertEquals(0, listener.getWorkExceptions().size());
+ }
+
+ /**
+ * Tests running a single job that fails on the Jsr237WorkScheduler
+ */
+ @Test
+ public void testSingleFailingJob() {
+ // Create the work and register it
+ JSR237MyFailingRunnable fail = new JSR237MyFailingRunnable();
+ JSR237MyRunnerListener listener = new JSR237MyRunnerListener();
+ workSchedular.scheduleWork(fail, listener);
+
+ // Wait for the 1 job to complete
+ waitForWorkToComplete(listener, 1);
+
+ // Test that the job completed successfully.
+ Assert.assertEquals(1, listener.getWorkAcceptedCallCount());
+ Assert.assertEquals(0, listener.getWorkRejectedCallCount());
+ Assert.assertEquals(1, listener.getWorkStartedCallCount());
+ Assert.assertEquals(0, listener.getWorkCompletedCallCount());
+ Assert.assertEquals(1, listener.getWorkFailedCallCount());
+ Assert.assertEquals(1, listener.getWorkExceptions().size());
+ }
+
+ /**
+ * Tests running a mixture of fast and slow jobs on the Jsr237WorkScheduler
+ */
+ @Test
+ public void testMultipleJobs() {
+ // Create the work and register it
+ JSR237MyRunnable fast1 = new JSR237MyRunnable(50);
+ JSR237MyRunnable fast2 = new JSR237MyRunnable(100);
+ JSR237MyRunnable fast3 = new JSR237MyRunnable(200);
+ JSR237MyRunnable slow1= new JSR237MyRunnable(2000);
+ JSR237MyRunnable slow2 = new JSR237MyRunnable(2000);
+ JSR237MyRunnerListener listener = new JSR237MyRunnerListener();
+ workSchedular.scheduleWork(fast1, listener);
+ workSchedular.scheduleWork(fast2, listener);
+ workSchedular.scheduleWork(fast3, listener);
+ workSchedular.scheduleWork(slow1, listener);
+ workSchedular.scheduleWork(slow2, listener);
+
+ // Wait for the 5 jobs to complete
+ waitForWorkToComplete(listener, 5);
+
+ // Test that the job completed successfully.
+ Assert.assertEquals(5, listener.getWorkAcceptedCallCount());
+ Assert.assertEquals(0, listener.getWorkRejectedCallCount());
+ Assert.assertEquals(5, listener.getWorkStartedCallCount());
+ Assert.assertEquals(5, listener.getWorkCompletedCallCount());
+ Assert.assertEquals(0, listener.getWorkExceptions().size());
+ }
+
+ /**
+ * Tests running a mixture of fast and slow jobs some of which fail on the
+ * Jsr237WorkScheduler
+ */
+ @Test
+ public void testMultipleJobsSomeFail() {
+ // Create the work and register it
+ JSR237MyRunnable fast1 = new JSR237MyRunnable(50);
+ JSR237MyRunnable fast2 = new JSR237MyRunnable(100);
+ JSR237MyRunnable fast3 = new JSR237MyRunnable(200);
+ JSR237MyRunnable slow1= new JSR237MyRunnable(2000);
+ JSR237MyRunnable slow2 = new JSR237MyRunnable(2000);
+ JSR237MyFailingRunnable fail1 = new JSR237MyFailingRunnable();
+ JSR237MyFailingRunnable fail2 = new JSR237MyFailingRunnable();
+ JSR237MyRunnerListener listener = new JSR237MyRunnerListener();
+ workSchedular.scheduleWork(fast1, listener);
+ workSchedular.scheduleWork(fast2, listener);
+ workSchedular.scheduleWork(fail1, listener);
+ workSchedular.scheduleWork(fast3, listener);
+ workSchedular.scheduleWork(slow1, listener);
+ workSchedular.scheduleWork(fail2, listener);
+ workSchedular.scheduleWork(slow2, listener);
+
+ // Wait for the 7 jobs to complete
+ waitForWorkToComplete(listener, 7);
+
+ // Test that the job completed successfully.
+ Assert.assertEquals(7, listener.getWorkAcceptedCallCount());
+ Assert.assertEquals(0, listener.getWorkRejectedCallCount());
+ Assert.assertEquals(7, listener.getWorkStartedCallCount());
+ Assert.assertEquals(5, listener.getWorkCompletedCallCount());
+ Assert.assertEquals(2, listener.getWorkFailedCallCount());
+ Assert.assertEquals(2, listener.getWorkExceptions().size());
+ }
+
+ /**
+ * Tests running a single job that has no listener
+ */
+ @Test
+ public void testSingleFastJobWithNoListener() {
+ // Create the work and register it
+ JSR237MyRunnable fast = new JSR237MyRunnable(10);
+ workSchedular.scheduleWork(fast);
+
+ // Wait for the job to complete
+ long startTime = System.currentTimeMillis();
+ while (true) {
+ int completedCount = fast.getRunCompletedCount();
+ if (completedCount == 1) {
+ break;
+ }
+
+ if (System.currentTimeMillis() - startTime > WAIT_TIMEOUT) {
+ Assert.fail("Only " + completedCount + " work items completed before timeout");
+ return;
+ }
+
+ // Lets wait for the job to complete
+ try {
+ Thread.sleep(25);
+ } catch (InterruptedException ex) {
+ Assert.fail("Unexpected exception: " + ex);
+ }
+ }
+ }
+
+ /**
+ * Tests scheduling a null as the work item
+ */
+ @Test
+ public void testNullWork() {
+ try {
+ workSchedular.scheduleWork(null);
+ Assert.fail("Should have thrown IllegalArgumentException ");
+ } catch (IllegalArgumentException ex) {
+ // As expected
+ Assert.assertTrue(ex.toString().indexOf("null") != -1);
+ }
+ }
+
+ /**
+ * Waits for the specified number of jobs to complete or the timeout to fire.
+ *
+ * @param listener The listener to use to track Work unit completion
+ * @param completedWorkItemsToWaitFor The number of Work items to complete
+ */
+ private void waitForWorkToComplete(JSR237MyRunnerListener listener, int completedWorkItemsToWaitFor) {
+ long startTime = System.currentTimeMillis();
+ while (true) {
+ int completedCount = listener.getWorkCompletedCallCount() + listener.getWorkFailedCallCount();
+ if (completedCount == completedWorkItemsToWaitFor) {
+ return;
+ }
+
+ if (System.currentTimeMillis() - startTime > WAIT_TIMEOUT) {
+ Assert.fail("Only " + completedCount + " work items completed before timeout");
+ return;
+ }
+
+ // Lets wait for more jobs to complete
+ try {
+ Thread.sleep(25);
+ } catch (InterruptedException ex) {
+ Assert.fail("Unexpected exception: " + ex);
+ }
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TestWorkListener.java b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TestWorkListener.java
new file mode 100644
index 0000000000..ba32a92c18
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TestWorkListener.java
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.work;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.junit.Assert;
+
+import commonj.work.WorkEvent;
+import commonj.work.WorkException;
+import commonj.work.WorkListener;
+
+/**
+ * A simple WorkListener that tracks invocations to it.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestWorkListener implements WorkListener {
+
+ /**
+ * Count of workAccepted() method calls
+ */
+ private AtomicInteger workAcceptedCallCount = new AtomicInteger();
+
+ /**
+ * Count of workStarted() method calls
+ */
+ private AtomicInteger workStartedCallCount = new AtomicInteger();
+
+ /**
+ * Count of workCompleted() method calls
+ */
+ private AtomicInteger workCompletedCallCount = new AtomicInteger();
+
+ /**
+ * Count of workRejected() method calls
+ */
+ private AtomicInteger workRejectedCallCount = new AtomicInteger();
+
+ /**
+ * List of all exceptions thrown by Work items
+ */
+ private List<WorkException> workExceptions = Collections.synchronizedList(new ArrayList<WorkException>());
+
+ /**
+ * {@inheritDoc}
+ */
+ public void workAccepted(WorkEvent work) {
+ workAcceptedCallCount.incrementAndGet();
+
+ // Validate the WorkEvent
+ Assert.assertNotNull(work.getWorkItem());
+ Assert.assertEquals(WorkEvent.WORK_ACCEPTED, work.getType());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void workStarted(WorkEvent work) {
+ workStartedCallCount.incrementAndGet();
+
+ // Validate the WorkEvent
+ Assert.assertNotNull(work.getWorkItem());
+ Assert.assertEquals(WorkEvent.WORK_STARTED, work.getType());
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void workCompleted(WorkEvent work) {
+ if (work.getException() != null) {
+ workExceptions.add(work.getException());
+ }
+
+ // Validate the WorkEvent
+ Assert.assertNotNull(work.getWorkItem());
+ Assert.assertEquals(WorkEvent.WORK_COMPLETED, work.getType());
+
+ workCompletedCallCount.incrementAndGet();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void workRejected(WorkEvent work) {
+ workRejectedCallCount.incrementAndGet();
+
+ // Validate the WorkEvent
+ Assert.assertNotNull(work.getWorkItem());
+ Assert.assertEquals(WorkEvent.WORK_REJECTED, work.getType());
+ }
+
+ /**
+ * Returns the number of calls to workAccepted()
+ *
+ * @return The number of calls to workAccepted()
+ */
+ public int getWorkAcceptedCallCount() {
+ return workAcceptedCallCount.get();
+ }
+
+ /**
+ * Returns the number of calls to workStarted()
+ *
+ * @return The number of calls to workStarted()
+ */
+ public int getWorkStartedCallCount() {
+ return workStartedCallCount.get();
+ }
+
+ /**
+ * Returns the number of calls to workCompleted()
+ *
+ * @return The number of calls to workCompleted()
+ */
+ public int getWorkCompletedCallCount() {
+ return workCompletedCallCount.get();
+ }
+
+ /**
+ * Returns the number of calls to workRejected()
+ *
+ * @return The number of calls to workRejected()
+ */
+ public int getWorkRejectedCallCount() {
+ return workRejectedCallCount.get();
+ }
+
+ /**
+ * Returns a List of all exceptions that are thrown by the Work items
+ *
+ * @return A List of all exceptions that are thrown by the Work items
+ */
+ public List<WorkException> getWorkExceptions() {
+ return Collections.unmodifiableList(workExceptions);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManagerTestCase.java b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManagerTestCase.java
new file mode 100644
index 0000000000..715f5f95c0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/ThreadPoolWorkManagerTestCase.java
@@ -0,0 +1,243 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.work;
+
+import org.junit.AfterClass;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * This test case will test the ThreadPoolWorkManager
+ *
+ * @version $Rev$ $Date$
+ */
+public class ThreadPoolWorkManagerTestCase {
+
+ /**
+ * Wait up to 20 seconds for the Work units to complete
+ */
+ private static final long WAIT_TIMEOUT = 20000;
+
+ /**
+ * This is the shared instance of the ThreadPoolWorkManager used by the tests
+ */
+ private static ThreadPoolWorkManager workManager = null;
+
+ /**
+ * Setup the ThreadPoolWorkManager
+ */
+ @BeforeClass
+ public static void setup() {
+ workManager = new ThreadPoolWorkManager(10);
+ }
+
+ /**
+ * Make sure that the ThreadPoolWorkManager is stopped after running the tests
+ */
+ @AfterClass
+ public static void destroy() {
+ if (workManager != null) {
+ workManager.destroy();
+ }
+ }
+
+ /**
+ * Tests running a single fast job on the ThreadPoolWorkManager
+ */
+ @Test
+ public void testSingleFastJob() {
+ // Create the work and register it
+ TimeDelayWork fast = new TimeDelayWork(10);
+ TestWorkListener listener = new TestWorkListener();
+ workManager.schedule(fast, listener);
+
+ // Wait for the 1 job to complete
+ waitForWorkToComplete(listener, 1);
+
+ // Test that the job completed successfully.
+ Assert.assertEquals(1, listener.getWorkAcceptedCallCount());
+ Assert.assertEquals(0, listener.getWorkRejectedCallCount());
+ Assert.assertEquals(1, listener.getWorkStartedCallCount());
+ Assert.assertEquals(1, listener.getWorkCompletedCallCount());
+ Assert.assertEquals(0, listener.getWorkExceptions().size());
+ }
+
+ /**
+ * Tests running a single job that fails on the ThreadPoolWorkManager
+ */
+ @Test
+ public void testSingleFailingJob() {
+ // Create the work and register it
+ FailingWork fail = new FailingWork();
+ TestWorkListener listener = new TestWorkListener();
+ workManager.schedule(fail, listener);
+
+ // Wait for the 1 job to complete
+ waitForWorkToComplete(listener, 1);
+
+ // Test that the job completed successfully.
+ Assert.assertEquals(1, listener.getWorkAcceptedCallCount());
+ Assert.assertEquals(0, listener.getWorkRejectedCallCount());
+ Assert.assertEquals(1, listener.getWorkStartedCallCount());
+ Assert.assertEquals(1, listener.getWorkCompletedCallCount());
+ Assert.assertEquals(1, listener.getWorkExceptions().size());
+ }
+
+ /**
+ * Tests running a mixture of fast and slow jobs on the ThreadPoolWorkManager
+ */
+ @Test
+ public void testMultipleJobs() {
+ // Create the work and register it
+ TimeDelayWork fast1 = new TimeDelayWork(50);
+ TimeDelayWork fast2 = new TimeDelayWork(100);
+ TimeDelayWork fast3 = new TimeDelayWork(200);
+ TimeDelayWork slow1= new TimeDelayWork(2000);
+ TimeDelayWork slow2 = new TimeDelayWork(2000);
+ TestWorkListener listener = new TestWorkListener();
+ workManager.schedule(fast1, listener);
+ workManager.schedule(fast2, listener);
+ workManager.schedule(fast3, listener);
+ workManager.schedule(slow1, listener);
+ workManager.schedule(slow2, listener);
+
+ // Wait for the 5 jobs to complete
+ waitForWorkToComplete(listener, 5);
+
+ // Test that the job completed successfully.
+ Assert.assertEquals(5, listener.getWorkAcceptedCallCount());
+ Assert.assertEquals(0, listener.getWorkRejectedCallCount());
+ Assert.assertEquals(5, listener.getWorkStartedCallCount());
+ Assert.assertEquals(5, listener.getWorkCompletedCallCount());
+ Assert.assertEquals(0, listener.getWorkExceptions().size());
+ }
+
+ /**
+ * Tests running a mixture of fast and slow jobs some of which fail on the
+ * ThreadPoolWorkManager
+ */
+ @Test
+ public void testMultipleJobsSomeFail() {
+ // Create the work and register it
+ TimeDelayWork fast1 = new TimeDelayWork(50);
+ TimeDelayWork fast2 = new TimeDelayWork(100);
+ TimeDelayWork fast3 = new TimeDelayWork(200);
+ TimeDelayWork slow1= new TimeDelayWork(2000);
+ TimeDelayWork slow2 = new TimeDelayWork(2000);
+ FailingWork fail1 = new FailingWork();
+ FailingWork fail2 = new FailingWork();
+ TestWorkListener listener = new TestWorkListener();
+ workManager.schedule(fast1, listener);
+ workManager.schedule(fast2, listener);
+ workManager.schedule(fail1, listener);
+ workManager.schedule(fast3, listener);
+ workManager.schedule(slow1, listener);
+ workManager.schedule(fail2, listener);
+ workManager.schedule(slow2, listener);
+
+ // Wait for the 7 jobs to complete
+ waitForWorkToComplete(listener, 7);
+
+ // Test that the job completed successfully.
+ Assert.assertEquals(7, listener.getWorkAcceptedCallCount());
+ Assert.assertEquals(0, listener.getWorkRejectedCallCount());
+ Assert.assertEquals(7, listener.getWorkStartedCallCount());
+ Assert.assertEquals(7, listener.getWorkCompletedCallCount());
+ Assert.assertEquals(2, listener.getWorkExceptions().size());
+ }
+
+ /**
+ * Tests creating a ThreadPoolWorkManager with invalid pool sizes of -10 to 0
+ * inclusive
+ */
+ @Test
+ public void testThreadPoolWorkManagerLessThan1Size() {
+ for (int i = 0; i >= -10; i--) {
+ try {
+ new ThreadPoolWorkManager(i);
+ Assert.fail("Should have thrown IllegalArgumentException");
+ } catch (IllegalArgumentException ex) {
+ Assert.assertTrue(ex.toString().indexOf(Integer.toString(i)) != -1);
+ }
+ }
+ }
+
+ /**
+ * Tests running a single job that has no listener
+ */
+ @Test
+ public void testSingleFastJobWithNoListener() {
+ // Create the work and register it
+ TimeDelayWork fast = new TimeDelayWork(10);
+ workManager.schedule(fast);
+
+ // Wait for the job to complete
+ long startTime = System.currentTimeMillis();
+ while (true) {
+ int completedCount = fast.getRunCompletedCount();
+ if (completedCount == 1) {
+ break;
+ }
+
+ if (System.currentTimeMillis() - startTime > WAIT_TIMEOUT) {
+ Assert.fail("Only " + completedCount + " work items completed before timeout");
+ return;
+ }
+
+ // Lets wait for the job to complete
+ try {
+ Thread.sleep(25);
+ } catch (InterruptedException ex) {
+ Assert.fail("Unexpected exception: " + ex);
+ }
+ }
+
+ // Make sure we have got one completed run
+ Assert.assertEquals(1, fast.getRunCompletedCount());
+ }
+
+ /**
+ * Waits for the specified number of jobs to complete or the timeout to fire.
+ *
+ * @param listener The listener to use to track Work unit completion
+ * @param completedWorkItemsToWaitFor The number of Work items to complete
+ */
+ private void waitForWorkToComplete(TestWorkListener listener, int completedWorkItemsToWaitFor) {
+ long startTime = System.currentTimeMillis();
+ while (true) {
+ int completedCount = listener.getWorkCompletedCallCount();
+ if (completedCount == completedWorkItemsToWaitFor) {
+ return;
+ }
+
+ if (System.currentTimeMillis() - startTime > WAIT_TIMEOUT) {
+ Assert.fail("Only " + completedCount + " work items completed before timeout");
+ return;
+ }
+
+ // Lets wait for more jobs to complete
+ try {
+ Thread.sleep(25);
+ } catch (InterruptedException ex) {
+ Assert.fail("Unexpected exception: " + ex);
+ }
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TimeDelayWork.java b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TimeDelayWork.java
new file mode 100644
index 0000000000..3b30d86f14
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/core/work/TimeDelayWork.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.core.work;
+
+import java.util.concurrent.atomic.AtomicInteger;
+
+import commonj.work.Work;
+
+/**
+ * Simple Work item that will sleep in the run() method for the specified
+ * period of time
+ *
+ * @version $Rev$ $Date$
+ */
+public class TimeDelayWork implements Work {
+
+ /**
+ * Count of completed run() method calls
+ */
+ private AtomicInteger runCompletedCount = new AtomicInteger();
+
+ /**
+ * The amount of time to sleep in the Run loop
+ */
+ private final long sleepTime;
+
+ /**
+ * Constructor
+ *
+ * @param sleepTime The amount of time to sleep (in milliseconds) in the run() method
+ */
+ public TimeDelayWork(long sleepTime) {
+ this.sleepTime = sleepTime;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public boolean isDaemon() {
+ return false;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void release() {
+ }
+
+ /**
+ * Sleeps for a period of time defined by sleepTime
+ */
+ public void run() {
+ System.out.println("Starting " + this);
+ try {
+ Thread.sleep(sleepTime);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ System.out.println("Done " + this);
+ runCompletedCount.incrementAndGet();
+ }
+
+ /**
+ * Returns the number of completed calls to run()
+ *
+ * @return The number of completed calls to run()
+ */
+ public int getRunCompletedCount() {
+ return runCompletedCount.get();
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/scope/ScopeTestCase.java b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/scope/ScopeTestCase.java
new file mode 100644
index 0000000000..341d889b7d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/test/java/org/apache/tuscany/sca/scope/ScopeTestCase.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.scope;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.core.scope.Scope;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ScopeTestCase extends TestCase {
+
+ public void testEquals() throws Exception {
+ Scope scope = new Scope("COMPOSITE");
+ assertTrue(scope.equals(Scope.COMPOSITE));
+ }
+
+ public void testEqualsNew() throws Exception {
+ Scope foo = new Scope("foo");
+ Scope foo2 = new Scope("FOO");
+ assertTrue(foo.equals(foo2));
+ }
+
+ public void testNotEquals() throws Exception {
+ Scope foo = new Scope("BAR");
+ Scope foo2 = new Scope("FOO");
+ assertFalse(foo.equals(foo2));
+ }
+
+ public void testNotEqualsDifferent() throws Exception {
+ Scope foo = new Scope("FOO");
+ assertFalse(foo.equals(new Bar("FOO")));
+ }
+
+ public class Bar {
+ String scope;
+
+ public Bar(String scope) {
+ this.scope = scope;
+ }
+ }
+
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/core/src/test/resources/META-INF/services/org.apache.tuscany.sca.invocation.PhaseTest b/sca-java-1.x/branches/sca-android/modules/core/src/test/resources/META-INF/services/org.apache.tuscany.sca.invocation.PhaseTest
new file mode 100644
index 0000000000..9ed0928a33
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/core/src/test/resources/META-INF/services/org.apache.tuscany.sca.invocation.PhaseTest
@@ -0,0 +1,22 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+name=implementation.last, stage=implementation, after=*
+name=reference.first, stage=reference, before=*
+name=reference.transaction, stage=reference, after=reference.interface
+name=service.transaction, stage=service, after=service.binding, before=component.service
+name=implementation.transaction, stage=implementation, before=implementation.policy \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/LICENSE b/sca-java-1.x/branches/sca-android/modules/databinding/LICENSE
new file mode 100644
index 0000000000..616bec99ed
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/LICENSE
@@ -0,0 +1,244 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+-----------------------------------------------------------------
+The test cases use xmlunit with the following license:
+-----------------------------------------------------------------
+
+/*
+******************************************************************
+Copyright (c) 2001-2007, Jeff Martin, Tim Bacon
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+ * Neither the name of the xmlunit.sourceforge.net nor the names
+ of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written
+ permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+******************************************************************
+*/
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/META-INF/README b/sca-java-1.x/branches/sca-android/modules/databinding/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/NOTICE b/sca-java-1.x/branches/sca-android/modules/databinding/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/pom.xml b/sca-java-1.x/branches/sca-android/modules/databinding/pom.xml
new file mode 100644
index 0000000000..890abcc2ea
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/pom.xml
@@ -0,0 +1,108 @@
+<?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.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-databinding</artifactId>
+ <name>Apache Tuscany SCA DataBinding Framework</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-extensibility</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-interface</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-xsd</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-sca-api</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.xml.stream</groupId>
+ <artifactId>stax-api</artifactId>
+ <version>1.0-2</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ <version>3.2.1</version>
+ <scope>runtime</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+
+ <dependency>
+ <groupId>xmlunit</groupId>
+ <artifactId>xmlunit</artifactId>
+ <version>1.1</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.databinding</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.databinding*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBinding.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBinding.java
new file mode 100644
index 0000000000..547f9d9f4f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBinding.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding;
+
+
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+
+/**
+ * DataBinding represents a data representation, for example, SDO, JAXB and AXIOM
+ *
+ * @version $Rev$ $Date$
+ */
+public interface DataBinding {
+ /**
+ * A special databinding for input message of an operation
+ */
+ String IDL_INPUT = "idl:input";
+ /**
+ * A special databinding for output message of an operation
+ */
+ String IDL_OUTPUT = "idl:output";
+ /**
+ * A special databinding for fault message of an operation
+ */
+ String IDL_FAULT = "idl:fault";
+ /**
+ * The name of a databinding should be case-insensitive and unique
+ *
+ * @return The name of the databinding
+ */
+ String getName();
+
+ /**
+ * Get the aliases for the databinding
+ *
+ * @return An array of aliases
+ */
+ String[] getAliases();
+
+ /**
+ * Introspect and populate information to a DataType model
+ *
+ * @param dataType The data type to be introspected
+ * @param operation The operation
+ * @return true if the databinding has recognized the given data type
+ */
+ boolean introspect(DataType dataType, Operation operation);
+
+ /**
+ * Introspect the data to figure out the corresponding data type
+ *
+ * @param value The object to be checked
+ * @param operation The operation
+ * @return The DataType or null if the java type is not supported by this databinding
+ */
+ DataType introspect(Object value, Operation operation);
+
+ /**
+ * Provide a WrapperHandler for this databinding
+ * @return A wrapper handler which can handle wrapping/wrapping for this databinding
+ */
+ WrapperHandler getWrapperHandler();
+
+ /**
+ * Make a copy of the object for "pass-by-value" semantics.
+ *
+ * @param object source object to copy
+ * @param dataType The data type
+ * @param operation The operation
+ * @return copy of the object passed in as argument
+ */
+ Object copy(Object object, DataType dataType, Operation operation);
+
+ /**
+ * Get the type mapper for simple types
+ * @return The databinding-specific simple type mapper
+ */
+ SimpleTypeMapper getSimpleTypeMapper();
+
+ /**
+ * Get the XML type helper for Java types
+ * @return The databinding-specific XML type helper class
+ */
+ XMLTypeHelper getXMLTypeHelper();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBindingExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBindingExtensionPoint.java
new file mode 100644
index 0000000000..2ff5d866b4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataBindingExtensionPoint.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding;
+
+
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+
+/**
+ * An extension point for data binding extensions.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface DataBindingExtensionPoint {
+
+ /**
+ * Register a data binding
+ *
+ * @param dataBinding
+ */
+ void addDataBinding(DataBinding dataBinding);
+
+ /**
+ * Look up a data binding by id
+ *
+ * @param id The name of the databinding
+ * @return The databinding
+ */
+ DataBinding getDataBinding(String id);
+
+ /**
+ * Unregister a data binding
+ *
+ * @param id
+ * @return The unregistered databinding
+ */
+ DataBinding removeDataBinding(String id);
+
+ /**
+ * Introspect the java class to figure out what DataType supports it.
+ *
+ * @param dataType The initial data type
+ * @param operation TODO
+ * @return A DataType representing the java type or null if no databinding
+ * recognizes the java type
+ */
+ boolean introspectType(DataType dataType, Operation operation);
+
+ /**
+ * Introspect the value to figure out the corresponding DataType
+ *
+ * @param value The object value
+ * @param operation TODO
+ * @return A DataType representing the value or null if no databinding
+ * recognizes the value
+ */
+ DataType introspectType(Object value, Operation operation);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipe.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipe.java
new file mode 100644
index 0000000000..505a810276
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipe.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding;
+
+/**
+ * Data pipe allows a data source pushes data into its sink and pipe the data into its result
+ *
+ * @param <S> The data binding type of the sink
+ * @param <R> The data binding type of the result
+ *
+ * @version $Rev$ $Date$
+ */
+public interface DataPipe<S, R> {
+
+ /**
+ * Returns a sink (for example, java.io.OutputStream, java.io.Writer or org.xml.sax.ContentHandler) to receive data
+ * pushed by the source
+ *
+ * @return The sink to consume data
+ */
+ S getSink();
+
+ /**
+ * Returns the data populated by the sink
+ *
+ * @return
+ */
+ R getResult();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipeTransformer.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipeTransformer.java
new file mode 100644
index 0000000000..1aac6d48be
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DataPipeTransformer.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding;
+
+/**
+ * Data pipe allows a data source pushes data into its sink and pipe the data into its result
+ *
+ * @version $Rev$ $Date$
+ */
+public interface DataPipeTransformer<S, R> extends Transformer {
+
+ DataPipe<S, R> newInstance();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java
new file mode 100644
index 0000000000..b2da024a72
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultDataBindingExtensionPoint.java
@@ -0,0 +1,268 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding;
+import org.apache.tuscany.sca.databinding.javabeans.JavaExceptionDataBinding;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+
+/**
+ * The default implementation of a data binding extension point.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultDataBindingExtensionPoint implements DataBindingExtensionPoint {
+ private final Map<String, DataBinding> bindings = new HashMap<String, DataBinding>();
+ private final List<DataBinding> databindings = new ArrayList<DataBinding>();
+ private static final Logger logger = Logger.getLogger(DefaultDataBindingExtensionPoint.class.getName());
+ private boolean loadedDataBindings;
+
+ public DefaultDataBindingExtensionPoint() {
+ }
+
+ public DataBinding getDataBinding(String id) {
+ if (id == null) {
+ return null;
+ }
+ DataBinding dataBinding = bindings.get(id.toLowerCase());
+ if (dataBinding == null) {
+ loadDataBindings();
+ dataBinding = bindings.get(id.toLowerCase());
+ }
+ return dataBinding;
+ }
+
+ public void addDataBinding(DataBinding dataBinding) {
+ if (logger.isLoggable(Level.FINE)) {
+ String className = dataBinding.getClass().getName();
+ boolean lazy = false;
+ if (dataBinding instanceof LazyDataBinding) {
+ className = ((LazyDataBinding)dataBinding).dataBindingDeclaration.getClassName();
+ lazy = true;
+ }
+ logger.fine("Adding databinding: " + className + ";type=" + dataBinding.getName() + ",lazy=" + lazy);
+ }
+ databindings.add(dataBinding);
+ bindings.put(dataBinding.getName().toLowerCase(), dataBinding);
+
+ String[] aliases = dataBinding.getAliases();
+ if (aliases != null) {
+ for (String alias : aliases) {
+ bindings.put(alias.toLowerCase(), dataBinding);
+ }
+ }
+ }
+
+ public DataBinding removeDataBinding(String id) {
+ if (id == null) {
+ return null;
+ }
+ DataBinding dataBinding = bindings.remove(id.toLowerCase());
+ if (dataBinding != null) {
+ databindings.remove(dataBinding);
+ String[] aliases = dataBinding.getAliases();
+ if (aliases != null) {
+ for (String alias : aliases) {
+ bindings.remove(alias.toLowerCase());
+ }
+ }
+ }
+ return dataBinding;
+ }
+
+ /**
+ * Dynamically load data bindings declared under META-INF/services
+ */
+ private synchronized void loadDataBindings() {
+ if (loadedDataBindings)
+ return;
+
+ // Get the databinding service declarations
+ Set<ServiceDeclaration> dataBindingDeclarations;
+ try {
+ dataBindingDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(DataBinding.class);
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+
+ // Load data bindings
+ for (ServiceDeclaration dataBindingDeclaration : dataBindingDeclarations) {
+ Map<String, String> attributes = dataBindingDeclaration.getAttributes();
+ String type = attributes.get("type");
+ String name = attributes.get("name");
+
+ // Create a data binding wrapper and register it
+ DataBinding dataBinding = new LazyDataBinding(type, name, dataBindingDeclaration);
+ addDataBinding(dataBinding);
+ }
+
+ loadedDataBindings = true;
+ }
+
+ /**
+ * A data binding facade allowing data bindings to be lazily loaded and
+ * initialized.
+ */
+ private static class LazyDataBinding implements DataBinding {
+
+ private String name;
+ private String[] aliases;
+ private ServiceDeclaration dataBindingDeclaration;
+ private DataBinding dataBinding;
+
+ private LazyDataBinding(String type, String name, ServiceDeclaration dataBindingDeclaration) {
+ this.name = type;
+ if (name != null) {
+ this.aliases = new String[] {name};
+ }
+ this.dataBindingDeclaration = dataBindingDeclaration;
+ }
+
+ /**
+ * Load and instantiate the data binding class.
+ *
+ * @return The data binding.
+ */
+ @SuppressWarnings("unchecked")
+ private DataBinding getDataBinding() {
+ if (dataBinding == null) {
+ try {
+ Class<DataBinding> dataBindingClass = (Class<DataBinding>)dataBindingDeclaration.loadClass();
+ Constructor<DataBinding> constructor = dataBindingClass.getConstructor();
+ dataBinding = constructor.newInstance();
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return dataBinding;
+ }
+
+ public Object copy(Object object, DataType dataType, Operation operation) {
+ return getDataBinding().copy(object, dataType, operation);
+ }
+
+ public String[] getAliases() {
+ return aliases;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public SimpleTypeMapper getSimpleTypeMapper() {
+ return getDataBinding().getSimpleTypeMapper();
+ }
+
+ public XMLTypeHelper getXMLTypeHelper() {
+ return getDataBinding().getXMLTypeHelper();
+ }
+
+ public WrapperHandler getWrapperHandler() {
+ return getDataBinding().getWrapperHandler();
+ }
+
+ public boolean introspect(DataType dataType, Operation operation) {
+ return getDataBinding().introspect(dataType, operation);
+ }
+
+ public DataType introspect(Object value, Operation operation) {
+ return getDataBinding().introspect(value, operation);
+ }
+ }
+
+ //FIXME The following methods should not be on the extension point
+ // they should be on a separate class
+ public boolean introspectType(DataType dataType, Operation operation) {
+ loadDataBindings();
+ for (DataBinding binding : databindings) {
+ // don't introspect for JavaBeansDatabinding as all javatypes will
+ // anyways match to its basetype
+ // which is java.lang.Object. Default to this only if no databinding
+ // results
+ if (!binding.getName().equals(JavaBeansDataBinding.NAME)) {
+ if (binding.introspect(dataType, operation)) {
+ return true;
+ }
+ }
+ }
+ // FIXME: Should we honor the databinding from operation/interface
+ // level?
+ Class physical = dataType.getPhysical();
+ if (physical == Object.class) {
+ dataType.setDataBinding(JavaBeansDataBinding.NAME);
+ return false;
+ }
+ if (dataType.getPhysical().isArray()) {
+ introspectArray(dataType, operation);
+ return true;
+ } else if (Throwable.class.isAssignableFrom(physical)) {
+ dataType.setDataBinding(JavaExceptionDataBinding.NAME);
+ return true;
+ } else {
+ dataType.setDataBinding(JavaBeansDataBinding.NAME);
+ return false;
+ }
+ }
+
+ private boolean introspectArray(DataType dataType, Operation operation) {
+ Class physical = dataType.getPhysical();
+ if (!physical.isArray() || physical == byte[].class) {
+ return false;
+ }
+ Class componentType = physical.getComponentType();
+ DataType logical = new DataTypeImpl(componentType, dataType.getLogical());
+ introspectType(logical, operation);
+ dataType.setDataBinding("java:array");
+ dataType.setLogical(logical);
+ return true;
+ }
+
+ public DataType introspectType(Object value, Operation operation) {
+ loadDataBindings();
+ DataType dataType = null;
+ for (DataBinding binding : databindings) {
+ // don't introspect for JavaBeansDatabinding as all javatypes will
+ // anyways match to its basetype
+ // which is java.lang.Object. Default to this only if no databinding
+ // results
+ if (!binding.getName().equals(JavaBeansDataBinding.NAME)) {
+ dataType = binding.introspect(value, operation);
+ }
+ if (dataType != null) {
+ return dataType;
+ }
+ }
+ return new DataTypeImpl<XMLType>(JavaBeansDataBinding.NAME, value.getClass(), XMLType.UNKNOWN);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultTransformerExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultTransformerExtensionPoint.java
new file mode 100644
index 0000000000..7aa55d2cff
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/DefaultTransformerExtensionPoint.java
@@ -0,0 +1,306 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.tuscany.sca.databinding.impl.DirectedGraph;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DefaultTransformerExtensionPoint implements TransformerExtensionPoint {
+ private static final Logger logger = Logger.getLogger(DefaultTransformerExtensionPoint.class.getName());
+ private boolean loadedTransformers;
+
+ private final DirectedGraph<Object, Transformer> graph = new DirectedGraph<Object, Transformer>();
+
+ public DefaultTransformerExtensionPoint() {
+ }
+
+ public void addTransformer(String sourceType, String resultType, int weight, Transformer transformer, boolean publicTransformer) {
+ if (logger.isLoggable(Level.FINE)) {
+ String className = transformer.getClass().getName();
+ boolean lazy = false;
+ boolean pull = (transformer instanceof PullTransformer);
+ if (transformer instanceof LazyPullTransformer) {
+ className = ((LazyPullTransformer)transformer).transformerDeclaration.getClassName();
+ lazy = true;
+ }
+ if (transformer instanceof LazyPushTransformer) {
+ className = ((LazyPushTransformer)transformer).transformerDeclaration.getClassName();
+ lazy = true;
+ }
+
+ logger.fine("Adding transformer: " + className
+ + ";source="
+ + sourceType
+ + ",target="
+ + resultType
+ + ",weight="
+ + weight
+ + ",type="
+ + (pull ? "pull" : "push")
+ + ",lazy="
+ + lazy);
+ }
+ graph.addEdge(sourceType, resultType, transformer, weight, publicTransformer);
+ }
+
+ public void addTransformer(Transformer transformer, boolean publicTransformer) {
+ addTransformer(transformer.getSourceDataBinding(),
+ transformer.getTargetDataBinding(),
+ transformer.getWeight(),
+ transformer, publicTransformer);
+ }
+
+ public boolean removeTransformer(String sourceType, String resultType) {
+ return graph.removeEdge(sourceType, resultType);
+ }
+
+ public Transformer getTransformer(String sourceType, String resultType) {
+ loadTransformers();
+
+ DirectedGraph<Object, Transformer>.Edge edge = graph.getEdge(sourceType, resultType);
+ return (edge == null) ? null : edge.getValue();
+ }
+
+ /**
+ * Dynamically load transformers registered under META-INF/services.
+ *
+ */
+ private synchronized void loadTransformers() {
+ if (loadedTransformers) {
+ return;
+ }
+ loadedTransformers = true;
+ loadTransformers(PullTransformer.class);
+ loadTransformers(PushTransformer.class);
+
+ }
+
+ /**
+ * Dynamically load transformers registered under META-INF/services.
+ *
+ * @param transformerClass
+ */
+ private void loadTransformers(Class<?> transformerClass) {
+
+ // Get the transformer service declarations
+ Set<ServiceDeclaration> transformerDeclarations;
+
+ try {
+ transformerDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(transformerClass);
+
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+
+ // Load transformers
+ for (ServiceDeclaration transformerDeclaration : transformerDeclarations) {
+ Map<String, String> attributes = transformerDeclaration.getAttributes();
+
+ String source = attributes.get("source");
+ String target = attributes.get("target");
+ int weight = Integer.valueOf(attributes.get("weight"));
+ String b = attributes.get("public");
+ boolean pub = true;
+ if (b != null) {
+ pub = Boolean.valueOf(b);
+ }
+
+ // Create a transformer wrapper and register it
+ Transformer transformer;
+ if (transformerClass == PullTransformer.class) {
+ transformer = new LazyPullTransformer(source, target, weight, transformerDeclaration);
+ } else {
+ transformer = new LazyPushTransformer(source, target, weight, transformerDeclaration);
+ }
+ addTransformer(transformer, pub);
+ }
+ }
+
+ /**
+ * A transformer facade allowing transformers to be lazily loaded
+ * and initialized.
+ */
+ private static class LazyPullTransformer implements PullTransformer<Object, Object> {
+
+ private String source;
+ private String target;
+ private int weight;
+ private ServiceDeclaration transformerDeclaration;
+ private PullTransformer<Object, Object> transformer;
+
+ public LazyPullTransformer(String source, String target, int weight, ServiceDeclaration transformerDeclaration) {
+ this.source = source;
+ this.target = target;
+ this.weight = weight;
+ this.transformerDeclaration = transformerDeclaration;
+ }
+
+ /**
+ * Load and instantiate the transformer class.
+ *
+ * @return The transformer.
+ */
+ @SuppressWarnings("unchecked")
+ private PullTransformer<Object, Object> getTransformer() {
+ if (transformer == null) {
+ try {
+ Class<PullTransformer<Object, Object>> transformerClass =
+ (Class<PullTransformer<Object, Object>>)transformerDeclaration.loadClass();
+ Constructor<PullTransformer<Object, Object>> constructor = transformerClass.getConstructor();
+ transformer = constructor.newInstance();
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return transformer;
+ }
+
+ public String getSourceDataBinding() {
+ return source;
+ }
+
+ public String getTargetDataBinding() {
+ return target;
+ }
+
+ public int getWeight() {
+ return weight;
+ }
+
+ public Object transform(Object source, TransformationContext context) {
+ return getTransformer().transform(source, context);
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer sb = new StringBuffer(super.toString());
+ sb.append(";className=").append(transformerDeclaration.getClassName());
+ return sb.toString();
+ }
+ }
+
+ /**
+ * A transformer facade allowing transformers to be lazily loaded
+ * and initialized.
+ */
+ private static class LazyPushTransformer implements PushTransformer<Object, Object> {
+
+ private String source;
+ private String target;
+ private int weight;
+ private ServiceDeclaration transformerDeclaration;
+ private PushTransformer<Object, Object> transformer;
+
+ public LazyPushTransformer(String source, String target, int weight, ServiceDeclaration transformerDeclaration) {
+ this.source = source;
+ this.target = target;
+ this.weight = weight;
+ this.transformerDeclaration = transformerDeclaration;
+ }
+
+ /**
+ * Load and instantiate the transformer class.
+ *
+ * @return The transformer.
+ */
+ @SuppressWarnings("unchecked")
+ private PushTransformer<Object, Object> getTransformer() {
+ if (transformer == null) {
+ try {
+ Class<PushTransformer<Object, Object>> transformerClass =
+ (Class<PushTransformer<Object, Object>>)transformerDeclaration.loadClass();
+ Constructor<PushTransformer<Object, Object>> constructor = transformerClass.getConstructor();
+ transformer = constructor.newInstance();
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return transformer;
+ }
+
+ public String getSourceDataBinding() {
+ return source;
+ }
+
+ public String getTargetDataBinding() {
+ return target;
+ }
+
+ public int getWeight() {
+ return weight;
+ }
+
+ public void transform(Object source, Object sink, TransformationContext context) {
+ getTransformer().transform(source, sink, context);
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer sb = new StringBuffer(super.toString());
+ sb.append(";className=").append(transformerDeclaration.getClassName());
+ return sb.toString();
+ }
+ }
+
+ //FIXME The following methods should be on a different class from
+ // extension point
+
+ public List<Transformer> getTransformerChain(String sourceType, String resultType) {
+ loadTransformers();
+
+ String source = sourceType;
+ String result = resultType;
+ List<Transformer> transformers = new ArrayList<Transformer>();
+ // First check if there is a direct path, if yes, use it regardless of the weight
+ DirectedGraph<Object, Transformer>.Edge link = graph.getEdge(sourceType, resultType);
+ if (link != null) {
+ transformers.add(link.getValue());
+ } else {
+ DirectedGraph<Object, Transformer>.Path path = graph.getShortestPath(source, result);
+ if (path == null) {
+ return null;
+ }
+ for (DirectedGraph<Object, Transformer>.Edge edge : path.getEdges()) {
+ transformers.add(edge.getValue());
+ }
+ }
+ return transformers;
+ }
+
+ @Override
+ public String toString() {
+ loadTransformers();
+
+ return graph.toString();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.java
new file mode 100644
index 0000000000..6b8acfc7b4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Mediator.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding;
+
+import java.util.Map;
+
+import org.apache.tuscany.sca.interfacedef.DataType;
+
+/**
+ * This interface will be used as a Tuscany system service to perform data mediations
+ *
+ * Mediate the data from one type to the other one
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Mediator {
+
+ /**
+ * Mediate the data from the source type to the target type
+ * @param source The data to be mediated
+ * @param sourceDataType Data type for the source data
+ * @param targetDataType Data type for the target data
+ * @param context
+ * @return
+ */
+ Object mediate(Object source, DataType sourceDataType, DataType targetDataType, Map<String, 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
+ */
+ void mediate(
+ Object source,
+ Object target,
+ DataType sourceDataType,
+ DataType targetDataType,
+ Map<String, Object> context);
+
+ /**
+ * Get the DataBindings used by this mediator.
+ * @return
+ */
+ DataBindingExtensionPoint getDataBindings();
+
+ /**
+ * Get the Transformers used by this mediator.
+ * @return
+ */
+ TransformerExtensionPoint getTransformers();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PullTransformer.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PullTransformer.java
new file mode 100644
index 0000000000..81264923eb
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PullTransformer.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding;
+
+/**
+ * PullTransformer transforms data from one binding format to the other one which can be directly consumed
+ *
+ * @param <S> The source data type
+ * @param <R> the target data type
+ *
+ * @version $Rev$ $Date$
+ */
+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/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PushTransformer.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PushTransformer.java
new file mode 100644
index 0000000000..600a6477f6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/PushTransformer.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding;
+
+/**
+ * A transformer that pushes data from its source into the sink
+ *
+ * @param <S>
+ * @param <R>
+ *
+ * @version $Rev$ $Date$
+ */
+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/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/SimpleTypeMapper.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/SimpleTypeMapper.java
new file mode 100644
index 0000000000..4e6d130aa9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/SimpleTypeMapper.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Type Mapper between XML schema simple data types and java objects
+ *
+ * @version $Rev$ $Date$
+ */
+public interface SimpleTypeMapper {
+ /**
+ * Parse the XML lexical representation into a java object
+ * @param simpleType The XSD simple type
+ * @param value the XML lexical representation
+ * @param context The context of the transformation
+ * @return A java object for the XML value
+ */
+ Object toJavaObject(QName simpleType, String value, TransformationContext context);
+ /**
+ * Create the XML lexical representation for a java object
+ * @param simpleType The XSD simple type
+ * @param obj The java object
+ * @param context The context of the transformation
+ * @return The XML lexical representation
+ */
+ String toXMLLiteral(QName simpleType, Object obj, TransformationContext context);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationContext.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationContext.java
new file mode 100644
index 0000000000..9ffadd1eae
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationContext.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding;
+
+import java.util.Map;
+
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+
+/**
+ * Context for data transformation
+ *
+ * @version $Rev$ $Date$
+ */
+public interface TransformationContext {
+
+ /**
+ * @return
+ */
+ Operation getSourceOperation();
+
+ /**
+ * @param sourceOperation
+ */
+ void setSourceOperation(Operation sourceOperation);
+
+ /**
+ * @return
+ */
+ Operation getTargetOperation();
+
+ /**
+ * @param targetOperation
+ */
+ void setTargetOperation(Operation targetOperation);
+
+ /**
+ * Get the source data type
+ *
+ * @return
+ */
+ DataType getSourceDataType();
+
+ /**
+ * Get the target data type
+ *
+ * @return
+ */
+ DataType getTargetDataType();
+
+ /**
+ * Set the source data type
+ *
+ * @param sourceDataType
+ */
+ void setSourceDataType(DataType sourceDataType);
+
+ /**
+ * Set the target data type
+ *
+ * @param targetDataType
+ */
+ void setTargetDataType(DataType targetDataType);
+
+ /**
+ * Get the ClassLoader
+ *
+ * @return Returns the ClassLoader
+ */
+ ClassLoader getClassLoader();
+
+ /**
+ * Get a map of metadata
+ *
+ * @return Returns a map of the metadata
+ */
+ Map<String, Object> getMetadata();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationException.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationException.java
new file mode 100644
index 0000000000..4f949f7dff
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformationException.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding;
+
+
+/**
+ * Reports problems during data transformation
+ *
+ * @version $Rev$ $Date$
+ */
+public class TransformationException extends RuntimeException {
+
+ private static final long serialVersionUID = 7662385613693006428L;
+ private String sourceDataBinding;
+ private String targetDataBinding;
+
+ public TransformationException() {
+ super();
+ }
+
+ public TransformationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public TransformationException(String message) {
+ super(message);
+ }
+
+ public TransformationException(Throwable cause) {
+ super(cause);
+ }
+
+ public String getSourceDataBinding() {
+ return sourceDataBinding;
+ }
+
+ public void setSourceDataBinding(String sourceDataBinding) {
+ this.sourceDataBinding = sourceDataBinding;
+ }
+
+ public String getTargetDataBinding() {
+ return targetDataBinding;
+ }
+
+ public void setTargetDataBinding(String targetDataBinding) {
+ this.targetDataBinding = targetDataBinding;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Transformer.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Transformer.java
new file mode 100644
index 0000000000..2aa0ad7c15
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/Transformer.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding;
+
+/**
+ * A transformer provides the data transformation from source type to target type. The cost of the transformation is
+ * modelled as weight.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Transformer {
+ /**
+ * Get the source type that this transformer transforms data from. The type is used as the key when the transformer
+ * is registered with TransformerRegistry.
+ *
+ * @return A key identifying the source type
+ */
+ String getSourceDataBinding();
+
+ /**
+ * Get the target type that this transformer transforms data into. The type is used as the key when the transformer
+ * is registered with TransformerRegistry.
+ *
+ * @return A key identifying the target type
+ */
+ String getTargetDataBinding();
+
+ /**
+ * Get the cost of the transformation. The weight can be used to choose the most efficient path if there are more
+ * than one available from the source to the target.
+ *
+ * @return An integer representing the cost of the transformation
+ */
+ int getWeight();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformerExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformerExtensionPoint.java
new file mode 100644
index 0000000000..ee7efe4860
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/TransformerExtensionPoint.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding;
+
+import java.util.List;
+
+/**
+ * An extension point for data transformer extensions.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface TransformerExtensionPoint {
+
+ /**
+ * Register a transformer
+ *
+ * @param sourceDataBinding
+ * @param targetDataBinding
+ * @param weight
+ * @param transformer
+ * @param publicTransformer TODO
+ */
+ void addTransformer(String sourceDataBinding,
+ String targetDataBinding,
+ int weight,
+ Transformer transformer,
+ boolean publicTransformer);
+
+ /**
+ * Register a transformer
+ *
+ * @param transformer
+ * @param publicTransformer TODO
+ */
+ void addTransformer(Transformer transformer, boolean publicTransformer);
+
+ /**
+ * Unregister a transformer
+ *
+ * @param sourceDataBinding
+ * @param targetDataBinding
+ * @return
+ */
+ boolean removeTransformer(String sourceDataBinding, String targetDataBinding);
+
+ /**
+ * Get the direct Transformer which can transform data from source type to
+ * result type
+ *
+ * @param sourceDataBinding
+ * @param targetDataBinding
+ * @return
+ */
+ Transformer getTransformer(String sourceDataBinding, String targetDataBinding);
+
+ /**
+ * Get the a chain of Transformers which can transform data from source type
+ * to result type
+ *
+ * @param sourceDataBinding
+ * @param targetDataBinding
+ * @return
+ */
+ List<Transformer> getTransformerChain(String sourceDataBinding, String targetDataBinding);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/WrapperHandler.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/WrapperHandler.java
new file mode 100644
index 0000000000..a91410ed71
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/WrapperHandler.java
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+
+/**
+ * A contract for transformers to deal with wrapping/unwrapping for WSDL wrapper style operations
+ *
+ * @version $Rev$ $Date$
+ */
+public interface WrapperHandler<T> {
+ /**
+ * Create a wrapper element
+ * @param operation The operation
+ * @param input Is it for input or output
+ * @return An object representing the wrapper element
+ */
+ T create(Operation operation, boolean input);
+
+ /**
+ * Get the data type for the wrapper
+ * @param operation The operation
+ * @param input Is it for input or output?
+ * @return The data type of the wrapper, null if it's not a wrapper type
+ */
+ DataType getWrapperType(Operation operation, boolean input);
+
+ /**
+ * Check if the given data is an instance of the wrapper
+ * @param wrapper
+ * @param operation The operation
+ * @param input Input or output
+ * @return
+ */
+ boolean isInstance(Object wrapper, Operation operation, boolean input);
+
+ /**
+ * Populate the wrapper element with the child objects
+ * @param wrapper The wrapper object
+ * @param childObjects The child objects
+ * @param operation The operation
+ * @param input Is it for input or output
+ */
+ public void setChildren(T wrapper,
+ Object[] childObjects,
+ Operation operation,
+ boolean input);
+
+ /**
+ * Get a list of child elements from the wrapper
+ * @param wrapper The wrapper object
+ * @param operation The operation
+ * @param input Is it for input or output
+ * @return child elements under the wrapper
+ */
+ List getChildren(T wrapper, Operation operation, boolean input);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/XMLTypeHelper.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/XMLTypeHelper.java
new file mode 100644
index 0000000000..e940f8675f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/XMLTypeHelper.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.util.TypeInfo;
+import org.apache.tuscany.sca.xsd.XSDFactory;
+import org.apache.tuscany.sca.xsd.XSDefinition;
+
+/**
+ * XML and schema helper for Java types
+ */
+public interface XMLTypeHelper {
+
+ // FIXME: This method seems to require the XMLHelper instance to be stateful
+ /**
+ * Convert a Java type into XML type information
+ * @param javaType the physical Java class
+ * @param logical the logical type information
+ * @return the XML type information
+ */
+ TypeInfo getTypeInfo(Class javaType, Object logical);
+
+ /**
+ * Get schema definitions for the Java types known to this helper
+ * @return A list of schema definitions
+ */
+ // List<XSDefinition> getSchemaDefinitions(XSDFactory factory, ModelResolver resolver);
+
+ /**
+ * Get a list of XML schemas for the given data types
+ * @param factory
+ * @param resolver
+ * @param dataTypes
+ * @return
+ */
+ List<XSDefinition> getSchemaDefinitions(XSDFactory factory, ModelResolver resolver, List<DataType> dataTypes);
+ /**
+ * Get a list of XML schemas for the given interface
+ * @param factory
+ * @param resolver
+ * @param intf
+ * @return
+ */
+ List<XSDefinition> getSchemaDefinitions(XSDFactory factory, ModelResolver resolver, Interface intf);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataBinding.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataBinding.java
new file mode 100644
index 0000000000..4405077e29
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataBinding.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.annotation;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Used to demarcate the mapping style for an interface or operation
+ *
+ * @version $Rev$ $Date$
+ */
+// FIXME: [rfeng] We should consider to use javax.jws.soap.SOAPBinding
+@Target({TYPE, METHOD})
+@Retention(RUNTIME)
+public @interface DataBinding {
+
+ /**
+ * Indicate the effective databinding that controls the WSDL/Java mapping of the
+ * interface/operation
+ *
+ * @return the data binding with the MIME media type syntax
+ */
+ String value();
+
+ /**
+ * Indicate if the operation is mapped using WRAPPED or BARE style. Originated from
+ * javax.jws.soap.SOAPBinding.ParameterStyle: Determines whether method parameters
+ * represent the entire message body, or whether the parameters are elements wrapped
+ * inside a top-level element named after the operation
+ *
+ * @return true if the parameter style is WRAPPED, false if BARE
+ */
+ boolean wrapped() default false;
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataType.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataType.java
new file mode 100644
index 0000000000..650e909c61
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/annotation/DataType.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.annotation;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Used to demarcate expected data types for parameters and return type
+ *
+ * @version $Rev$ $Date$
+ */
+@Target( {METHOD, PARAMETER})
+@Retention(RUNTIME)
+public @interface DataType {
+
+ /**
+ * Returns the data binding configuration in MIME media type syntax
+ * @return the data binding
+ */
+ String value();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/externalizable/ExternalizableDataBinding.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/externalizable/ExternalizableDataBinding.java
new file mode 100644
index 0000000000..640a43f55d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/externalizable/ExternalizableDataBinding.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.externalizable;
+
+import org.apache.tuscany.sca.databinding.impl.BaseDataBinding;
+
+/**
+ * DataNinding for Externalizable objects.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ExternalizableDataBinding extends BaseDataBinding {
+
+ public static final String NAME = java.io.Externalizable.class.getName();
+ public static final String[] ALIASES = new String[] {"externalizable"};
+
+ public ExternalizableDataBinding() {
+ super(NAME, ALIASES, java.io.Externalizable.class);
+ }
+
+
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseDataBinding.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseDataBinding.java
new file mode 100644
index 0000000000..4bbcf7ddef
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseDataBinding.java
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.impl;
+
+
+import org.apache.tuscany.sca.databinding.DataBinding;
+import org.apache.tuscany.sca.databinding.SimpleTypeMapper;
+import org.apache.tuscany.sca.databinding.WrapperHandler;
+import org.apache.tuscany.sca.databinding.XMLTypeHelper;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+
+/**
+ * Base Implementation of DataBinding
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class BaseDataBinding implements DataBinding {
+
+ private Class<?> baseType;
+
+ private String name;
+ private String[] aliases;
+
+ /**
+ * Create a databinding with the base java type whose name will be used as
+ * the name of the databinding
+ *
+ * @param baseType The base java class or interface representing the
+ * databinding, for example, org.w3c.dom.Node
+ */
+ protected BaseDataBinding(Class<?> baseType) {
+ this(baseType.getName(), null, baseType);
+ }
+
+ /**
+ * Create a databinding with the name and base java type
+ *
+ * @param name The name of the databinding
+ * @param baseType The base java class or interface representing the
+ * databinding, for example, org.w3c.dom.Node
+ */
+ protected BaseDataBinding(String name, Class<?> baseType) {
+ this(name, null, baseType);
+ }
+
+ /**
+ * Create a databinding with the name and base java type
+ *
+ * @param name The name of the databinding
+ * @param aliases The aliases of the databinding
+ * @param baseType The base java class or interface representing the
+ * databinding, for example, org.w3c.dom.Node
+ */
+ protected BaseDataBinding(String name, String[] aliases, Class<?> baseType) {
+ this.name = name;
+ this.baseType = baseType;
+ this.aliases = aliases;
+ }
+
+ @SuppressWarnings("unchecked")
+ public boolean introspect(DataType type, Operation operation) {
+ assert type != null;
+ Class cls = type.getPhysical();
+ if (baseType != null && baseType.isAssignableFrom(cls)) {
+ type.setDataBinding(getName());
+ if (type.getLogical() == null) {
+ type.setLogical(XMLType.UNKNOWN);
+ }
+ return true;
+ }
+ return false;
+ }
+
+ public DataType introspect(Object value, Operation operation) {
+ if (value == null) {
+ return null;
+ } else {
+ DataType<Class> dataType = new DataTypeImpl<Class>(value.getClass(), value.getClass());
+ if (introspect(dataType, (Operation) null)) {
+ return dataType;
+ } else {
+ return null;
+ }
+ }
+ }
+
+ public final String getName() {
+ return name;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.DataBinding#getWrapperHandler()
+ */
+ public WrapperHandler getWrapperHandler() {
+ return null;
+ }
+
+ public Object copy(Object object, DataType dataType, Operation operation) {
+ return object;
+ }
+
+ public SimpleTypeMapper getSimpleTypeMapper() {
+ return new SimpleTypeMapperImpl();
+ }
+
+ public XMLTypeHelper getXMLTypeHelper() {
+ return null;
+ }
+
+ public String[] getAliases() {
+ return aliases;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseTransformer.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseTransformer.java
new file mode 100644
index 0000000000..94a2cdb0bb
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/BaseTransformer.java
@@ -0,0 +1,52 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.impl;
+
+import org.apache.tuscany.sca.databinding.Transformer;
+
+/**
+ * Base Implementation of Transformer which provides the registration to the
+ * transformer registry
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class BaseTransformer<S, T> implements Transformer {
+
+ protected BaseTransformer() {
+ super();
+ }
+
+ protected abstract Class<S> getSourceType();
+
+ protected abstract Class<T> getTargetType();
+
+ public String getSourceDataBinding() {
+ return getSourceType().getName();
+ }
+
+ public String getTargetDataBinding() {
+ return getTargetType().getName();
+ }
+
+ public int getWeight() {
+ // default to 50
+ return 50;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java
new file mode 100644
index 0000000000..64b3d22c10
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DOMHelper.java
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.impl;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+
+/**
+ * Helper for DOM
+ *
+ * @version $Rev$ $Date$
+ */
+public final class DOMHelper {
+ private static DocumentBuilderFactory FACTORY;
+
+ private DOMHelper() {
+ }
+
+ public static Document newDocument() throws ParserConfigurationException {
+ return newDocumentBuilder().newDocument();
+ }
+
+ public static DocumentBuilder newDocumentBuilder() throws ParserConfigurationException {
+ init();
+ return FACTORY.newDocumentBuilder();
+ }
+
+ /**
+ *
+ */
+ private static synchronized void init() {
+ if (FACTORY == null) {
+ FACTORY = DocumentBuilderFactory.newInstance();
+ FACTORY.setNamespaceAware(true);
+ }
+ }
+
+ public static QName getQName(Node node) {
+ String ns = node.getNamespaceURI();
+ if (ns == null) {
+ ns = "";
+ }
+ // node.getLocalName() will return null if it is created using DOM Level
+ // 1 method
+ // such as createElement()
+ return new QName(ns, node.getNodeName());
+ }
+
+ public static Element createElement(Document document, QName name) {
+ String prefix = name.getPrefix();
+ String qname =
+ (prefix != null && prefix.length() > 0) ? prefix + ":" + name.getLocalPart() : name.getLocalPart();
+ return document.createElementNS(name.getNamespaceURI(), qname);
+ }
+
+ /**
+ * Wrap an element as a DOM document
+ * @param node
+ * @return
+ */
+ public static Document promote(Node node) {
+ if (node instanceof Document) {
+ return (Document)node;
+ }
+ Element element = (Element)node;
+ Document doc = element.getOwnerDocument();
+ if (doc.getDocumentElement() == element) {
+ return doc;
+ }
+ doc = (Document)element.getOwnerDocument().cloneNode(false);
+ Element schema = (Element)doc.importNode(element, true);
+ doc.appendChild(schema);
+ Node parent = element.getParentNode();
+ while (parent instanceof Element) {
+ Element root = (Element)parent;
+ NamedNodeMap nodeMap = root.getAttributes();
+ for (int i = 0; i < nodeMap.getLength(); i++) {
+ Attr attr = (Attr)nodeMap.item(i);
+ String name = attr.getName();
+ if ("xmlns".equals(name) || name.startsWith("xmlns:")) {
+ if (schema.getAttributeNode(name) == null) {
+ schema.setAttributeNodeNS((Attr)doc.importNode(attr, true));
+ }
+ }
+ }
+ parent = parent.getParentNode();
+ }
+ return doc;
+ }
+
+ /**
+ * @param context
+ * @param element
+ */
+ public static Element adjustElementName(TransformationContext context, Element element) {
+ if (context != null) {
+ DataType dataType = context.getTargetDataType();
+ Object logical = dataType == null ? null : dataType.getLogical();
+ if (!(logical instanceof XMLType)) {
+ return element;
+ }
+ XMLType xmlType = (XMLType)logical;
+ QName name = new QName(element.getNamespaceURI(), element.getLocalName());
+ if (xmlType.isElement() && !xmlType.getElementName().equals(name)) {
+ QName newName = xmlType.getElementName();
+ String prefix = newName.getPrefix();
+ String qname = newName.getLocalPart();
+ if (prefix != null && !prefix.equals("")) {
+ qname = prefix + ":" + qname;
+ }
+ Document doc = element.getOwnerDocument();
+ Element newElement = doc.createElementNS(newName.getNamespaceURI(), qname);
+ // Copy the attributes to the new element
+ NamedNodeMap attrs = element.getAttributes();
+ for (int i = 0; i < attrs.getLength(); i++) {
+ Attr attr = (Attr)doc.importNode(attrs.item(i), true);
+ newElement.getAttributes().setNamedItem(attr);
+ }
+
+ // Move all the children
+ while (element.hasChildNodes()) {
+ newElement.appendChild(element.getFirstChild());
+ }
+
+ // Replace the old node with the new node
+ if (element.getParentNode() != null) {
+ element.getParentNode().replaceChild(newElement, element);
+ }
+
+ return newElement;
+ }
+ }
+ return element;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DirectedGraph.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DirectedGraph.java
new file mode 100644
index 0000000000..01916dfb96
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/DirectedGraph.java
@@ -0,0 +1,452 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.impl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Directed, weighted graph
+ *
+ * @param <V> The type of vertex object
+ * @param <E> The type of edge object
+ *
+ * @version $Rev$ $Date$
+ */
+public class DirectedGraph<V, E> implements Cloneable {
+ 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;
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ if (!VertexPair.class.isInstance(object)) {
+ return false;
+ }
+ VertexPair pair = (VertexPair)object;
+ return source == pair.source && target == pair.target;
+ }
+
+ @Override
+ public int hashCode() {
+ int x = source == null ? 0 : source.hashCode();
+ int y = target == null ? 0 : target.hashCode();
+ return x ^ y;
+ }
+
+ }
+
+ // Fix for TUSCANY-2069, making the map concurrent
+ private final Map<VertexPair, Path> paths = new ConcurrentHashMap<VertexPair, Path>();
+ private final Path NULL_PATH = new Path();
+
+ /**
+ * Vertex of a graph
+ */
+ public final class Vertex {
+ private V value;
+
+ // TODO: Do we want to support multiple edges for a vertex pair? If so,
+ // we should use a List instead of Map
+ private Map<Vertex, Edge> outEdges = new HashMap<Vertex, Edge>();
+ private Map<Vertex, Edge> inEdges = new HashMap<Vertex, Edge>();
+
+ private Vertex(V value) {
+ this.value = value;
+ }
+
+ @Override
+ public String toString() {
+ return "(" + value + ")";
+ }
+
+ public V getValue() {
+ return value;
+ }
+
+ public Map<Vertex, Edge> getOutEdges() {
+ return outEdges;
+ }
+
+ public Map<Vertex, Edge> getInEdges() {
+ return inEdges;
+ }
+
+ }
+
+ /**
+ * An Edge connects two vertices in one direction
+ */
+ public final class Edge {
+ private Vertex sourceVertex;
+
+ private Vertex targetVertex;
+
+ private E value;
+
+ private int weight;
+
+ private boolean pub = true;
+
+ public Edge(Vertex source, Vertex target, E value, int weight, boolean pub) {
+ this.sourceVertex = source;
+ this.targetVertex = target;
+ this.value = value;
+ this.weight = weight;
+ this.pub = pub;
+ }
+
+ @Override
+ public String toString() {
+ return sourceVertex + "->" + targetVertex + "[" + value + "," + weight + "]";
+ }
+
+ public E getValue() {
+ return value;
+ }
+
+ public void setValue(E value) {
+ this.value = value;
+ }
+
+ public Vertex getTargetVertex() {
+ return targetVertex;
+ }
+
+ public void setTargetVertex(Vertex vertex) {
+ this.targetVertex = vertex;
+ }
+
+ public int getWeight() {
+ return weight;
+ }
+
+ public void setWeight(int weight) {
+ this.weight = weight;
+ }
+
+ public Vertex getSourceVertex() {
+ return sourceVertex;
+ }
+
+ public void setSourceVertex(Vertex sourceVertex) {
+ this.sourceVertex = sourceVertex;
+ }
+
+ public boolean isPublic() {
+ return pub;
+ }
+
+ public void setPublic(boolean pub) {
+ this.pub = pub;
+ }
+ }
+
+ private final class Node implements Comparable<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, boolean publicEdge) {
+ Vertex s = getVertex(source);
+ if (s == null) {
+ s = new Vertex(source);
+ vertices.put(source, s);
+ }
+ Vertex t = getVertex(target);
+ if (t == null) {
+ t = new Vertex(target);
+ vertices.put(target, t);
+ }
+ Edge edge = new Edge(s, t, edgeValue, weight, publicEdge);
+ s.outEdges.put(t, edge);
+ t.inEdges.put(s, edge);
+ }
+
+ public void addEdge(V soure, V target) {
+ addEdge(soure, target, null, 0, true);
+ }
+
+ public Vertex getVertex(V source) {
+ Vertex s = vertices.get(source);
+ return s;
+ }
+
+ public boolean removeEdge(V source, V target) {
+ Vertex s = getVertex(source);
+ if (s == null) {
+ return false;
+ }
+
+ Vertex t = getVertex(target);
+ if (t == null) {
+ return false;
+ }
+
+ return s.outEdges.remove(t) != null && t.inEdges.remove(s) != null;
+
+ }
+
+ public void removeEdge(Edge edge) {
+ edge.sourceVertex.outEdges.remove(edge.targetVertex);
+ edge.targetVertex.inEdges.remove(edge.sourceVertex);
+ }
+
+ public void removeVertex(Vertex vertex) {
+ vertices.remove(vertex.getValue());
+ for (Edge e : new ArrayList<Edge>(vertex.outEdges.values())) {
+ removeEdge(e);
+ }
+ for (Edge e : new ArrayList<Edge>(vertex.inEdges.values())) {
+ removeEdge(e);
+ }
+ }
+
+ public Edge getEdge(Vertex source, Vertex target) {
+ return source.outEdges.get(target);
+ }
+
+ public Edge getEdge(V source, V target) {
+ Vertex sv = getVertex(source);
+ if (sv == null) {
+ return null;
+ }
+ Vertex tv = getVertex(target);
+ if (tv == null) {
+ return null;
+ }
+ return getEdge(getVertex(source), getVertex(target));
+ }
+
+ /**
+ * Get the shortest path from the source vertex to the target vertex using
+ * Dijkstra's algorithm. If there's no path, null will be returned. If the
+ * source is the same as the target, it returns a path with empty edges with
+ * weight 0.
+ *
+ * @param sourceValue The value identifies the source
+ * @param targetValue The value identifies the target
+ * @return The shortest path
+ */
+ public Path getShortestPath(V sourceValue, V targetValue) {
+ Vertex source = getVertex(sourceValue);
+ if (source == null) {
+ return null;
+ }
+ Vertex target = getVertex(targetValue);
+ if (target == null) {
+ return null;
+ }
+
+ VertexPair pair = new VertexPair(source, target);
+ Path path = null;
+ if (paths.containsKey(pair)) {
+ path = paths.get(pair);
+ return path == NULL_PATH? null: path;
+ }
+
+ // Check if there is a direct link, if yes, use it instead
+ Edge direct = getEdge(source, target);
+ path = new Path();
+ if (direct != null) {
+ path.addEdge(direct);
+ paths.put(pair, path);
+ return path;
+ }
+
+ Map<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>();
+ Node nextNode = null;
+ while (!otherNodes.isEmpty()) {
+ nextNode = extractMin(otherNodes);
+ if (nextNode.vertex == target) {
+ path = getPath(nextNode);
+ paths.put(pair, path); // Cache it
+ return path == NULL_PATH? null: path;
+ }
+ nodesOnPath.add(nextNode);
+ for (Edge edge : nextNode.vertex.outEdges.values()) {
+ Node adjacentNode = nodes.get(edge.targetVertex);
+ // The private edge can only be used if the edge connects to the target directly
+ if (edge.isPublic() || edge.getTargetVertex() == target) {
+ if (nextNode.distance + edge.weight < adjacentNode.distance) {
+ adjacentNode.distance = nextNode.distance + edge.weight;
+ adjacentNode.previous = nextNode;
+ }
+ }
+ }
+ }
+ paths.put(pair, NULL_PATH); // Cache it
+ return null;
+ }
+
+ /**
+ * Searches for the vertex u in the vertex set Q that has the least d[u]
+ * value. That vertex is removed from the set Q and returned to the user.
+ *
+ * @param nodes
+ * @return
+ */
+ private Node extractMin(Set<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;
+ }
+
+ @Override
+ public String toString() {
+ return edges + ", " + weight;
+ }
+ }
+
+ private Path getPath(Node t) {
+ if (t.distance == Integer.MAX_VALUE) {
+ return NULL_PATH;
+ }
+ Path path = new Path();
+ Node u = t;
+ while (u.previous != null) {
+ Edge edge = getEdge(u.previous.vertex, u.vertex);
+ path.addEdge(edge);
+ u = u.previous;
+ }
+ return path;
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ for (Vertex v : vertices.values()) {
+ sb.append(v.outEdges.values()).append("\n");
+ }
+ return sb.toString();
+ }
+
+ public Map<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, true);
+ }
+ }
+ }
+
+ private Vertex getFirst() {
+ for (Vertex v : vertices.values()) {
+ if (v.inEdges.isEmpty()) {
+ return v;
+ }
+ }
+ if (!vertices.isEmpty()) {
+ throw new IllegalArgumentException("Circular ordering has been detected: " + toString());
+ } else {
+ return null;
+ }
+ }
+
+ public List<V> topologicalSort(boolean readOnly) {
+ DirectedGraph<V, E> graph = (!readOnly) ? this : (DirectedGraph<V, E>)clone();
+ List<V> list = new ArrayList<V>();
+ while (true) {
+ Vertex v = graph.getFirst();
+ if (v == null) {
+ break;
+ }
+ list.add(v.getValue());
+ graph.removeVertex(v);
+ }
+
+ return list;
+ }
+
+ @Override
+ public Object clone() {
+ DirectedGraph<V, E> copy = new DirectedGraph<V, E>();
+ copy.addGraph(this);
+ return copy;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Group2GroupTransformer.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Group2GroupTransformer.java
new file mode 100644
index 0000000000..cc7b40d06b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Group2GroupTransformer.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.impl;
+
+import org.apache.tuscany.sca.databinding.Mediator;
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.interfacedef.DataType;
+
+/**
+ * This is a special transformer to transform the output from one IDL to the
+ * other one
+ *
+ * @version $Rev$ $Date$
+ */
+public class Group2GroupTransformer extends BaseTransformer<Object, Object> implements
+ PullTransformer<Object, Object> {
+
+ protected Mediator mediator;
+
+ /**
+ * @param wrapperHandler
+ */
+ public Group2GroupTransformer() {
+ super();
+ }
+
+ /**
+ * @param mediator the mediator to set
+ */
+ public void setMediator(Mediator mediator) {
+ this.mediator = mediator;
+ }
+
+ @Override
+ public String getSourceDataBinding() {
+ return GroupDataBinding.NAME;
+ }
+
+ @Override
+ public String getTargetDataBinding() {
+ return GroupDataBinding.NAME;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getSourceType()
+ */
+ @Override
+ protected Class<Object> getSourceType() {
+ return Object.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.impl.BaseTransformer#getTargetType()
+ */
+ @Override
+ protected Class<Object> getTargetType() {
+ return Object.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.Transformer#getWeight()
+ */
+ @Override
+ public int getWeight() {
+ return 10;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object transform(Object source, TransformationContext context) {
+ DataType<DataType> sourceType = context.getSourceDataType();
+ DataType<DataType> targetType = context.getTargetDataType();
+
+ return mediator.mediate(source, sourceType.getLogical(), targetType.getLogical(), context.getMetadata());
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/GroupDataBinding.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/GroupDataBinding.java
new file mode 100644
index 0000000000..4a918488c5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/GroupDataBinding.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.impl;
+
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+
+/**
+ * The base class for a special databinding which represents a group of other databindings
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class GroupDataBinding extends BaseDataBinding {
+ public static final String NAME = "databinding:group";
+
+ /**
+ * Marker type is a java class or interface representing the data format.
+ */
+ protected Class[] markerTypes;
+
+ public GroupDataBinding(Class[] types) {
+ super(NAME, null, GroupDataBinding.class);
+ this.markerTypes = types;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public boolean introspect(DataType type, Operation operation) {
+ if (markerTypes == null) {
+ return false;
+ }
+ Type physical = type.getPhysical();
+ if (physical instanceof ParameterizedType) {
+ physical = ((ParameterizedType)physical).getRawType();
+ }
+ if (!(physical instanceof Class)) {
+ return false;
+ }
+ Class cls = (Class)physical;
+ for (Class<?> c : markerTypes) {
+ if (isTypeOf(c, cls)) {
+ type.setDataBinding(getDataBinding(c));
+ Object logical = getLogical(cls, null);
+ if (logical != null) {
+ type.setLogical(getLogical(cls, null));
+ } else {
+ type.setLogical(XMLType.UNKNOWN);
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Test if the given type is a subtype of the base type
+ * @param markerType
+ * @param type
+ * @return
+ */
+ protected boolean isTypeOf(Class<?> markerType, Class<?> type) {
+ return markerType.isAssignableFrom(type);
+ }
+
+ /**
+ * Derive the databinding name from a base class
+ * @param baseType
+ * @return
+ */
+ protected String getDataBinding(Class<?> baseType) {
+ return baseType.getName();
+ }
+
+ /**
+ * Get the logical type
+ * @param type The java type
+ * @param operation TODO
+ * @return
+ */
+ protected abstract Object getLogical(Class<?> type, Operation operation);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Java2SimpleTypeTransformer.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Java2SimpleTypeTransformer.java
new file mode 100644
index 0000000000..45896ca6a1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/Java2SimpleTypeTransformer.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.impl;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.SimpleTypeMapper;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+
+/**
+ * Transformer to convert data from a simple java object to a databinding's representation
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class Java2SimpleTypeTransformer<T> extends BaseTransformer<Object, T> implements
+ PullTransformer<Object, T> {
+
+ protected SimpleTypeMapper mapper;
+
+ public Java2SimpleTypeTransformer() {
+ this.mapper = new SimpleTypeMapperImpl();
+ }
+
+ public Java2SimpleTypeTransformer(SimpleTypeMapper mapper) {
+ this.mapper = (mapper != null) ? mapper : new SimpleTypeMapperImpl();
+ }
+
+ public T transform(Object source, TransformationContext context) {
+ XMLType xmlType = (XMLType) context.getTargetDataType().getLogical();
+ String text = mapper.toXMLLiteral(xmlType.getTypeName(), source, context);
+ return createElement(xmlType.getElementName(), text, context);
+ }
+
+ @Override
+ public Class<Object> getSourceType() {
+ return Object.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 10000;
+ }
+
+ protected abstract T createElement(QName element, String literal, TransformationContext context);
+
+ @Override
+ public String getSourceDataBinding() {
+ return SimpleJavaDataBinding.NAME;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java
new file mode 100644
index 0000000000..b7ddf87a41
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/MediatorImpl.java
@@ -0,0 +1,182 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.impl;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.databinding.DataPipe;
+import org.apache.tuscany.sca.databinding.DataPipeTransformer;
+import org.apache.tuscany.sca.databinding.Mediator;
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.PushTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.Transformer;
+import org.apache.tuscany.sca.databinding.TransformerExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
+
+/**
+ * Default Mediator implementation
+ *
+ * @version $Rev$ $Date$
+ */
+public class MediatorImpl implements Mediator {
+
+ private DataBindingExtensionPoint dataBindings;
+ private TransformerExtensionPoint transformers;
+
+ public MediatorImpl(DataBindingExtensionPoint dataBindings, TransformerExtensionPoint transformers) {
+ this.dataBindings = dataBindings;
+ this.transformers = transformers;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object mediate(Object source, DataType sourceDataType, DataType targetDataType, Map<String, Object> metadata) {
+ if (sourceDataType == null || sourceDataType.getDataBinding() == null) {
+ if (source != null) {
+ Operation operation = (Operation) metadata.get("source.operation");
+ sourceDataType = dataBindings.introspectType(source, operation);
+ }
+ }
+ if (sourceDataType == null || targetDataType == null) {
+ return source;
+ } else if (sourceDataType.equals(targetDataType)) {
+ return source;
+ }
+
+ List<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) {
+ DataPipeTransformer dataPipeFactory = (i < size - 1) ? (DataPipeTransformer)path.get(++i) : null;
+ DataPipe dataPipe = dataPipeFactory == null ? null : dataPipeFactory.newInstance();
+ ((PushTransformer)transformer).transform(result, dataPipe.getSink(), context);
+ result = dataPipe.getResult();
+ }
+ i++;
+ }
+
+ return result;
+ }
+
+ private TransformationContext createTransformationContext(DataType sourceDataType,
+ DataType targetDataType,
+ int size,
+ int index,
+ Transformer transformer,
+ Map<String, Object> metadata) {
+ DataType sourceType =
+ (index == 0) ? sourceDataType : new DataTypeImpl<Object>(transformer.getSourceDataBinding(), Object.class,
+ sourceDataType.getLogical());
+ DataType targetType =
+ (index == size - 1) ? targetDataType : new DataTypeImpl<Object>(transformer.getTargetDataBinding(),
+ Object.class, targetDataType.getLogical());
+
+ //FIXME The ClassLoader should be passed in
+ // Allow privileged access to get ClassLoader. Requires RuntimePermission in security
+ // policy.
+ ClassLoader classLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() {
+ public ClassLoader run() {
+ return 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<String, Object> metadata) {
+ if (source == null) {
+ // Shortcut for null value
+ return;
+ }
+ if (sourceDataType == null || sourceDataType.getDataBinding() == null) {
+ Operation operation = (Operation) metadata.get("source.operation");
+ sourceDataType = dataBindings.introspectType(source, operation);
+ }
+ if (sourceDataType == null) {
+ return;
+ } else if (sourceDataType.equals(targetDataType)) {
+ return;
+ }
+
+ List<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) {
+ DataPipeTransformer dataPipeFactory = (i < size - 1) ? (DataPipeTransformer)path.get(++i) : null;
+ DataPipe dataPipe = dataPipeFactory == null ? null : dataPipeFactory.newInstance();
+ Object sink = dataPipe != null ? dataPipe.getSink() : target;
+ ((PushTransformer)transformer).transform(result, sink, context);
+ result = (dataPipe != null) ? dataPipe.getResult() : null;
+ }
+ }
+ }
+
+ private List<Transformer> getTransformerChain(DataType sourceDataType, DataType targetDataType) {
+ String sourceId = sourceDataType.getDataBinding();
+ String targetId = targetDataType.getDataBinding();
+ List<Transformer> path = transformers.getTransformerChain(sourceId, targetId);
+ if (path == null) {
+ TransformationException ex =
+ new TransformationException("No path found for the transformation: " + sourceId + "->" + targetId);
+ ex.setSourceDataBinding(sourceId);
+ ex.setTargetDataBinding(targetId);
+ throw ex;
+ }
+ return path;
+ }
+
+ public DataBindingExtensionPoint getDataBindings() {
+ return dataBindings;
+ }
+
+ public TransformerExtensionPoint getTransformers() {
+ return transformers;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/PipedTransformer.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/PipedTransformer.java
new file mode 100644
index 0000000000..a1a89005b3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/PipedTransformer.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.impl;
+
+import org.apache.tuscany.sca.databinding.DataPipe;
+import org.apache.tuscany.sca.databinding.DataPipeTransformer;
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.PushTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+
+/**
+ * A utility class to connect PushTransformer and DataPipe to create a
+ * PullTransformer
+ *
+ * @param <S> Source type
+ * @param <I> Intermediate type
+ * @param <R> Result type
+ *
+ * @version $Rev$ $Date$
+ */
+public class PipedTransformer<S, I, R> implements PullTransformer<S, R> {
+ private PushTransformer<S, I> pusher;
+
+ private DataPipeTransformer<I, R> pipe;
+
+ /**
+ * @param pumper
+ * @param pipe
+ */
+ public PipedTransformer(PushTransformer<S, I> pumper, DataPipeTransformer<I, R> pipe) {
+ super();
+ this.pusher = pumper;
+ this.pipe = pipe;
+ }
+
+ public R transform(S source, TransformationContext context) {
+ DataPipe<I, R> dataPipe = pipe.newInstance();
+ pusher.transform(source, dataPipe.getSink(), context);
+ return dataPipe.getResult();
+ }
+
+ public String getSourceDataBinding() {
+ return pusher.getSourceDataBinding();
+ }
+
+ public String getTargetDataBinding() {
+ return pipe.getTargetDataBinding();
+ }
+
+ public int getWeight() {
+ return pusher.getWeight() + pipe.getWeight();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleType2JavaTransformer.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleType2JavaTransformer.java
new file mode 100644
index 0000000000..c91176fc2c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleType2JavaTransformer.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.impl;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.SimpleTypeMapper;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+
+/**
+ * Transformer to convert data from a databinding's representation of simple
+ * types to Java Objects
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class SimpleType2JavaTransformer<T> extends BaseTransformer<T, Object> implements
+ PullTransformer<T, Object> {
+
+ protected SimpleTypeMapper mapper;
+
+ public SimpleType2JavaTransformer() {
+ this.mapper = new SimpleTypeMapperImpl();
+ }
+
+ public SimpleType2JavaTransformer(SimpleTypeMapper mapper) {
+ this.mapper = (mapper != null) ? mapper : new SimpleTypeMapperImpl();
+ }
+
+ public Object transform(T source, TransformationContext context) {
+ XMLType xmlType = (XMLType)context.getSourceDataType().getLogical();
+ QName type = (xmlType != null) ? xmlType.getTypeName() : null;
+ if (type == null) {
+ xmlType = (XMLType)context.getTargetDataType().getLogical();
+ type = (xmlType != null) ? xmlType.getTypeName() : null;
+ }
+ Object result = mapper.toJavaObject(type, getText(source), context);
+ close(source);
+ return result;
+ }
+
+ @Override
+ protected Class<Object> getTargetType() {
+ return Object.class;
+ }
+
+ @Override
+ public int getWeight() {
+ // Cannot be used for intermediate
+ return 10000;
+ }
+
+ /**
+ * Get the string value from the source
+ * @param source
+ * @return A string
+ */
+ protected abstract String getText(T source);
+
+ /**
+ * To be overrided by the subclass
+ * @param source
+ */
+ protected void close(T source) {
+ }
+
+ @Override
+ public String getTargetDataBinding() {
+ return SimpleJavaDataBinding.NAME;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleTypeMapperImpl.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleTypeMapperImpl.java
new file mode 100644
index 0000000000..32a2313f59
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/SimpleTypeMapperImpl.java
@@ -0,0 +1,401 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.impl;
+
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.XMLGregorianCalendar;
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.databinding.SimpleTypeMapper;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.interfacedef.util.TypeInfo;
+
+/**
+ * Simple type mapper that maps from XSD types to Java Classes and Java Classes to XSD types.
+ *
+ * @version $Rev$ $Date$
+ */
+public class SimpleTypeMapperImpl extends XSDDataTypeConverter implements SimpleTypeMapper {
+
+ public static final Map<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 DatatypeFactory factory;
+
+ public SimpleTypeMapperImpl() {
+ super();
+ try {
+ this.factory = DatatypeFactory.newInstance();
+ } catch (DatatypeConfigurationException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ public static Class getJavaType(QName xmlType) {
+ if (xmlType != null && URI_2001_SCHEMA_XSD.equals(xmlType.getNamespaceURI())) {
+ return XML2JAVA.get(xmlType.getLocalPart());
+ } else {
+ return null;
+ }
+ }
+
+ public static TypeInfo getXMLType(Class javaType) {
+ return XSD_SIMPLE_TYPES.get(JAVA2XML.get(javaType));
+ }
+
+ public Object toJavaObject(QName simpleType, String literal, TransformationContext context) {
+ /**
+ * <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();
+
+ QName type = simpleType;
+ if (type.equals(XSD_STRING)) {
+ return parseString(value);
+ } else if (type.equals(XSD_INT)) {
+ return parseInt(value);
+ } else if (type.equals(XSD_INTEGER)) {
+ return parseInteger(value);
+ } else if (type.equals(XSD_INT)) {
+ return parseInt(value);
+ } else if (type.equals(XSD_FLOAT)) {
+ return parseFloat(value);
+ } else if (type.equals(XSD_DOUBLE)) {
+ return parseDouble(value);
+ } else if (type.equals(XSD_SHORT)) {
+ return parseShort(value);
+ } else if (type.equals(XSD_DECIMAL)) {
+ return parseDecimal(value);
+ } else if (type.equals(XSD_BOOLEAN)) {
+ return parseBoolean(value);
+ } else if (type.equals(XSD_BYTE)) {
+ return parseByte(value);
+ } else if (type.equals(XSD_LONG)) {
+ return parseLong(value);
+ } else if (type.equals(XSD_UNSIGNEDBYTE)) {
+ return parseUnsignedShort(value);
+ } else if (type.equals(XSD_UNSIGNEDSHORT)) {
+ return parseUnsignedShort(value);
+ } else if (type.equals(XSD_UNSIGNEDINT)) {
+ return parseUnsignedInt(value);
+ } else if (type.equals(XSD_UNSIGNEDLONG)) {
+ return parseUnsignedInt(value);
+ } else if (type.equals(XSD_DATETIME)) {
+ return parseDateTime(value);
+ } else if (type.equals(XSD_DATE)) {
+ return parseDate(value);
+ } else if (type.equals(XSD_TIME)) {
+ return parseTime(value);
+ } else if (type.equals(XSD_DURATION)) {
+ return parseDuration(value);
+ } else if (type.equals(XSD_HEXBIN)) {
+ return parseHexBinary(value);
+ } else if (type.equals(XSD_BASE64)) {
+ return parseBase64Binary(value);
+ } else if (type.equals(XSD_QNAME)) {
+ NamespaceContext namespaceContext =
+ (NamespaceContext)((context != null) ? context.getMetadata().get(NamespaceContext.class.getName()) : null);
+ return parseQName(value, namespaceContext);
+ } else if (type.equals(XSD_NOTATION)) {
+ NamespaceContext namespaceContext =
+ (NamespaceContext)((context != null) ? context.getMetadata().get(NamespaceContext.class.getName()) : null);
+ return parseQName(value, namespaceContext);
+ } else if (type.equals(XSD_YEAR)) {
+ return factory.newXMLGregorianCalendar(value);
+ } else if (type.equals(XSD_MONTH)) {
+ return factory.newXMLGregorianCalendar(value);
+ } else if (type.equals(XSD_DAY)) {
+ return factory.newXMLGregorianCalendar(value);
+ } else if (type.equals(XSD_YEARMONTH)) {
+ return factory.newXMLGregorianCalendar(value);
+ } else if (type.equals(XSD_MONTHDAY)) {
+ return factory.newXMLGregorianCalendar(value);
+ } else {
+ return value;
+ }
+ }
+
+ @SuppressWarnings("deprecation")
+ private XMLGregorianCalendar toXMLGregorianCalendar(Date date) {
+ GregorianCalendar c =
+ new GregorianCalendar(date.getYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(),
+ date.getSeconds());
+ return factory.newXMLGregorianCalendar(c);
+ }
+
+ private XMLGregorianCalendar toXMLGregorianCalendar(GregorianCalendar calendar) {
+ return factory.newXMLGregorianCalendar(calendar);
+ }
+
+ public String toXMLLiteral(QName simpleType, Object obj, TransformationContext context) {
+ if(obj == null) {
+ // It could be null if nilable=true
+ return null;
+ }
+ if (obj instanceof Float || obj instanceof Double) {
+ if (obj instanceof Float) {
+ return printDouble(((Float)obj).floatValue());
+ } else {
+ return printDouble(((Double)obj).doubleValue());
+ }
+ } else if (obj instanceof GregorianCalendar) {
+ GregorianCalendar calendar = (GregorianCalendar)obj;
+ return toXMLGregorianCalendar(calendar).toXMLFormat();
+ } else if (obj instanceof Date) {
+ return toXMLGregorianCalendar((Date)obj).toXMLFormat();
+ } else if (obj instanceof XMLGregorianCalendar) {
+ return ((XMLGregorianCalendar)obj).toXMLFormat();
+ } else if (obj instanceof byte[]) {
+ if (simpleType != null) {
+ if (simpleType.equals(XSD_BASE64)) {
+ return printBase64Binary((byte[])obj);
+ } else if (simpleType.equals(XSD_HEXBIN)) {
+ return printHexBinary((byte[])obj);
+ }
+ }
+ } else if (obj instanceof QName) {
+ NamespaceContext namespaceContext =
+ (NamespaceContext)((context != null) ? context.getMetadata().get(NamespaceContext.class.getName()) : null);
+ return printQName((QName)obj, namespaceContext);
+ }
+ return obj.toString();
+ }
+
+ public static boolean isSimpleXSDType(QName typeName) {
+ if (typeName == null) {
+ return false;
+ }
+ return typeName.getNamespaceURI().equals(URI_2001_SCHEMA_XSD)
+ && XSD_SIMPLE_TYPES.get(typeName.getLocalPart()) != null;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/TransformationContextImpl.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/TransformationContextImpl.java
new file mode 100644
index 0000000000..a6c0639411
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/TransformationContextImpl.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.impl;
+
+import java.lang.ref.WeakReference;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+
+public class TransformationContextImpl implements TransformationContext {
+ private DataType sourceDataType;
+
+ private DataType targetDataType;
+
+ private final Map<String, Object> metadata = new HashMap<String, Object>();
+
+ private WeakReference<ClassLoader> classLoaderRef;
+
+ public TransformationContextImpl() {
+ super();
+ // This is used only for testing
+ setClassLoader(Thread.currentThread().getContextClassLoader());
+ }
+
+ public TransformationContextImpl(DataType sourceDataType,
+ DataType targetDataType,
+ ClassLoader classLoader,
+ Map<String, 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<String, Object> getMetadata() {
+ return metadata;
+ }
+
+ /**
+ * @return the sourceOperation
+ */
+ public Operation getSourceOperation() {
+ return (Operation) metadata.get("source.operation");
+ }
+
+ /**
+ * @param sourceOperation the sourceOperation to set
+ */
+ public void setSourceOperation(Operation sourceOperation) {
+ this.metadata.put("source.operation", sourceOperation);
+ }
+
+ /**
+ * @return the targetOperation
+ */
+ public Operation getTargetOperation() {
+ return (Operation) metadata.get("target.operation");
+ }
+
+ /**
+ * @param targetOperation the targetOperation to set
+ */
+ public void setTargetOperation(Operation targetOperation) {
+ this.metadata.put("target.operation", targetOperation);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/XSDDataTypeConverter.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/XSDDataTypeConverter.java
new file mode 100644
index 0000000000..fb747864e7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/impl/XSDDataTypeConverter.java
@@ -0,0 +1,945 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.impl;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.text.FieldPosition;
+import java.text.Format;
+import java.text.ParsePosition;
+import java.util.Calendar;
+import java.util.TimeZone;
+
+import javax.xml.XMLConstants;
+import javax.xml.datatype.DatatypeConfigurationException;
+import javax.xml.datatype.DatatypeFactory;
+import javax.xml.datatype.Duration;
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+
+/**
+ * Utility class for XSD data type conversions
+ *
+ * @version $Rev$ $Date$
+ */
+public class XSDDataTypeConverter {
+ public static final class Base64Binary {
+ private static final char[] S_BASE64CHAR =
+ {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
+ 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
+ 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4',
+ '5', '6', '7', '8', '9', '+', '/'};
+
+ private static final char S_BASE64PAD = '=';
+
+ private static final byte[] S_DECODETABLE = new byte[128];
+
+ static {
+ for (int i = 0; i < S_DECODETABLE.length; i++) {
+ S_DECODETABLE[i] = Byte.MAX_VALUE; // 127
+ }
+ for (int i = 0; i < S_BASE64CHAR.length; i++) {
+ // 0 to 63
+ S_DECODETABLE[S_BASE64CHAR[i]] = (byte) i;
+ }
+ }
+
+ private Base64Binary() {
+ }
+
+ /**
+ *
+ */
+ public static byte[] decode(char[] data, int off, int len) {
+ char[] ibuf = new char[4];
+ int ibufcount = 0;
+ byte[] obuf = new byte[len / 4 * 3 + 3];
+ int obufcount = 0;
+ for (int i = off; i < off + len; i++) {
+ char ch = data[i];
+ if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
+ ibuf[ibufcount++] = ch;
+ if (ibufcount == ibuf.length) {
+ ibufcount = 0;
+ obufcount += decode0(ibuf, obuf, obufcount);
+ }
+ }
+ }
+ if (obufcount == obuf.length) {
+ return obuf;
+ }
+ byte[] ret = new byte[obufcount];
+ System.arraycopy(obuf, 0, ret, 0, obufcount);
+ return ret;
+ }
+
+ /**
+ *
+ */
+ public static void decode(char[] data, int off, int len, OutputStream ostream) throws IOException {
+ char[] ibuf = new char[4];
+ int ibufcount = 0;
+ byte[] obuf = new byte[3];
+ for (int i = off; i < off + len; i++) {
+ char ch = data[i];
+ if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
+ ibuf[ibufcount++] = ch;
+ if (ibufcount == ibuf.length) {
+ ibufcount = 0;
+ int obufcount = decode0(ibuf, obuf, 0);
+ ostream.write(obuf, 0, obufcount);
+ }
+ }
+ }
+ }
+
+ /**
+ *
+ */
+ public static byte[] decode(String data) {
+ char[] ibuf = new char[4];
+ int ibufcount = 0;
+ byte[] obuf = new byte[data.length() / 4 * 3 + 3];
+ int obufcount = 0;
+ for (int i = 0; i < data.length(); i++) {
+ char ch = data.charAt(i);
+ if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
+ ibuf[ibufcount++] = ch;
+ if (ibufcount == ibuf.length) {
+ ibufcount = 0;
+ obufcount += decode0(ibuf, obuf, obufcount);
+ }
+ }
+ }
+ if (obufcount == obuf.length) {
+ return obuf;
+ }
+ byte[] ret = new byte[obufcount];
+ System.arraycopy(obuf, 0, ret, 0, obufcount);
+ return ret;
+ }
+
+ /**
+ *
+ */
+ public static void decode(String data, OutputStream ostream) throws IOException {
+ char[] ibuf = new char[4];
+ int ibufcount = 0;
+ byte[] obuf = new byte[3];
+ for (int i = 0; i < data.length(); i++) {
+ char ch = data.charAt(i);
+ if (ch == S_BASE64PAD || ch < S_DECODETABLE.length && S_DECODETABLE[ch] != Byte.MAX_VALUE) {
+ ibuf[ibufcount++] = ch;
+ if (ibufcount == ibuf.length) {
+ ibufcount = 0;
+ int obufcount = decode0(ibuf, obuf, 0);
+ ostream.write(obuf, 0, obufcount);
+ }
+ }
+ }
+ }
+
+ private static int decode0(char[] ibuf, byte[] obuf, int index) {
+ int wp = index;
+ int outlen = 3;
+ if (ibuf[3] == S_BASE64PAD) {
+ outlen = 2;
+ }
+ if (ibuf[2] == S_BASE64PAD) {
+ outlen = 1;
+ }
+ int b0 = S_DECODETABLE[ibuf[0]];
+ int b1 = S_DECODETABLE[ibuf[1]];
+ int b2 = S_DECODETABLE[ibuf[2]];
+ int b3 = S_DECODETABLE[ibuf[3]];
+ switch (outlen) {
+ case 1:
+ obuf[wp] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3);
+ return 1;
+ case 2:
+ obuf[wp++] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3);
+ obuf[wp] = (byte) (b1 << 4 & 0xf0 | b2 >> 2 & 0xf);
+ return 2;
+ case 3:
+ obuf[wp++] = (byte) (b0 << 2 & 0xfc | b1 >> 4 & 0x3);
+ obuf[wp++] = (byte) (b1 << 4 & 0xf0 | b2 >> 2 & 0xf);
+ obuf[wp] = (byte) (b2 << 6 & 0xc0 | b3 & 0x3f);
+ return 3;
+ default:
+ throw new IllegalArgumentException("The character sequence is not base64 encoded.");
+ }
+ }
+
+ /**
+ * Returns base64 representation of specified byte array.
+ */
+ public static String encode(byte[] data) {
+ return encode(data, 0, data.length);
+ }
+
+ /**
+ * Returns base64 representation of specified byte array.
+ */
+ public static String encode(byte[] data, int off, int len) {
+ if (len <= 0) {
+ return "";
+ }
+ char[] out = new char[len / 3 * 4 + 4];
+ int rindex = off;
+ int windex = 0;
+ int rest = len - off;
+ while (rest >= 3) {
+ int i =
+ ((data[rindex] & 0xff) << 16) + ((data[rindex + 1] & 0xff) << 8)
+ + (data[rindex + 2] & 0xff);
+ out[windex++] = S_BASE64CHAR[i >> 18];
+ out[windex++] = S_BASE64CHAR[(i >> 12) & 0x3f];
+ out[windex++] = S_BASE64CHAR[(i >> 6) & 0x3f];
+ out[windex++] = S_BASE64CHAR[i & 0x3f];
+ rindex += 3;
+ rest -= 3;
+ }
+ if (rest == 1) {
+ int i = data[rindex] & 0xff;
+ out[windex++] = S_BASE64CHAR[i >> 2];
+ out[windex++] = S_BASE64CHAR[(i << 4) & 0x3f];
+ out[windex++] = S_BASE64PAD;
+ out[windex++] = S_BASE64PAD;
+ } else if (rest == 2) {
+ int i = ((data[rindex] & 0xff) << 8) + (data[rindex + 1] & 0xff);
+ out[windex++] = S_BASE64CHAR[i >> 10];
+ out[windex++] = S_BASE64CHAR[(i >> 4) & 0x3f];
+ out[windex++] = S_BASE64CHAR[(i << 2) & 0x3f];
+ out[windex++] = S_BASE64PAD;
+ }
+ return new String(out, 0, windex);
+ }
+
+ /**
+ * Outputs base64 representation of the specified byte array to a byte stream.
+ */
+ public static void encode(byte[] data, int off, int len, OutputStream ostream) throws IOException {
+ if (len <= 0) {
+ return;
+ }
+ byte[] out = new byte[4];
+ int rindex = off;
+ int rest = len - off;
+ while (rest >= 3) {
+ int i =
+ ((data[rindex] & 0xff) << 16) + ((data[rindex + 1] & 0xff) << 8)
+ + (data[rindex + 2] & 0xff);
+ out[0] = (byte) S_BASE64CHAR[i >> 18];
+ out[1] = (byte) S_BASE64CHAR[(i >> 12) & 0x3f];
+ out[2] = (byte) S_BASE64CHAR[(i >> 6) & 0x3f];
+ out[3] = (byte) S_BASE64CHAR[i & 0x3f];
+ ostream.write(out, 0, 4);
+ rindex += 3;
+ rest -= 3;
+ }
+ if (rest == 1) {
+ int i = data[rindex] & 0xff;
+ out[0] = (byte) S_BASE64CHAR[i >> 2];
+ out[1] = (byte) S_BASE64CHAR[(i << 4) & 0x3f];
+ out[2] = (byte) S_BASE64PAD;
+ out[3] = (byte) S_BASE64PAD;
+ ostream.write(out, 0, 4);
+ } else if (rest == 2) {
+ int i = ((data[rindex] & 0xff) << 8) + (data[rindex + 1] & 0xff);
+ out[0] = (byte) S_BASE64CHAR[i >> 10];
+ out[1] = (byte) S_BASE64CHAR[(i >> 4) & 0x3f];
+ out[2] = (byte) S_BASE64CHAR[(i << 2) & 0x3f];
+ out[3] = (byte) S_BASE64PAD;
+ ostream.write(out, 0, 4);
+ }
+ }
+
+ /**
+ * Outputs base64 representation of the specified byte array to a character stream.
+ */
+ public static void encode(byte[] data, int off, int len, Writer writer) throws IOException {
+ if (len <= 0) {
+ return;
+ }
+ char[] out = new char[4];
+ int rindex = off;
+ int rest = len - off;
+ int output = 0;
+ while (rest >= 3) {
+ int i =
+ ((data[rindex] & 0xff) << 16) + ((data[rindex + 1] & 0xff) << 8)
+ + (data[rindex + 2] & 0xff);
+ out[0] = S_BASE64CHAR[i >> 18];
+ out[1] = S_BASE64CHAR[(i >> 12) & 0x3f];
+ out[2] = S_BASE64CHAR[(i >> 6) & 0x3f];
+ out[3] = S_BASE64CHAR[i & 0x3f];
+ writer.write(out, 0, 4);
+ rindex += 3;
+ rest -= 3;
+ output += 4;
+ if (output % 76 == 0) {
+ writer.write("\n");
+ }
+ }
+ if (rest == 1) {
+ int i = data[rindex] & 0xff;
+ out[0] = S_BASE64CHAR[i >> 2];
+ out[1] = S_BASE64CHAR[(i << 4) & 0x3f];
+ out[2] = S_BASE64PAD;
+ out[3] = S_BASE64PAD;
+ writer.write(out, 0, 4);
+ } else if (rest == 2) {
+ int i = ((data[rindex] & 0xff) << 8) + (data[rindex + 1] & 0xff);
+ out[0] = S_BASE64CHAR[i >> 10];
+ out[1] = S_BASE64CHAR[(i >> 4) & 0x3f];
+ out[2] = S_BASE64CHAR[(i << 2) & 0x3f];
+ out[3] = S_BASE64PAD;
+ writer.write(out, 0, 4);
+ }
+ }
+ }
+
+ /**
+ * <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);
+ }
+
+ @Override
+ public StringBuffer format(Object pCalendar, StringBuffer pBuffer, FieldPosition pPos) {
+ assert pCalendar != null : "The Calendar argument must not be null.";
+ assert pBuffer != null : "The StringBuffer argument must not be null.";
+ assert pPos != null : "The FieldPosition argument must not be null.";
+
+ Calendar cal = (Calendar) pCalendar;
+ if (parseDate) {
+ int year = cal.get(Calendar.YEAR);
+ if (year < 0) {
+ pBuffer.append('-');
+ year = -year;
+ }
+ append(pBuffer, year, 4);
+ pBuffer.append('-');
+ append(pBuffer, cal.get(Calendar.MONTH) + 1, 2);
+ pBuffer.append('-');
+ append(pBuffer, cal.get(Calendar.DAY_OF_MONTH), 2);
+ if (parseTime) {
+ pBuffer.append('T');
+ }
+ }
+ if (parseTime) {
+ append(pBuffer, cal.get(Calendar.HOUR_OF_DAY), 2);
+ pBuffer.append(':');
+ append(pBuffer, cal.get(Calendar.MINUTE), 2);
+ pBuffer.append(':');
+ append(pBuffer, cal.get(Calendar.SECOND), 2);
+ int millis = cal.get(Calendar.MILLISECOND);
+ if (millis > 0) {
+ pBuffer.append('.');
+ append(pBuffer, millis, 3);
+ }
+ }
+ TimeZone tz = cal.getTimeZone();
+ // JDK 1.4: int offset = tz.getOffset(cal.getTimeInMillis());
+ int offset = cal.get(Calendar.ZONE_OFFSET);
+ if (tz.inDaylightTime(cal.getTime())) {
+ offset += cal.get(Calendar.DST_OFFSET);
+ }
+ if (offset == 0) {
+ pBuffer.append('Z');
+ } else {
+ if (offset < 0) {
+ pBuffer.append('-');
+ offset = -offset;
+ } else {
+ pBuffer.append('+');
+ }
+ int minutes = offset / (60 * 1000);
+ int hours = minutes / 60;
+ minutes -= hours * 60;
+ append(pBuffer, hours, 2);
+ pBuffer.append(':');
+ append(pBuffer, minutes, 2);
+ }
+ return pBuffer;
+ }
+
+ private int parseInt(String pString, int offset, StringBuffer pDigits) {
+ int length = pString.length();
+ int pOffset = offset;
+ pDigits.setLength(0);
+ while (pOffset < length) {
+ char c = pString.charAt(pOffset);
+ if (Character.isDigit(c)) {
+ pDigits.append(c);
+ ++pOffset;
+ } else {
+ break;
+ }
+ }
+ return pOffset;
+ }
+
+ @Override
+ public Object parseObject(String pString, ParsePosition pParsePosition) {
+ assert pString != null : "The String argument must not be null.";
+ assert pParsePosition != null : "The ParsePosition argument must not be null.";
+ int offset = pParsePosition.getIndex();
+ int length = pString.length();
+
+ boolean isMinus = false;
+ StringBuffer digits = new StringBuffer();
+ int year = 0;
+ int month = 0;
+ int mday = 0;
+ if (parseDate) {
+ // Sign
+ if (offset < length) {
+ char c = pString.charAt(offset);
+ if (c == '+') {
+ ++offset;
+ } else if (c == '-') {
+ ++offset;
+ isMinus = true;
+ }
+ }
+
+ offset = parseInt(pString, offset, digits);
+ if (digits.length() < 4) {
+ pParsePosition.setErrorIndex(offset);
+ return null;
+ }
+ year = Integer.parseInt(digits.toString());
+
+ if (offset < length && pString.charAt(offset) == '-') {
+ ++offset;
+ } else {
+ pParsePosition.setErrorIndex(offset);
+ return null;
+ }
+
+ offset = parseInt(pString, offset, digits);
+ if (digits.length() != 2) {
+ pParsePosition.setErrorIndex(offset);
+ return null;
+ }
+ month = Integer.parseInt(digits.toString());
+
+ if (offset < length && pString.charAt(offset) == '-') {
+ ++offset;
+ } else {
+ pParsePosition.setErrorIndex(offset);
+ return null;
+ }
+
+ offset = parseInt(pString, offset, digits);
+ if (digits.length() != 2) {
+ pParsePosition.setErrorIndex(offset);
+ return null;
+ }
+ mday = Integer.parseInt(digits.toString());
+
+ if (parseTime) {
+ if (offset < length && pString.charAt(offset) == 'T') {
+ ++offset;
+ } else {
+ pParsePosition.setErrorIndex(offset);
+ return null;
+ }
+ }
+ } else {
+ year = month = mday = 0;
+ }
+
+ int hour = 0;
+ int minute = 0;
+ int second = 0;
+ int millis = 0;
+ if (parseTime) {
+ offset = parseInt(pString, offset, digits);
+ if (digits.length() != 2) {
+ pParsePosition.setErrorIndex(offset);
+ return null;
+ }
+ hour = Integer.parseInt(digits.toString());
+
+ if (offset < length && pString.charAt(offset) == ':') {
+ ++offset;
+ } else {
+ pParsePosition.setErrorIndex(offset);
+ return null;
+ }
+
+ offset = parseInt(pString, offset, digits);
+ if (digits.length() != 2) {
+ pParsePosition.setErrorIndex(offset);
+ return null;
+ }
+ minute = Integer.parseInt(digits.toString());
+
+ if (offset < length && pString.charAt(offset) == ':') {
+ ++offset;
+ } else {
+ pParsePosition.setErrorIndex(offset);
+ return null;
+ }
+
+ offset = parseInt(pString, offset, digits);
+ if (digits.length() != 2) {
+ pParsePosition.setErrorIndex(offset);
+ return null;
+ }
+ second = Integer.parseInt(digits.toString());
+
+ if (offset < length && pString.charAt(offset) == '.') {
+ ++offset;
+ offset = parseInt(pString, offset, digits);
+ if (digits.length() > 0) {
+ millis = Integer.parseInt(digits.toString());
+ } else {
+ millis = 0;
+ }
+ } else {
+ millis = 0;
+ }
+ } else {
+ hour = minute = second = millis = 0;
+ }
+
+ digits.setLength(0);
+ digits.append("GMT");
+ if (offset < length) {
+ char c = pString.charAt(offset);
+ if (c == 'Z') {
+ // Ignore UTC, it is the default
+ ++offset;
+ } else if (c == '+' || c == '-') {
+ digits.append(c);
+ ++offset;
+ for (int i = 0; i < 5; i++) {
+ if (offset >= length) {
+ pParsePosition.setErrorIndex(offset);
+ return null;
+ }
+ c = pString.charAt(offset);
+ if ((i != 2 && Character.isDigit(c)) || (i == 2 && c == ':')) {
+ digits.append(c);
+ } else {
+ pParsePosition.setErrorIndex(offset);
+ return null;
+ }
+ ++offset;
+ }
+ }
+ }
+
+ Calendar cal = Calendar.getInstance(TimeZone.getTimeZone(digits.toString()));
+ cal.set(isMinus ? -year : year, parseDate ? month - 1 : month, mday, hour, minute, second);
+ cal.set(Calendar.MILLISECOND, millis);
+ pParsePosition.setIndex(offset);
+ return cal;
+ }
+ }
+
+ public static class XSDTimeFormat extends XSDDateTimeFormat {
+ private static final long serialVersionUID = 1346506860724640517L;
+
+ /**
+ * Creates a new instance.
+ */
+ public XSDTimeFormat() {
+ super(false, true);
+ }
+ }
+
+ private static final long MAX_UNSIGNED_INT = (((long) Integer.MAX_VALUE) * 2) + 1;
+
+ private static final int MAX_UNSIGNED_SHORT = Short.MAX_VALUE * 2 + 1;
+
+ public String parseAnySimpleType(String value) {
+ return value;
+ }
+
+ public byte[] parseBase64Binary(String value) {
+ return Base64Binary.decode(value);
+ }
+
+ public boolean parseBoolean(String value) {
+ return Boolean.valueOf(value).booleanValue();
+ }
+
+ public byte parseByte(String value) {
+ return Byte.parseByte(value);
+ }
+
+ public Calendar parseDate(String value) {
+ XSDDateFormat format = new XSDDateFormat();
+ ParsePosition pos = new ParsePosition(0);
+ Calendar cal = (Calendar) format.parseObject(value, pos);
+ if (cal == null) {
+ throw new IllegalArgumentException("Failed to parse date " + value + " at:"
+ + value.substring(pos.getErrorIndex()));
+ }
+ return cal;
+ }
+
+ public Calendar parseDateTime(String value) {
+ XSDDateTimeFormat format = new XSDDateTimeFormat();
+ ParsePosition pos = new ParsePosition(0);
+ Calendar cal = (Calendar) format.parseObject(value, pos);
+ if (cal == null) {
+ throw new IllegalArgumentException("Failed to parse dateTime " + value + " at:"
+ + value.substring(pos.getErrorIndex()));
+ }
+ return cal;
+ }
+
+ public BigDecimal parseDecimal(String value) {
+ return new BigDecimal(value);
+ }
+
+ public double parseDouble(String value) {
+ if ("INF".equals(value)) {
+ return Double.POSITIVE_INFINITY;
+ } else if ("-INF".equals(value)) {
+ return Double.NEGATIVE_INFINITY;
+ } else if ("NaN".equals(value)) {
+ return Double.NaN;
+ } else {
+ return Double.parseDouble(value);
+ }
+ }
+
+ public Duration parseDuration(String pDuration) {
+ try {
+ return DatatypeFactory.newInstance().newDuration(pDuration);
+ } catch (DatatypeConfigurationException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ public float parseFloat(String value) {
+ if ("INF".equals(value)) {
+ return Float.POSITIVE_INFINITY;
+ } else if ("-INF".equals(value)) {
+ return Float.NEGATIVE_INFINITY;
+ } else if ("NaN".equals(value)) {
+ return Float.NaN;
+ } else {
+ return Float.parseFloat(value);
+ }
+ }
+
+ public byte[] parseHexBinary(String value) {
+ return HexBinary.decode(value);
+ }
+
+ public int parseInt(String value) {
+ return Integer.parseInt(value);
+ }
+
+ public BigInteger parseInteger(String value) {
+ return new BigInteger(value);
+ }
+
+ public long parseLong(String value) {
+ return Long.parseLong(value);
+ }
+
+ public QName parseQName(String value, NamespaceContext context) {
+ int offset = value.indexOf(':');
+ String uri;
+ String localName;
+ switch (offset) {
+ case -1:
+ localName = value;
+ uri = context.getNamespaceURI("");
+ if (uri == null) {
+ // Should not happen, indicates an error in the
+ // NamespaceContext
+ // implementation
+ throw new IllegalArgumentException("The default prefix is not bound.");
+ }
+ break;
+ case 0:
+ throw new IllegalArgumentException("Default prefix must be indicated by not using a colon: "
+ + value);
+ default:
+ String prefix = value.substring(0, offset);
+ localName = value.substring(offset + 1);
+ uri = context.getNamespaceURI(prefix);
+ if (uri == null) {
+ throw new IllegalArgumentException("The prefix " + prefix + " is not bound.");
+ }
+ }
+ return new QName(uri, localName);
+ }
+
+ public short parseShort(String value) {
+ return Short.parseShort(value);
+ }
+
+ public String parseString(String value) {
+ return value;
+ }
+
+ public Calendar parseTime(String value) {
+ XSDTimeFormat format = new XSDTimeFormat();
+ ParsePosition pos = new ParsePosition(0);
+ Calendar cal = (Calendar) format.parseObject(value, pos);
+ if (cal == null) {
+ throw new IllegalArgumentException("Failed to parse time " + value + " at:"
+ + value.substring(pos.getErrorIndex()));
+ }
+ return cal;
+ }
+
+ public long parseUnsignedInt(String value) {
+ long l = Long.parseLong(value);
+ if (l < 0) {
+ throw new IllegalArgumentException("Failed to parse UnsignedInt " + value
+ + ": result is negative");
+ }
+ if (l > MAX_UNSIGNED_INT) {
+ throw new IllegalArgumentException("Failed to parse UnsignedInt " + value
+ + ": result exceeds maximum value " + MAX_UNSIGNED_INT);
+ }
+ return l;
+ }
+
+ public int parseUnsignedShort(String value) {
+ int i = Integer.parseInt(value);
+ if (i < 0) {
+ throw new IllegalArgumentException("Failed to parse UnsignedShort " + value
+ + ": result is negative");
+ }
+ if (i > MAX_UNSIGNED_SHORT) {
+ throw new IllegalArgumentException("Failed to parse UnsignedShort " + value
+ + ": result exceeds maximum value " + MAX_UNSIGNED_SHORT);
+ }
+ return i;
+ }
+
+ public String printAnySimpleType(String value) {
+ return value;
+ }
+
+ public String printBase64Binary(byte[] value) {
+ return Base64Binary.encode(value);
+ }
+
+ public String printBoolean(boolean value) {
+ return (value ? Boolean.TRUE : Boolean.FALSE).toString();
+ }
+
+ public String printByte(byte value) {
+ return Byte.toString(value);
+ }
+
+ public String printDate(Calendar value) {
+ return new XSDDateFormat().format(value);
+ }
+
+ public String printDateTime(Calendar value) {
+ return new XSDDateTimeFormat().format(value);
+ }
+
+ public String printDecimal(BigDecimal value) {
+ return value.toString();
+ }
+
+ public String printDouble(double value) {
+ return Double.toString(value);
+ }
+
+ public String printDuration(Duration pDuration) {
+ return pDuration.toString();
+ }
+
+ public String printFloat(float value) {
+ return Float.toString(value);
+ }
+
+ public String printHexBinary(byte[] value) {
+ return HexBinary.encode(value);
+ }
+
+ public String printInt(int value) {
+ return Integer.toString(value);
+ }
+
+ public String printInteger(BigInteger value) {
+ return value.toString();
+ }
+
+ public String printLong(long value) {
+ return Long.toString(value);
+ }
+
+ public String printQName(QName value, NamespaceContext context) {
+ String prefix = context.getPrefix(value.getNamespaceURI());
+ if (prefix == null) {
+ throw new IllegalArgumentException("The namespace URI " + value.getNamespaceURI()
+ + " is not bound.");
+ } else if (XMLConstants.DEFAULT_NS_PREFIX.equals(prefix)) {
+ return value.getLocalPart();
+ } else {
+ return prefix + ":" + value.getLocalPart();
+ }
+ }
+
+ public String printShort(short value) {
+ return Short.toString(value);
+ }
+
+ public String printString(String value) {
+ return value;
+ }
+
+ public String printTime(Calendar value) {
+ return new XSDTimeFormat().format(value);
+ }
+
+ public String printUnsignedInt(long value) {
+ return Long.toString(value);
+ }
+
+ public String printUnsignedShort(int value) {
+ return Integer.toString(value);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/DOMNode2JavaBeanTransformer.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/DOMNode2JavaBeanTransformer.java
new file mode 100644
index 0000000000..2f95c2a9c6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/DOMNode2JavaBeanTransformer.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.javabeans;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Transformer to convert data from DOM Node to JavaBean
+ *
+ * @version $Rev$ $Date$
+ */
+public class DOMNode2JavaBeanTransformer extends XML2JavaBeanTransformer<Node> {
+
+ @Override
+ public Node getRootElement(Node element) throws XML2JavaMapperException {
+ if (element instanceof Document) {
+ return ((Document)element).getDocumentElement();
+ } else {
+ return element;
+ }
+
+ }
+
+ @Override
+ public Iterator<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.iterator();
+ }
+
+ @Override
+ public String getElementName(Node element) throws XML2JavaMapperException {
+ return element.getLocalName();
+ }
+
+ @Override
+ public String getText(Node element) throws XML2JavaMapperException {
+ if (element instanceof Document) {
+ element = ((Document)element).getDocumentElement();
+ }
+ return element.getTextContent();
+ }
+
+ @Override
+ public boolean isTextElement(Node element) throws XML2JavaMapperException {
+ return element.getNodeType() == Node.TEXT_NODE;
+ }
+
+ @Override
+ public boolean isTextOnly(Node element) throws XML2JavaMapperException {
+ NodeList childNodes = element.getChildNodes();
+ return childNodes.getLength() == 1 && isTextElement(childNodes.item(0));
+ }
+
+ @Override
+ public Node getFirstChildWithName(Node element, QName name) throws XML2JavaMapperException {
+ Node child;
+ for (child = element.getFirstChild();
+ child != null && !(child.getNodeName() == name.getLocalPart()
+ && child.getNamespaceURI() == name.getNamespaceURI()) ;
+ child = child.getNextSibling()) {
+ }
+ return child;
+ }
+
+ @Override
+ public Class getSourceType() {
+ return Node.class;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/Java2XMLMapperException.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/Java2XMLMapperException.java
new file mode 100644
index 0000000000..9615f43572
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/Java2XMLMapperException.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.javabeans;
+
+import javax.xml.namespace.QName;
+
+/**
+ * This exception is used to encapsulate and rethrow exceptions that arise out
+ * of converting JavaBean objects to XML
+ *
+ * @version $Rev$ $Date$
+ */
+public class Java2XMLMapperException extends RuntimeException {
+ private static final long serialVersionUID = 6811924384399578686L;
+
+ private QName xmlElementName;
+ private String javaFieldName;
+ private Class javaType;
+
+ public Java2XMLMapperException(String message) {
+ super(message);
+ }
+
+ public Java2XMLMapperException(Throwable cause) {
+ super(cause);
+ }
+
+ public String getJavaFieldName() {
+ return javaFieldName;
+ }
+
+ public void setJavaFieldName(String javaFieldName) {
+ this.javaFieldName = javaFieldName;
+ }
+
+ public Class getJavaType() {
+ return javaType;
+ }
+
+ public void setJavaType(Class javaType) {
+ this.javaType = javaType;
+ }
+
+ public QName getXmlElementName() {
+ return xmlElementName;
+ }
+
+ public void setXmlElementName(QName xmlElementName) {
+ this.xmlElementName = xmlElementName;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2DOMNodeTransformer.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2DOMNodeTransformer.java
new file mode 100644
index 0000000000..58f594751a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2DOMNodeTransformer.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.javabeans;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.tuscany.sca.databinding.impl.DOMHelper;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * Transformer to convert data from a JavaBean object to DOM Node
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaBean2DOMNodeTransformer extends JavaBean2XMLTransformer<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 void appendText(Node parentElement, String textData) throws Java2XMLMapperException {
+ Node textNode;
+ if (textData != null) {
+ textNode = factory.createTextNode(textData);
+ } else {
+ Attr nil = factory.createAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:nil");
+ nil.setValue("true");
+ textNode = nil;
+ }
+ appendChild(parentElement, textNode);
+ }
+
+ @Override
+ public Class getTargetType() {
+ return Node.class;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLStreamReaderTransformer.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLStreamReaderTransformer.java
new file mode 100644
index 0000000000..4942fef0da
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLStreamReaderTransformer.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.javabeans;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.apache.tuscany.sca.databinding.xml.BeanXMLStreamReaderImpl;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+
+/**
+ * Transformer to convert data from a JavaBean object to XMLStreamReader.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaBean2XMLStreamReaderTransformer extends BaseTransformer<Object, XMLStreamReader> implements
+ PullTransformer<Object, XMLStreamReader> {
+
+ public XMLStreamReader transform(Object source, TransformationContext context) {
+ try {
+ javax.xml.namespace.QName name = null;
+ if (context != null) {
+ Object logical = context.getSourceDataType().getLogical();
+ if (logical instanceof XMLType) {
+ name = ((XMLType)logical).getElementName();
+ }
+ }
+ return new BeanXMLStreamReaderImpl(name, source);
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ @Override
+ protected Class<Object> getSourceType() {
+ return Object.class;
+ }
+
+ @Override
+ protected Class<XMLStreamReader> getTargetType() {
+ return XMLStreamReader.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 50;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLTransformer.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLTransformer.java
new file mode 100644
index 0000000000..b96b394bb8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBean2XMLTransformer.java
@@ -0,0 +1,262 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.javabeans;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Date;
+import java.util.GregorianCalendar;
+
+import javax.xml.datatype.XMLGregorianCalendar;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+
+/**
+ * Transformer to convert data from a JavaBean object to xml
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class JavaBean2XMLTransformer<T> extends BaseTransformer<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 SimpleTypeMapperImpl mapper;
+
+ public JavaBean2XMLTransformer() {
+ this.mapper = new SimpleTypeMapperImpl();
+ }
+
+ public T transform(Object source, TransformationContext context) {
+ QName rootElement = null;
+ if (context != null) {
+ DataType<?> type = context.getTargetDataType();
+ if (type != null) {
+ Object logical = type.getLogical();
+ if (logical instanceof XMLType) {
+ rootElement = ((XMLType)logical).getElementName();
+ }
+ }
+ }
+ //FIXME See how/if we still need to get the metadata here
+ //QName rootElementName = (QName)context.getTargetDataType().getMetadata("RootElementName");
+ //if (rootElementName == null) {
+ QName rootElementName = new QName(resolveRootElementName(source.getClass()));
+ //}
+
+ T root = createElement(rootElementName);
+ appendChildElements(root, resolveElementName(source.getClass()), source.getClass(), source, context);
+ return root;
+ }
+
+ private void appendChildElements(T parent,
+ QName elementName,
+ Class javaType,
+ Object javaObject,
+ TransformationContext context) {
+ T element = null;
+ if (javaObject != null) {
+ if (javaType.isPrimitive() || isSimpleJavaType(javaObject)) {
+ appendText(parent, mapper.toXMLLiteral(null, javaObject, context));
+ } else if (javaType.isArray()) {
+ int size = Array.getLength(javaObject);
+ for (int count = 0; count < size; ++count) {
+ Object item = Array.get(javaObject, count);
+ element = createElement(elementName);
+ appendChild(parent, element);
+ appendChildElements(element, elementName, javaType.getComponentType(), item, context);
+ }
+ } else {
+ Field[] javaFields = javaType.getFields();
+ for (Field aField : javaFields) {
+ try {
+ QName fieldElementName = new QName(aField.getName());
+ if (!aField.getType().isArray()) {
+ element = createElement(fieldElementName);
+ appendChild(parent, element);
+ appendChildElements(element,
+ fieldElementName,
+ aField.getType(),
+ aField.get(javaObject),
+ context);
+ } else {
+ appendChildElements(parent,
+ fieldElementName,
+ aField.getType(),
+ aField.get(javaObject),
+ context);
+ }
+ } catch (IllegalAccessException e) {
+ Java2XMLMapperException java2xmlEx = new Java2XMLMapperException(e);
+ java2xmlEx.setJavaFieldName(aField.getName());
+ java2xmlEx.setJavaType(javaType);
+ throw java2xmlEx;
+ }
+ }
+
+ Method[] methods = javaType.getMethods();
+ String fieldName = null;
+ for (Method aMethod : methods) {
+ try {
+ if (Modifier.isPublic(aMethod.getModifiers()) && aMethod.getName().startsWith(GET)
+ && aMethod.getParameterTypes().length == 0
+ && isMappedGetter(aMethod.getName())) {
+ fieldName = resolveFieldFromMethod(aMethod.getName());
+ try {
+ javaType.getField(fieldName);
+ } catch (NoSuchFieldException e) {
+ QName fieldElementName = new QName(fieldName);
+ if (aMethod.getReturnType().isArray()) {
+ appendChildElements(parent, fieldElementName, aMethod.getReturnType(), aMethod
+ .invoke(javaObject, new Object[0]), context);
+ } else {
+ element = createElement(fieldElementName);
+ appendChild(parent, element);
+ appendChildElements(element, fieldElementName, aMethod.getReturnType(), aMethod
+ .invoke(javaObject, new Object[0]), context);
+ }
+ }
+ }
+ } catch (IllegalAccessException e) {
+ Java2XMLMapperException java2xmlEx = new Java2XMLMapperException(e);
+ java2xmlEx.setJavaFieldName(fieldName);
+ java2xmlEx.setJavaType(javaType);
+ throw java2xmlEx;
+ } catch (InvocationTargetException e) {
+ Java2XMLMapperException java2xmlEx = new Java2XMLMapperException(e);
+ java2xmlEx.setJavaFieldName(fieldName);
+ java2xmlEx.setJavaType(javaType);
+ throw java2xmlEx;
+ }
+ }
+ }
+ }
+ }
+
+ /*
+ * Subclasses can override this method to prevent some getter methods
+ * from being mapped. The default implementation provided by this class
+ * maps all getter methods.
+ */
+ protected boolean isMappedGetter(String methodName) {
+ return true;
+ }
+
+ @Override
+ public String getSourceDataBinding() {
+ return JavaBeansDataBinding.NAME;
+ }
+
+ @Override
+ public Class<Object> getSourceType() {
+ return Object.class;
+ }
+
+ private boolean isSimpleJavaType(Object javaObject) {
+ if (javaObject instanceof String) {
+ return true;
+ }
+ if (javaObject instanceof Byte || javaObject instanceof Character
+ || javaObject instanceof Short
+ || javaObject instanceof Integer
+ || javaObject instanceof Long
+ || javaObject instanceof Float
+ || javaObject instanceof Double
+ || javaObject instanceof Boolean) {
+ return true;
+ }
+ if (javaObject instanceof GregorianCalendar || javaObject instanceof Date
+ || javaObject instanceof XMLGregorianCalendar
+ || javaObject instanceof byte[]
+ || javaObject instanceof QName) {
+ return true;
+ }
+ return false;
+ }
+
+ private String resolveRootElementName(Class javaType) {
+ if (javaType.isArray()) {
+ return javaType.getComponentType().getSimpleName() + "_collection";
+ } else {
+ return javaType.getSimpleName() + "_instance";
+ }
+ }
+
+ private QName resolveElementName(Class javaType) {
+ if (javaType.isArray()) {
+ return new QName(javaType.getComponentType().getSimpleName());
+ } else {
+ return new QName(javaType.getSimpleName());
+ }
+ }
+
+ private String resolveFieldFromMethod(String methodName) {
+ StringBuffer fieldName = new StringBuffer();
+ fieldName.append(Character.toLowerCase(methodName.charAt(GET.length())));
+ fieldName.append(methodName.substring(GET.length() + 1));
+ return fieldName.toString();
+ }
+
+ public String getNexPrefix() {
+ return PREFIX + prefixCount++;
+ }
+
+ @Override
+ public int getWeight() {
+ return JavaBeansDataBinding.HEAVY_WEIGHT;
+ }
+
+ /**
+ * Create an element with the given name
+ * @param qName
+ * @return
+ * @throws Java2XMLMapperException
+ */
+ public abstract T createElement(QName qName) throws Java2XMLMapperException;
+
+ /**
+ * Create a text node and add it to the parent
+ * @param parentElement
+ * @param textData
+ * @throws Java2XMLMapperException
+ */
+ public abstract void appendText(T parentElement, String textData) throws Java2XMLMapperException;
+
+ /**
+ * Add the child element to the parent
+ * @param parentElement
+ * @param childElement
+ * @throws Java2XMLMapperException
+ */
+ public abstract void appendChild(T parentElement, T childElement) throws Java2XMLMapperException;
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java
new file mode 100644
index 0000000000..fb04014051
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaBeansDataBinding.java
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.javabeans;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.ObjectStreamClass;
+import java.io.OutputStream;
+import java.io.Serializable;
+
+import org.apache.tuscany.sca.databinding.impl.BaseDataBinding;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+
+/**
+ * DataBinding for JavaBeans
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaBeansDataBinding extends BaseDataBinding {
+ /**
+ * Defining a weight to a very high number so that the transformer won't be picked
+ * up by other paths unless it's the only available path
+ */
+ public static final int HEAVY_WEIGHT = 10000;
+ public static final String NAME = "java:complexType";
+
+ public JavaBeansDataBinding() {
+ super(NAME, Object.class);
+ }
+
+ protected JavaBeansDataBinding(String name, Class<?> baseType) {
+ super(name, baseType);
+ }
+
+ @Override
+ public Object copy(Object arg, DataType dataType, Operation operation) {
+ if (arg == null) {
+ return null;
+ }
+ final Class clazz = arg.getClass();
+ if (String.class == clazz || clazz.isPrimitive()
+ || Number.class.isAssignableFrom(clazz)
+ || Boolean.class.isAssignableFrom(clazz)
+ || Character.class.isAssignableFrom(clazz)
+ || Byte.class.isAssignableFrom(clazz)) {
+ // Immutable classes
+ return arg;
+ }
+ try {
+ if (arg instanceof Serializable) {
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ ObjectOutputStream oos = getObjectOutputStream(bos);
+ oos.writeObject(arg);
+ oos.close();
+ bos.close();
+
+ // Work out which ClassLoader to use for deserializing arg
+ // We want to use:
+ // * The ClassLoader of arg if it is not the System ClassLoader
+ // * The ThreadContext ClassLoader if the ClassLoader of arg is the System ClassLoader
+ // because Collection classes are loaded by the System ClassLoader but their contents
+ // may be loaded from another ClassLoader
+ //
+ ClassLoader classLoaderToUse = clazz.getClassLoader();
+ if (classLoaderToUse == null)
+ {
+ // ClassLoader of arg is the System ClassLoader so we will use the ThreadContext ClassLoader
+ // instead
+ classLoaderToUse = Thread.currentThread().getContextClassLoader();
+ }
+
+ ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
+ ObjectInputStream ois = getObjectInputStream(bis, classLoaderToUse);
+ Object objectCopy = ois.readObject();
+ ois.close();
+ bis.close();
+ return objectCopy;
+ } else {
+ // return arg;
+ throw new IllegalArgumentException("Argument type '" + arg.getClass().getCanonicalName() + "' is not Serializable. " +
+ " Pass-by-value cannot be performed on this argument");
+ }
+ } catch (Exception e) {
+ throw new IllegalArgumentException("Pass-by-value is not supported for the given object", e);
+ }
+ }
+
+ protected ObjectOutputStream getObjectOutputStream(OutputStream os) throws IOException {
+ return new ObjectOutputStream(os);
+ }
+
+ protected ObjectInputStream getObjectInputStream(InputStream is, final ClassLoader cl) throws IOException {
+ ObjectInputStream ois = new ObjectInputStream(is) {
+ @Override
+ protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
+ try {
+ return Class.forName(desc.getName(), false, cl);
+ } catch (ClassNotFoundException e) {
+ try {
+ // For OSGi, use context ClassLoader if the bundle ClassLoader cannot load the class
+ if (cl != Thread.currentThread().getContextClassLoader()) {
+ return Class.forName(desc.getName(), false, Thread.currentThread().getContextClassLoader());
+ }
+ } catch (ClassNotFoundException e1) {
+ // ignore
+ } catch (NoClassDefFoundError e1) {
+ // ignore
+ }
+ return super.resolveClass(desc);
+ }
+ }
+
+ };
+ return ois;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaExceptionDataBinding.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaExceptionDataBinding.java
new file mode 100644
index 0000000000..7ae64c6a27
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/JavaExceptionDataBinding.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.javabeans;
+
+
+/**
+ * DataBinding for Java Exceptions
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaExceptionDataBinding extends JavaBeansDataBinding {
+
+ public static final String NAME = "java:exception";
+
+ public JavaExceptionDataBinding() {
+ super(NAME, null);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/SimpleJavaDataBinding.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/SimpleJavaDataBinding.java
new file mode 100644
index 0000000000..11c82e062c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/SimpleJavaDataBinding.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.javabeans;
+
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.databinding.impl.BaseDataBinding;
+import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl;
+import org.apache.tuscany.sca.databinding.xml.XMLStringDataBinding;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.TypeInfo;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+
+/**
+ * DataBinding for Java simple types
+ *
+ * @version $Rev$ $Date$
+ */
+public class SimpleJavaDataBinding extends BaseDataBinding {
+ public static final String NAME = "java:simpleType";
+
+ public SimpleJavaDataBinding() {
+ super(NAME, Object.class);
+ }
+
+ @Override
+ public Object copy(Object arg, DataType dataType, Operation operation) {
+ if (arg instanceof byte[]) {
+ return ((byte[])arg).clone();
+ }
+ return arg;
+ }
+
+ @Override
+ public boolean introspect(DataType type, Operation operation) {
+ Class<?> cls = type.getPhysical();
+ if (cls == Object.class) {
+ return false;
+ }
+ // HACK: [rfeng] By pass the one know to XMLString
+ String db = type.getDataBinding();
+ if (db != null && (XMLStringDataBinding.NAME.equals(db) || XMLStringDataBinding.ALIASES[0].equals(db))) {
+ return false;
+ }
+ if (SimpleTypeMapperImpl.JAVA2XML.keySet().contains(cls)) {
+ type.setDataBinding(NAME);
+ QName elementName = null;
+ Object logical = type.getLogical();
+ if (logical instanceof XMLType) {
+ elementName = ((XMLType)logical).getElementName();
+ }
+ TypeInfo typeInfo = SimpleTypeMapperImpl.getXMLType(cls);
+ type.setLogical(new XMLType(elementName, typeInfo == null ? null : typeInfo.getQName()));
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaBeanTransformer.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaBeanTransformer.java
new file mode 100644
index 0000000000..06feeffabd
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaBeanTransformer.java
@@ -0,0 +1,329 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.javabeans;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+
+/**
+ * Transformer to convert data from XML to JavaBean
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class XML2JavaBeanTransformer<T> extends BaseTransformer<T, Object> implements
+ PullTransformer<T, Object> {
+
+ public static final String SET = "set";
+ public static final QName QNAME_MESSAGE = new QName("message");
+
+ protected SimpleTypeMapperImpl mapper;
+
+ public XML2JavaBeanTransformer() {
+ this.mapper = new SimpleTypeMapperImpl();
+ }
+
+ @Override
+ public int getWeight() {
+ return JavaBeansDataBinding.HEAVY_WEIGHT;
+ }
+
+ public Object transform(T source, TransformationContext context) {
+ //FIXME why is the logical type sometimes a Class instead of an XMLType?
+ if (context.getSourceDataType().getLogical() instanceof XMLType) {
+ XMLType xmlType = (XMLType) context.getSourceDataType().getLogical();
+ return toJavaObject(xmlType.getTypeName(), getRootElement(source), context);
+ } else {
+ return toJavaObject(null, getRootElement(source), context);
+ }
+ }
+
+ public Object toJavaObject(QName xmlType, T xmlElement, TransformationContext context) {
+ if (xmlType != null && SimpleTypeMapperImpl.isSimpleXSDType(xmlType)) {
+ return mapper.toJavaObject(xmlType, getText(xmlElement), context);
+ } else {
+ Class<?> javaType = (Class<?>)context.getTargetDataType().getPhysical();
+ return createJavaObject(xmlElement, javaType, context);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private <L> L createJavaObject(T element, Class<L> javaType, TransformationContext context)
+ throws XML2JavaMapperException {
+ if (isTextOnly(element)) {
+ return (L) mapper.toJavaObject(SimpleTypeMapperImpl.getXMLType(javaType).getQName(),
+ getText(element),
+ context);
+ } else {
+ String fieldName = null;
+ try {
+ L javaInstance;
+ T detailMsg = null;
+ if (Throwable.class.isAssignableFrom(javaType)) {
+ T msgElement = getFirstChildWithName(element, QNAME_MESSAGE);
+ if (msgElement != null && isTextOnly(msgElement)) {
+ detailMsg = msgElement; // skip this when handling child elements
+ Constructor constructor = javaType.getConstructor(new Class[] {String.class});
+ javaInstance = (L)constructor.newInstance(new Object[] {getText(detailMsg)});
+ } else {
+ javaInstance = javaType.newInstance();
+ }
+ } else {
+ javaInstance = javaType.newInstance();
+ }
+ Map<Field, List<Object>> arrayFields = new Hashtable<Field, List<Object>>();
+ Map<Method, List<Object>> arraySetters = new Hashtable<Method, List<Object>>();
+
+ for (Iterator<T> childElements = getChildElements(element); childElements.hasNext(); ) {
+ T childElement = childElements.next();
+ if (!isTextElement(childElement) && childElement != detailMsg) {
+ fieldName = getElementName(childElement);
+ try {
+ Field javaField = javaType.getField(fieldName);
+ setFieldValue(javaInstance,
+ javaField,
+ childElement,
+ arrayFields,
+ context);
+
+ } catch (NoSuchFieldException e1) {
+ setFieldValueUsingSetter(javaType,
+ javaInstance,
+ fieldName,
+ childElement,
+ arraySetters,
+ context);
+ }
+ }
+ }
+
+ setArrayValues(javaInstance, arrayFields, arraySetters);
+ return javaInstance;
+ } catch (Exception e2) {
+ XML2JavaMapperException xml2JavaEx = new XML2JavaMapperException(e2);
+ xml2JavaEx.setJavaType(javaType);
+ xml2JavaEx.setJavaFieldName(fieldName);
+ throw xml2JavaEx;
+ }
+ }
+ }
+
+ private void setFieldValue(Object javaInstance,
+ Field javaField,
+ T fieldValue,
+ Map<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 Iterator<T> getChildElements(T parent) throws XML2JavaMapperException;
+
+ public abstract String getElementName(T element) throws XML2JavaMapperException;
+
+ public abstract boolean isTextElement(T element) throws XML2JavaMapperException;
+
+ public abstract boolean isTextOnly(T element) throws XML2JavaMapperException;
+
+ public abstract T getFirstChildWithName(T element, QName name) throws XML2JavaMapperException;
+
+ public abstract T getRootElement(T element) throws XML2JavaMapperException;
+
+ @Override
+ public Class<Object> getTargetType() {
+ return Object.class;
+ }
+
+ @Override
+ public String getTargetDataBinding() {
+ return JavaBeansDataBinding.NAME;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaMapperException.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaMapperException.java
new file mode 100644
index 0000000000..a723fd445c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/javabeans/XML2JavaMapperException.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.javabeans;
+
+import javax.xml.namespace.QName;
+
+/**
+ * This exception is used to encapsulate and rethrow exceptions that arise out
+ * of converting XML Data to Java Objects.
+ *
+ * @version $Rev$ $Date$
+ */
+public class XML2JavaMapperException extends RuntimeException {
+ private static final long serialVersionUID = 6596530102591630642L;
+
+ private QName xmlElementName;
+ private String javaFieldName;
+ private Class javaType;
+
+ public XML2JavaMapperException(String message) {
+ super(message);
+ }
+
+ public XML2JavaMapperException(Throwable cause) {
+ super(cause);
+ }
+
+ public QName getXmlElementName() {
+ return xmlElementName;
+ }
+
+ public void setXmlElementName(QName xmlElementName) {
+ this.xmlElementName = xmlElementName;
+ }
+
+ public String getJavaFieldName() {
+ return javaFieldName;
+ }
+
+ public void setJavaFieldName(String javaFieldName) {
+ this.javaFieldName = javaFieldName;
+ }
+
+ public Class getJavaType() {
+ return javaType;
+ }
+
+ public void setJavaType(Class javaType) {
+ this.javaType = javaType;
+ }
+
+ @Override
+ public String getMessage() {
+ return super.getMessage() + " <" + getJavaFieldName() + "> " + " in <" + getJavaType() + ">";
+ }
+
+
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/DataTypeHelper.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/DataTypeHelper.java
new file mode 100644
index 0000000000..1e39150f4a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/DataTypeHelper.java
@@ -0,0 +1,165 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.util;
+
+import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+import java.lang.reflect.WildcardType;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.WrapperInfo;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataTypeHelper {
+ private DataTypeHelper() {
+ }
+
+ /**
+ * Find all classes referenced by this data type though java generics
+ * @param d
+ * @return
+ */
+ public static Set<Class<?>> findClasses(DataType d) {
+ Set<Class<?>> classes = new HashSet<Class<?>>();
+ Set<Type> visited = new HashSet<Type>();
+ findClasses(d, classes, visited);
+ return classes;
+ }
+
+ private static void findClasses(DataType d, Set<Class<?>> classes, Set<Type> visited) {
+ if (d == null) {
+ return;
+ }
+ classes.add(d.getPhysical());
+ if (d.getPhysical() != d.getGenericType()) {
+ findClasses(d.getGenericType(), classes, visited);
+ }
+ }
+
+ /**
+ * Find referenced classes in the generic type
+ * @param type
+ * @param classSet
+ * @param visited
+ */
+ private static void findClasses(Type type, Set<Class<?>> classSet, Set<Type> visited) {
+ if (visited.contains(type) || type == null) {
+ return;
+ }
+ visited.add(type);
+ if (type instanceof Class) {
+ Class<?> cls = (Class<?>)type;
+ if (!cls.isInterface()) {
+ classSet.add(cls);
+ }
+ return;
+ } else if (type instanceof ParameterizedType) {
+ ParameterizedType pType = (ParameterizedType)type;
+ findClasses(pType.getRawType(), classSet, visited);
+ for (Type t : pType.getActualTypeArguments()) {
+ findClasses(t, classSet, visited);
+ }
+ } else if (type instanceof TypeVariable) {
+ TypeVariable<?> tv = (TypeVariable<?>)type;
+ for (Type t : tv.getBounds()) {
+ findClasses(t, classSet, visited);
+ }
+ } else if (type instanceof GenericArrayType) {
+ GenericArrayType gType = (GenericArrayType)type;
+ findClasses(gType, classSet, visited);
+ } else if (type instanceof WildcardType) {
+ WildcardType wType = (WildcardType)type;
+ for (Type t : wType.getLowerBounds()) {
+ findClasses(t, classSet, visited);
+ }
+ for (Type t : wType.getUpperBounds()) {
+ findClasses(t, classSet, visited);
+ }
+ }
+ }
+
+ /**
+ * Get all the data types in the interface
+ * @param intf The interface
+ * @param useWrapper Use wrapper classes?
+ * @return A list of DataTypes
+ */
+ public static List<DataType> getDataTypes(Interface intf, boolean useWrapper) {
+ List<DataType> dataTypes = new ArrayList<DataType>();
+ for (Operation op : intf.getOperations()) {
+ getDataTypes(dataTypes, op, useWrapper);
+ }
+ return dataTypes;
+ }
+
+ /**
+ * Get all the data types in the operation
+ * @param op The operaiton
+ * @param useWrapper Use wrapper classes?
+ * @return A list of DataTypes
+ */
+ public static List<DataType> getDataTypes(Operation op, boolean useWrapper) {
+ List<DataType> dataTypes = new ArrayList<DataType>();
+ getDataTypes(dataTypes, op, useWrapper);
+ return dataTypes;
+ }
+
+ private static void getDataTypes(List<DataType> dataTypes, Operation op, boolean useWrapper) {
+ WrapperInfo wrapper = op.getWrapper();
+ if (useWrapper && wrapper != null) {
+ DataType dt1 = wrapper.getInputWrapperType();
+ if (dt1 != null) {
+ dataTypes.add(dt1);
+ }
+ DataType dt2 = wrapper.getOutputWrapperType();
+ if (dt2 != null) {
+ dataTypes.add(dt2);
+ }
+ }
+ // FIXME: [rfeng] We may need to find the referenced classes in the child types
+ // else
+ {
+ for (DataType dt1 : op.getInputType().getLogical()) {
+ dataTypes.add(dt1);
+ }
+ DataType dt2 = op.getOutputType();
+ if (dt2 != null) {
+ dataTypes.add(dt2);
+ }
+ }
+ for (DataType<DataType> dt3 : op.getFaultTypes()) {
+ DataType dt4 = dt3.getLogical();
+ if (dt4 != null) {
+ dataTypes.add(dt4);
+ }
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/LRUCache.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/LRUCache.java
new file mode 100644
index 0000000000..34a82fd2d3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/util/LRUCache.java
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.util;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+/**
+ * A Simple LRU Cache
+ *
+ * @version $Revision$
+ * @param <K>
+ * @param <V>
+ */
+
+public class LRUCache<K, V> extends LinkedHashMap<K, V> {
+ private static final long serialVersionUID = -342098639681884413L;
+ protected int maxCacheSize = 4096;
+
+ /**
+ * Default constructor for an LRU Cache The default capacity is 10000
+ */
+ public LRUCache() {
+ this(0, 4096, 0.75f, true);
+ }
+
+ /**
+ * Constructs a LRUCache with a maximum capacity
+ *
+ * @param maximumCacheSize
+ */
+ public LRUCache(int maximumCacheSize) {
+ this(0, maximumCacheSize, 0.75f, true);
+ }
+
+ /**
+ * Constructs an empty <tt>LRUCache</tt> instance with the specified
+ * initial capacity, maximumCacheSize,load factor and ordering mode.
+ *
+ * @param initialCapacity the initial capacity.
+ * @param maximumCacheSize
+ * @param loadFactor the load factor.
+ * @param accessOrder the ordering mode - <tt>true</tt> for access-order,
+ * <tt>false</tt> for insertion-order.
+ * @throws IllegalArgumentException if the initial capacity is negative or
+ * the load factor is non-positive.
+ */
+
+ public LRUCache(int initialCapacity, int maximumCacheSize, float loadFactor, boolean accessOrder) {
+ super(initialCapacity, loadFactor, accessOrder);
+ this.maxCacheSize = maximumCacheSize;
+ }
+
+ /**
+ * @return Returns the maxCacheSize.
+ */
+ public int getMaxCacheSize() {
+ return maxCacheSize;
+ }
+
+ /**
+ * @param maxCacheSize The maxCacheSize to set.
+ */
+ public void setMaxCacheSize(int maxCacheSize) {
+ this.maxCacheSize = maxCacheSize;
+ }
+
+ @Override
+ protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
+ return size() > maxCacheSize;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/BeanXMLStreamReaderImpl.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/BeanXMLStreamReaderImpl.java
new file mode 100644
index 0000000000..3423d3e3b0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/BeanXMLStreamReaderImpl.java
@@ -0,0 +1,296 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.beans.BeanInfo;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl;
+import org.apache.tuscany.sca.interfacedef.util.TypeInfo;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class BeanXMLStreamReaderImpl extends XmlTreeStreamReaderImpl {
+ private static final Comparator<Accessor> COMPARATOR = new Comparator<Accessor>() {
+ public int compare(Accessor o1, Accessor o2) {
+ return o1.getName().compareTo(o2.getName());
+ }
+ };
+
+ public static class BeanXmlNodeImpl extends SimpleXmlNodeImpl implements XmlNode {
+ private static final Object[] NULL = null;
+ private static final SimpleTypeMapperImpl MAPPER = new SimpleTypeMapperImpl();
+
+ public BeanXmlNodeImpl(Object bean) {
+ super(getName(bean == null ? null : bean.getClass()), bean);
+ }
+
+ public BeanXmlNodeImpl(QName name, Object bean) {
+ super(name, bean);
+ }
+
+ private static boolean isSimpleType(Class<?> javaType) {
+ return SimpleTypeMapperImpl.getXMLType(javaType) != null;
+ }
+
+ private static String getStringValue(Object o) {
+ if (o == null) {
+ return null;
+ }
+ TypeInfo info = SimpleTypeMapperImpl.getXMLType(o.getClass());
+ if (info != null) {
+ return MAPPER.toXMLLiteral(info.getQName(), o, null);
+ } else {
+ return String.valueOf(o);
+ }
+ }
+
+ @Override
+ public Iterator<XmlNode> children() {
+ if (name == null) {
+ return null;
+ }
+ if (value == null) {
+ return super.children();
+ }
+ if (isSimpleType(value.getClass())) {
+ XmlNode textNode = new BeanXmlNodeImpl(null, value);
+ return Arrays.asList(textNode).iterator();
+ }
+ if (Map.class.isAssignableFrom(value.getClass())) {
+ List<XmlNode> entries = new ArrayList<XmlNode>();
+ QName entryName = new QName(name.getNamespaceURI(), "entry");
+ Map map = (Map)value;
+ if (map != null) {
+ for (Object e : map.entrySet()) {
+ Map.Entry entry = (Map.Entry)e;
+ entries.add(new BeanXmlNodeImpl(entryName, entry));
+ }
+ }
+ return entries.iterator();
+ }
+ try {
+ Map<String, Accessor> accessorMap = getAccessors(value);
+ List<Accessor> accessorList = new ArrayList<Accessor>(accessorMap.values());
+ Collections.sort(accessorList, COMPARATOR);
+
+ List<XmlNode> props = new ArrayList<XmlNode>();
+ for (Accessor accessor : accessorList) {
+ Class<?> pType = accessor.getType();
+
+ QName pName = new QName(name.getNamespaceURI(), accessor.getName());
+ Object pValue = accessor.getValue();
+ if (pType.isArray()) {
+ if (pValue != null) {
+ int i1 = Array.getLength(pValue);
+ for (int j = 0; j < i1; j++) {
+ Object o = Array.get(pValue, j);
+ props.add(new BeanXmlNodeImpl(pName, o));
+ }
+ } else {
+ // TODO: How to handle null?
+ }
+ } else if (Collection.class.isAssignableFrom(pType)) {
+ Collection objList = (Collection)pValue;
+ if (objList != null && objList.size() > 0) {
+ for (Iterator j = objList.iterator(); j.hasNext();) {
+ Object o = j.next();
+ props.add(new BeanXmlNodeImpl(pName, o));
+ }
+
+ } else {
+ // How to handle null
+ }
+ } else {
+ props.add(new BeanXmlNodeImpl(pName, pValue));
+ }
+ }
+ return props.iterator();
+ } catch (Exception e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ @Override
+ public QName getName() {
+ return name;
+ }
+
+ @Override
+ public String getValue() {
+ return getStringValue(value);
+ }
+
+ private static String getPackageName(Class<?> cls) {
+ String name = cls.getName();
+ int index = name.lastIndexOf('.');
+ return index == -1 ? "" : name.substring(0, index);
+ }
+
+ public static QName getName(Class<?> cls) {
+ if (cls == null) {
+ return null;
+ }
+
+ String packageName = getPackageName(cls);
+
+ if ("".equals(packageName)) {
+ return new QName("", cls.getSimpleName());
+ }
+ StringBuffer ns = new StringBuffer("http://");
+ String[] names = packageName.split("\\.");
+ for (int i = names.length - 1; i >= 0; i--) {
+ ns.append(names[i]);
+ if (i != 0) {
+ ns.append('.');
+ }
+ }
+ ns.append('/');
+ return new QName(ns.toString(), cls.getSimpleName());
+ }
+
+ }
+
+ public BeanXMLStreamReaderImpl(QName name, Object bean) {
+ super(getXmlNode(name, bean));
+ }
+
+ private static BeanXmlNodeImpl getXmlNode(QName name, Object bean) {
+ BeanXmlNodeImpl root = null;
+ if (name != null) {
+ root = new BeanXmlNodeImpl(name, bean);
+ } else {
+ root = new BeanXmlNodeImpl(bean);
+ }
+ return root;
+ }
+
+ public static interface Accessor {
+ String getName();
+
+ Class<?> getType();
+
+ Object getValue() throws Exception;
+
+ void setValue(Object value) throws Exception;
+ }
+
+ private static class FieldAccessor implements Accessor {
+ private Object target;
+ private Field field;
+
+ public FieldAccessor(Object target, Field field) {
+ super();
+ this.target = target;
+ this.field = field;
+ this.field.setAccessible(true);
+ }
+
+ public String getName() {
+ return field.getName();
+ }
+
+ public Object getValue() throws Exception {
+ return field.get(target);
+ }
+
+ public void setValue(Object value) throws Exception {
+ field.set(target, value);
+ }
+
+ public Class<?> getType() {
+ return field.getType();
+ }
+
+ }
+
+ private static class PropertyAccessor implements Accessor {
+ private Object target;
+ private PropertyDescriptor prop;
+
+ public PropertyAccessor(Object target, PropertyDescriptor prop) {
+ super();
+ this.target = target;
+ this.prop = prop;
+ }
+
+ public String getName() {
+ return prop.getName();
+ }
+
+ public Class<?> getType() {
+ return prop.getPropertyType();
+ }
+
+ public Object getValue() throws Exception {
+ Method getter = prop.getReadMethod();
+ if (getter != null) {
+ getter.setAccessible(true);
+ return getter.invoke(target);
+ }
+ throw new IllegalAccessException("The property cannot be read: " + getName());
+ }
+
+ public void setValue(Object value) throws Exception {
+ Method setter = prop.getWriteMethod();
+ if (setter != null) {
+ setter.setAccessible(true);
+ setter.invoke(target);
+ }
+ throw new IllegalAccessException("The property cannot be written: " + getName());
+ }
+
+ }
+
+ private static Map<String, Accessor> getAccessors(Object target) throws Exception {
+ if (target == null) {
+ return Collections.emptyMap();
+ }
+ Map<String, Accessor> map = new HashMap<String, Accessor>();
+ Class<?> type = target.getClass();
+ for (Field f : type.getFields()) {
+ map.put(f.getName(), new FieldAccessor(target, f));
+ }
+ BeanInfo info = Introspector.getBeanInfo(type, Object.class);
+ for (PropertyDescriptor p : info.getPropertyDescriptors()) {
+ // if (p.getReadMethod() != null && p.getWriteMethod() != null) {
+ map.put(p.getName(), new PropertyAccessor(target, p));
+ // }
+ }
+ return map;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMDataBinding.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMDataBinding.java
new file mode 100644
index 0000000000..92058d769f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMDataBinding.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.databinding.WrapperHandler;
+import org.apache.tuscany.sca.databinding.impl.BaseDataBinding;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.w3c.dom.Node;
+
+/**
+ * DOM DataBinding
+ *
+ * @version $Rev$ $Date$
+ */
+public class DOMDataBinding extends BaseDataBinding {
+ public static final String NAME = Node.class.getName();
+ public static final String[] ALIASES = new String[] {"dom"};
+
+ public static final String ROOT_NAMESPACE = "http://tuscany.apache.org/xmlns/sca/databinding/dom/1.0";
+ public static final QName ROOT_ELEMENT = new QName(ROOT_NAMESPACE, "root");
+
+ public DOMDataBinding() {
+ super(NAME, ALIASES, Node.class);
+ }
+
+ @Override
+ public WrapperHandler getWrapperHandler() {
+ return new DOMWrapperHandler();
+ }
+
+ @Override
+ public Object copy(Object source, DataType dataType, Operation operation) {
+ if (Node.class.isAssignableFrom(source.getClass())) {
+ Node nodeSource = (Node)source;
+ return nodeSource.cloneNode(true);
+ }
+ return super.copy(source, dataType, operation);
+ }
+
+ @Override
+ public boolean introspect(DataType type, Operation operation) {
+ if (Node.class.isAssignableFrom(type.getPhysical())) {
+ if (type.getLogical() == null) {
+ type.setLogical(new XMLType(ROOT_ELEMENT, null));
+ }
+ type.setDataBinding(NAME);
+ return true;
+ }
+ return false;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMWrapperHandler.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMWrapperHandler.java
new file mode 100644
index 0000000000..9e1ebb3522
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMWrapperHandler.java
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.WrapperHandler;
+import org.apache.tuscany.sca.databinding.impl.DOMHelper;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
+import org.apache.tuscany.sca.interfacedef.util.ElementInfo;
+import org.apache.tuscany.sca.interfacedef.util.WrapperInfo;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+public class DOMWrapperHandler implements WrapperHandler<Node> {
+
+ public DOMWrapperHandler() {
+ super();
+ }
+
+ public Node create(Operation operation, boolean input) {
+ try {
+ WrapperInfo wrapperInfo = operation.getWrapper();
+ ElementInfo element = input ? wrapperInfo.getInputWrapperElement() : wrapperInfo.getOutputWrapperElement();
+ // Class<?> wrapperClass = input ? wrapperInfo.getInputWrapperClass() : wrapperInfo.getOutputWrapperClass();
+ Document document = DOMHelper.newDocument();
+ QName name = element.getQName();
+ return DOMHelper.createElement(document, name);
+ } catch (ParserConfigurationException e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ public void setChildren(Node wrapper,
+ Object[] childObjects,
+ Operation operation, boolean input) {
+ List<ElementInfo> childElements = input? operation.getWrapper().getInputChildElements():
+ operation.getWrapper().getOutputChildElements();
+ for (int i = 0; i < childElements.size(); i++) {
+ setChild(wrapper, i, childElements.get(i), childObjects[i]);
+ }
+
+ }
+ public void setChild(Node wrapper, int i, ElementInfo childElement, Object value) {
+ Node node = (Node)value;
+ if (node.getNodeType() == Node.DOCUMENT_NODE) {
+ node = ((Document)node).getDocumentElement();
+ }
+ wrapper.appendChild(wrapper.getOwnerDocument().importNode(node, true));
+ }
+
+ public List getChildren(Node wrapper, Operation operation, boolean input) {
+ assert wrapper != null;
+ List<ElementInfo> childElements = input? operation.getWrapper().getInputChildElements():
+ operation.getWrapper().getOutputChildElements();
+ if (wrapper.getNodeType() == Node.DOCUMENT_NODE) {
+ wrapper = ((Document)wrapper).getDocumentElement();
+ }
+ List<Node> elements = new ArrayList<Node>();
+ NodeList nodes = wrapper.getChildNodes();
+ for (int j = 0; j < nodes.getLength(); j++) {
+ Node node = nodes.item(j);
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ elements.add(node);
+ }
+ }
+ return elements;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.WrapperHandler#getWrapperType(Operation, boolean)
+ */
+ public DataType getWrapperType(Operation operation, boolean input) {
+ WrapperInfo wrapper = operation.getWrapper();
+ ElementInfo element = input? wrapper.getInputWrapperElement(): wrapper.getOutputWrapperElement();
+ DataType<XMLType> wrapperType =
+ new DataTypeImpl<XMLType>(DOMDataBinding.NAME, Node.class, new XMLType(element));
+ return wrapperType;
+ }
+
+ public boolean isInstance(Object wrapperObj,
+ Operation operation,
+ boolean input) {
+ WrapperInfo wrapperInfo = operation.getWrapper();
+ ElementInfo element = input ? wrapperInfo.getInputWrapperElement() : wrapperInfo.getOutputWrapperElement();
+ List<ElementInfo> childElements =
+ input ? wrapperInfo.getInputChildElements() : wrapperInfo.getOutputChildElements();
+ Node wrapper = (Node)wrapperObj;
+ if (wrapper.getNodeType() == Node.DOCUMENT_NODE) {
+ wrapper = ((Document)wrapper).getDocumentElement();
+ }
+ QName elementName = new QName(wrapper.getNamespaceURI(), wrapper.getLocalName());
+ if (!element.getQName().equals(elementName)) {
+ return false;
+ }
+ Set<QName> names = new HashSet<QName>();
+ for (ElementInfo e : childElements) {
+ names.add(e.getQName());
+ }
+ NodeList nodes = wrapper.getChildNodes();
+ for (int j = 0; j < nodes.getLength(); j++) {
+ Node node = nodes.item(j);
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ elementName = new QName(wrapper.getNamespaceURI(), wrapper.getLocalName());
+ if (!names.contains(elementName)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXMLStreamReader.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXMLStreamReader.java
new file mode 100644
index 0000000000..8c7a742cdd
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXMLStreamReader.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import org.w3c.dom.Node;
+
+public class DOMXMLStreamReader extends XmlTreeStreamReaderImpl {
+
+ public DOMXMLStreamReader(Node node) {
+ super(new DOMXmlNodeImpl(node));
+ switch (node.getNodeType()) {
+ case Node.DOCUMENT_NODE:
+ break;
+ case Node.ELEMENT_NODE:
+ break;
+ default:
+ throw new IllegalArgumentException("Illegal node type: " + node);
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXmlNodeImpl.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXmlNodeImpl.java
new file mode 100644
index 0000000000..507c141c33
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DOMXmlNodeImpl.java
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DOMXmlNodeImpl implements XmlNode {
+ private Node node;
+ private Map<String, String> namespaces;
+ private Type type;
+
+ /**
+ * @param element
+ */
+ public DOMXmlNodeImpl(Node element) {
+ super();
+ if (element.getNodeType() == Node.DOCUMENT_NODE) {
+ this.node = ((Document)element).getDocumentElement();
+ } else {
+ this.node = element;
+ }
+ switch (node.getNodeType()) {
+ case Node.CDATA_SECTION_NODE:
+ this.type = Type.CHARACTERS;
+ break;
+ case Node.ELEMENT_NODE:
+ this.type = Type.ELEMENT;
+ break;
+ case Node.TEXT_NODE:
+ this.type = Type.CHARACTERS;
+ break;
+ }
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.xml.XmlNode#attributes()
+ */
+ public List<XmlNode> attributes() {
+ if (type != Type.ELEMENT) {
+ return null;
+ }
+ NamedNodeMap attrs = node.getAttributes();
+ List<XmlNode> xmlAttrs = new ArrayList<XmlNode>();
+ for (int i = 0; i < attrs.getLength(); i++) {
+ Attr attr = (Attr)attrs.item(i);
+ if (!attr.getName().equals("xmlns") && !attr.getName().startsWith("xmlns:")) {
+ xmlAttrs.add(new SimpleXmlNodeImpl(getQName(attr), attr.getValue(), XmlNode.Type.ATTRIBUTE));
+ }
+ }
+ return xmlAttrs;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.xml.XmlNode#children()
+ */
+ public Iterator<XmlNode> children() {
+ if (type != Type.ELEMENT) {
+ return null;
+ }
+ NodeList nodes = node.getChildNodes();
+ List<XmlNode> xmlNodes = new ArrayList<XmlNode>();
+ for (int i = 0; i < nodes.getLength(); i++) {
+ Node child = (Node)nodes.item(i);
+ int nodeType = child.getNodeType();
+ if (nodeType == Node.ELEMENT_NODE || nodeType == Node.TEXT_NODE || nodeType == Node.CDATA_SECTION_NODE) {
+ xmlNodes.add(new DOMXmlNodeImpl(child));
+ }
+ }
+ return xmlNodes.iterator();
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.xml.XmlNode#getName()
+ */
+ public QName getName() {
+ return getQName(node);
+ }
+
+ private static QName getQName(Node node) {
+ int type = node.getNodeType();
+ if (type == Node.ELEMENT_NODE || type == Node.ATTRIBUTE_NODE) {
+ String ns = node.getNamespaceURI();
+ String prefix = node.getPrefix();
+ String localName = node.getLocalName();
+ return new QName(ns == null ? "" : ns, localName, prefix == null ? "" : prefix);
+ }
+ return null;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.xml.XmlNode#getValue()
+ */
+ public String getValue() {
+ return node.getNodeValue();
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.xml.XmlNode#namespaces()
+ */
+ public Map<String, String> namespaces() {
+ if (type != Type.ELEMENT) {
+ return null;
+ }
+ if (namespaces == null) {
+ namespaces = new HashMap<String, String>();
+ NamedNodeMap attrs = node.getAttributes();
+ for (int i = 0; i < attrs.getLength(); i++) {
+ Attr attr = (Attr)attrs.item(i);
+ if ("xmlns".equals(attr.getPrefix())) {
+ namespaces.put(attr.getLocalName(), attr.getValue());
+ }
+ if ("xmlns".equals(attr.getName())) {
+ namespaces.put("", attr.getValue());
+ }
+ }
+ }
+ return namespaces;
+ }
+
+ public Type getType() {
+ return type;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DelegatingNamespaceContext.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DelegatingNamespaceContext.java
new file mode 100644
index 0000000000..7f49a50e1e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/DelegatingNamespaceContext.java
@@ -0,0 +1,310 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.util.ArrayList;
+import java.util.EmptyStackException;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.xml.namespace.NamespaceContext;
+
+public class DelegatingNamespaceContext implements NamespaceContext {
+ private static int count;
+
+ private class WrappingIterator implements Iterator {
+
+ private Iterator containedIterator;
+
+ public WrappingIterator(Iterator containedIterator) {
+ this.containedIterator = containedIterator;
+ }
+
+ public Iterator getContainedIterator() {
+ return containedIterator;
+ }
+
+ public boolean hasNext() {
+ return containedIterator.hasNext();
+ }
+
+ public Object next() {
+ return containedIterator.next();
+ }
+
+ /**
+ * As per the contract on the API of Namespace context the returned iterator should be immutable
+ */
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ public void setContainedIterator(Iterator containedIterator) {
+ this.containedIterator = containedIterator;
+ }
+ }
+
+ private NamespaceContext parentNsContext;
+
+ private FastStack<String> prefixStack = new FastStack<String>();
+
+ // Keep two ArrayLists for the prefixes and namespaces. They should be in
+ // sync
+ // since the index of the entry will be used to relate them
+ // use the minimum initial capacity to let things handle memory better
+
+ private FastStack<String> uriStack = new FastStack<String>();
+
+ /**
+ * Generates a unique namespace prefix that is not in the scope of the NamespaceContext
+ *
+ * @return string
+ */
+ public String generateUniquePrefix() {
+ String prefix = "p" + count++;
+ // null should be returned if the prefix is not bound!
+ while (getNamespaceURI(prefix) != null) {
+ prefix = "p" + count++;
+ }
+
+ return prefix;
+ }
+
+ public String getNamespaceURI(String prefix) {
+ // do the corrections as per the Javadoc
+ int index = prefixStack.search(prefix);
+ if (index != -1) {
+ return uriStack.get(index);
+ }
+ if (parentNsContext != null) {
+ return parentNsContext.getPrefix(prefix);
+ }
+ return null;
+ }
+
+ public NamespaceContext getParentNsContext() {
+ return parentNsContext;
+ }
+
+ public String getPrefix(String uri) {
+ // do the corrections as per the Javadoc
+ int index = uriStack.search(uri);
+ if (index != -1) {
+ return prefixStack.get(index);
+ }
+
+ if (parentNsContext != null) {
+ return parentNsContext.getPrefix(uri);
+ }
+ return null;
+ }
+
+ public Iterator getPrefixes(String uri) {
+ // create an ArrayList that contains the relevant prefixes
+ String[] uris = uriStack.toArray(new String[uriStack.size()]);
+ List<String> tempList = new ArrayList<String>();
+ for (int i = uris.length - 1; i >= 0; i--) {
+ if (uris[i].equals(uri)) {
+ tempList.add(prefixStack.get(i));
+ // we assume that array conversion preserves the order
+ }
+ }
+ // by now all the relevant prefixes are collected
+ // make a new iterator and provide a wrapper iterator to
+ // obey the contract on the API
+ return new WrappingIterator(tempList.iterator());
+ }
+
+ /**
+ * Pop a namespace
+ */
+ public void popNamespace() {
+ prefixStack.pop();
+ uriStack.pop();
+ }
+
+ /**
+ * Register a namespace in this context
+ *
+ * @param prefix
+ * @param uri
+ */
+ public void pushNamespace(String prefix, String uri) {
+ prefixStack.push(prefix);
+ uriStack.push(uri);
+
+ }
+
+ public void setParentNsContext(NamespaceContext parentNsContext) {
+ this.parentNsContext = parentNsContext;
+ }
+
+ /**
+ * An implementation of the {@link java.util.Stack} API that is based on an <code>ArrayList</code> instead of a
+ * <code>Vector</code>, so it is not synchronized to protect against multi-threaded access. The implementation is
+ * therefore operates faster in environments where you do not need to worry about multiple thread contention.
+ * <p>
+ * The removal order of an <code>ArrayStack</code> is based on insertion order: The most recently added element is
+ * removed first. The iteration order is <i>not</i> the same as the removal order. The iterator returns elements
+ * from the bottom up, whereas the {@link #remove()} method removes them from the top down.
+ * <p>
+ * Unlike <code>Stack</code>, <code>ArrayStack</code> accepts null entries.
+ */
+ public static class FastStack<T> extends ArrayList<T> {
+
+ /** Ensure Serialization compatibility */
+ private static final long serialVersionUID = 2130079159931574599L;
+
+ /**
+ * Constructs a new empty <code>ArrayStack</code>. The initial size is controlled by <code>ArrayList</code>
+ * and is currently 10.
+ */
+ public FastStack() {
+ super();
+ }
+
+ /**
+ * Constructs a new empty <code>ArrayStack</code> with an initial size.
+ *
+ * @param initialSize the initial size to use
+ * @throws IllegalArgumentException if the specified initial size is negative
+ */
+ public FastStack(int initialSize) {
+ super(initialSize);
+ }
+
+ /**
+ * Return <code>true</code> if this stack is currently empty.
+ * <p>
+ * This method exists for compatibility with <code>java.util.Stack</code>. New users of this class should use
+ * <code>isEmpty</code> instead.
+ *
+ * @return true if the stack is currently empty
+ */
+ public boolean empty() {
+ return isEmpty();
+ }
+
+ /**
+ * Returns the top item off of this stack without removing it.
+ *
+ * @return the top item on the stack
+ * @throws EmptyStackException if the stack is empty
+ */
+ public T peek() throws EmptyStackException {
+ int n = size();
+ if (n <= 0) {
+ throw new EmptyStackException();
+ } else {
+ return get(n - 1);
+ }
+ }
+
+ /**
+ * Returns the n'th item down (zero-relative) from the top of this stack without removing it.
+ *
+ * @param n the number of items down to go
+ * @return the n'th item on the stack, zero relative
+ * @throws EmptyStackException if there are not enough items on the stack to satisfy this request
+ */
+ public T peek(int n) throws EmptyStackException {
+ int m = (size() - n) - 1;
+ if (m < 0) {
+ throw new EmptyStackException();
+ } else {
+ return get(m);
+ }
+ }
+
+ /**
+ * Pops the top item off of this stack and return it.
+ *
+ * @return the top item on the stack
+ * @throws EmptyStackException if the stack is empty
+ */
+ public T pop() throws EmptyStackException {
+ int n = size();
+ if (n <= 0) {
+ throw new EmptyStackException();
+ } else {
+ return remove(n - 1);
+ }
+ }
+
+ /**
+ * Pushes a new item onto the top of this stack. The pushed item is also returned. This is equivalent to calling
+ * <code>add</code>.
+ *
+ * @param item the item to be added
+ * @return the item just pushed
+ */
+ public Object push(T item) {
+ add(item);
+ return item;
+ }
+
+ /**
+ * Returns the top-most index for the object in the stack
+ *
+ * @param object the object to be searched for
+ * @return top-most index, or -1 if not found
+ */
+ public int search(T object) {
+ int i = size() - 1; // Current index
+ while (i >= 0) {
+ T current = get(i);
+ if ((object == null && current == null) || (object != null && object.equals(current))) {
+ return i;
+ }
+ i--;
+ }
+ return -1;
+ }
+
+ /**
+ * Returns the element on the top of the stack.
+ *
+ * @return the element on the top of the stack
+ * @throws EmptyStackException if the stack is empty
+ */
+ public T get() {
+ int size = size();
+ if (size == 0) {
+ throw new EmptyStackException();
+ }
+ return get(size - 1);
+ }
+
+ /**
+ * Removes the element on the top of the stack.
+ *
+ * @return the removed element
+ * @throws EmptyStackException if the stack is empty
+ */
+ public T remove() {
+ int size = size();
+ if (size == 0) {
+ throw new EmptyStackException();
+ }
+ return remove(size - 1);
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2Node.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2Node.java
new file mode 100644
index 0000000000..5f583da283
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2Node.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+
+/**
+ * Push DOM InputSource to Node
+ *
+ * @version $Rev$ $Date$
+ */
+public class InputSource2Node extends BaseTransformer<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);
+ }
+ }
+
+ @Override
+ public Class<InputSource> getSourceType() {
+ return InputSource.class;
+ }
+
+ @Override
+ public Class<Node> getTargetType() {
+ return Node.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2SAX.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2SAX.java
new file mode 100644
index 0000000000..39116ba4a1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputSource2SAX.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import org.apache.tuscany.sca.databinding.PushTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderFactory;
+
+/**
+ * Push InputSource to SAX
+ *
+ * @version $Rev$ $Date$
+ */
+public class InputSource2SAX extends BaseTransformer<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);
+ }
+ }
+
+ @Override
+ public Class<InputSource> getSourceType() {
+ return InputSource.class;
+ }
+
+ @Override
+ public Class<ContentHandler> getTargetType() {
+ return ContentHandler.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2Node.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2Node.java
new file mode 100644
index 0000000000..e40c3006fb
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2Node.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.io.InputStream;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.sax.SAXSource;
+
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+
+/**
+ * Push DOM InputSource to Node
+ *
+ * @version $Rev$ $Date$
+ */
+public class InputStream2Node extends BaseTransformer<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);
+ }
+ }
+
+ @Override
+ public Class<InputStream> getSourceType() {
+ return InputStream.class;
+ }
+
+ @Override
+ public Class<Node> getTargetType() {
+ return Node.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2SAX.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2SAX.java
new file mode 100644
index 0000000000..3b7bd3088a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/InputStream2SAX.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.io.InputStream;
+
+import org.apache.tuscany.sca.databinding.PushTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderFactory;
+
+/**
+ * Push InputStream to SAX
+ *
+ * @version $Rev$ $Date$
+ */
+public class InputStream2SAX extends BaseTransformer<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);
+ }
+ }
+
+ @Override
+ public Class<InputStream> getSourceType() {
+ return InputStream.class;
+ }
+
+ @Override
+ public Class<ContentHandler> getTargetType() {
+ return ContentHandler.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValueArrayStreamReader.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValueArrayStreamReader.java
new file mode 100644
index 0000000000..5a31d9db91
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValueArrayStreamReader.java
@@ -0,0 +1,403 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
+
+public class NameValueArrayStreamReader implements XMLFragmentStreamReader {
+
+ private static final int START_ELEMENT_STATE = 0;
+ private static final int TEXT_STATE = 1;
+ private static final int END_ELEMENT_STATE = 2;
+ private static final int FINAL_END_ELEMENT_STATE = 3;
+ private static final int START_ELEMENT_STATE_WITH_NULL = 4;
+
+ private DelegatingNamespaceContext namespaceContext = new DelegatingNamespaceContext();
+ // the index of the array
+ private int arrayIndex;
+
+ private QName name;
+ private String[] values;
+
+ // start element is the default state
+ private int state = START_ELEMENT_STATE;
+
+ public NameValueArrayStreamReader(QName name, String[] values) {
+ this.name = name;
+ this.values = values;
+ }
+
+ public void setParentNamespaceContext(NamespaceContext nsContext) {
+ this.namespaceContext.setParentNsContext(nsContext);
+ }
+
+ public void init() {
+ // TODO what if the QName namespace has not been declared
+ }
+
+ public Object getProperty(String string) throws IllegalArgumentException {
+ return null;
+ }
+
+ /**
+ * @throws XMLStreamException
+ */
+ public int next() throws XMLStreamException {
+ switch (state) {
+ case START_ELEMENT_STATE:
+ if (values.length > 0) {
+ state = TEXT_STATE;
+ return CHARACTERS;
+ } else {
+ state = FINAL_END_ELEMENT_STATE;
+ return END_ELEMENT;
+ }
+
+ case START_ELEMENT_STATE_WITH_NULL:
+ if (arrayIndex == (values.length - 1)) {
+ state = FINAL_END_ELEMENT_STATE;
+ } else {
+ state = END_ELEMENT_STATE;
+ }
+ return END_ELEMENT;
+ case FINAL_END_ELEMENT_STATE:
+ // oops, not supposed to happen!
+ throw new XMLStreamException("end already reached!");
+ case END_ELEMENT_STATE:
+ // we've to have more values since this is not the
+ // last value
+ // increment the counter
+ arrayIndex++;
+ if (values[arrayIndex] == null) {
+ state = START_ELEMENT_STATE_WITH_NULL;
+ } else {
+ state = START_ELEMENT_STATE;
+ }
+ return START_ELEMENT;
+ case TEXT_STATE:
+ if (arrayIndex == (values.length - 1)) {
+ state = FINAL_END_ELEMENT_STATE;
+ return END_ELEMENT;
+ } else {
+ state = END_ELEMENT_STATE;
+ return END_ELEMENT;
+ }
+
+ default:
+ throw new XMLStreamException("unknown event type!");
+ }
+ }
+
+ public void require(int i, String string, String string1) throws XMLStreamException {
+ // nothing done here
+ }
+
+ public String getElementText() throws XMLStreamException {
+ return null; // not implemented
+ }
+
+ public int nextTag() throws XMLStreamException {
+ return 0; // not implemented
+ }
+
+ public String getAttributeValue(String string, String string1) {
+ if (state == TEXT_STATE) {
+ // TODO something
+ return null;
+ } else {
+ return null;
+ }
+
+ }
+
+ public int getAttributeCount() {
+ if (state == START_ELEMENT_STATE_WITH_NULL) {
+ return 1;
+ }
+ if (state == START_ELEMENT_STATE) {
+ return 0;
+ } else {
+ throw new IllegalStateException();
+ }
+
+ }
+
+ public QName getAttributeName(int i) {
+ if (state == START_ELEMENT_STATE_WITH_NULL && i == 0) {
+ return NIL_QNAME;
+ }
+ if (state == START_ELEMENT_STATE) {
+ return null;
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeNamespace(int i) {
+ if (state == START_ELEMENT_STATE_WITH_NULL && i == 0) {
+ return NIL_QNAME.getNamespaceURI();
+ }
+ if (state == START_ELEMENT_STATE) {
+ return null;
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeLocalName(int i) {
+ if (state == START_ELEMENT_STATE_WITH_NULL && i == 0) {
+ return NIL_QNAME.getLocalPart();
+ }
+ if (state == START_ELEMENT_STATE) {
+ return null;
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributePrefix(int i) {
+ if (state == START_ELEMENT_STATE_WITH_NULL && i == 0) {
+ return NIL_QNAME.getPrefix();
+ }
+ if (state == START_ELEMENT_STATE) {
+ return null;
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeType(int i) {
+ return null; // not implemented
+ }
+
+ public String getAttributeValue(int i) {
+ if (state == START_ELEMENT_STATE_WITH_NULL && i == 0) {
+ return NIL_VALUE_TRUE;
+ }
+ if (state == START_ELEMENT_STATE) {
+ return null;
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public boolean isAttributeSpecified(int i) {
+ return false; // not supported
+ }
+
+ public int getNamespaceCount() {
+ if (state == START_ELEMENT_STATE_WITH_NULL && isXsiNamespacePresent()) {
+ return 1;
+ } else {
+ return 0;
+ }
+
+ }
+
+ public String getNamespacePrefix(int i) {
+ if (state == START_ELEMENT_STATE_WITH_NULL && isXsiNamespacePresent() && i == 0) {
+ return NIL_QNAME.getPrefix();
+ } else {
+ return null;
+ }
+ }
+
+ public String getNamespaceURI(int i) {
+ if (state == START_ELEMENT_STATE_WITH_NULL && isXsiNamespacePresent() && i == 0) {
+ return NIL_QNAME.getNamespaceURI();
+ } else {
+ return null;
+ }
+ }
+
+ public NamespaceContext getNamespaceContext() {
+ return this.namespaceContext;
+ }
+
+ public boolean isDone() {
+ return state == FINAL_END_ELEMENT_STATE;
+ }
+
+ public int getEventType() {
+ switch (state) {
+ case START_ELEMENT_STATE:
+ return START_ELEMENT;
+ case END_ELEMENT_STATE:
+ return END_ELEMENT;
+ case TEXT_STATE:
+ return CHARACTERS;
+ case FINAL_END_ELEMENT_STATE:
+ return END_ELEMENT;
+ default:
+ throw new UnsupportedOperationException();
+ // we've no idea what this is!!!!!
+ }
+
+ }
+
+ public String getText() {
+ if (state == TEXT_STATE) {
+ return values[arrayIndex];
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public char[] getTextCharacters() {
+ if (state == TEXT_STATE) {
+ return values[arrayIndex].toCharArray();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public int getTextCharacters(int i, char[] chars, int i1, int i2) throws XMLStreamException {
+ // not implemented
+ throw new UnsupportedOperationException();
+ }
+
+ public int getTextStart() {
+ if (state == TEXT_STATE) {
+ return 0;
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public int getTextLength() {
+ if (state == TEXT_STATE) {
+ return values[arrayIndex].length();
+ } else {
+ throw new IllegalStateException();
+ }
+
+ }
+
+ public String getEncoding() {
+ return null;
+ }
+
+ public boolean hasText() {
+ return state == TEXT_STATE;
+ }
+
+ public Location getLocation() {
+ return null; // not supported
+ }
+
+ public QName getName() {
+ if (state != TEXT_STATE) {
+ return name;
+ } else {
+ return null;
+ }
+ }
+
+ public String getLocalName() {
+ if (state != TEXT_STATE) {
+ return name.getLocalPart();
+ } else {
+ return null;
+ }
+ }
+
+ public boolean hasName() {
+ return state != TEXT_STATE;
+
+ }
+
+ public String getNamespaceURI() {
+ if (state != TEXT_STATE) {
+ return name.getNamespaceURI();
+ } else {
+ return null;
+ }
+
+ }
+
+ public String getPrefix() {
+ if (state != TEXT_STATE) {
+ return name.getPrefix();
+ } else {
+ return null;
+ }
+ }
+
+ public String getVersion() {
+ return null; // TODO 1.0 ?
+ }
+
+ public boolean isStandalone() {
+ return false;
+ }
+
+ public boolean standaloneSet() {
+ return false;
+ }
+
+ public String getCharacterEncodingScheme() {
+ return null;
+ }
+
+ public String getPITarget() {
+ return null;
+ }
+
+ public String getPIData() {
+ return null;
+ }
+
+ public boolean hasNext() throws XMLStreamException {
+ return state != FINAL_END_ELEMENT_STATE;
+ }
+
+ public void close() throws XMLStreamException {
+ // Do nothing - we've nothing to free here
+ }
+
+ public String getNamespaceURI(String prefix) {
+ return namespaceContext.getNamespaceURI(prefix);
+ }
+
+ public boolean isStartElement() {
+ return state == START_ELEMENT_STATE;
+ }
+
+ public boolean isEndElement() {
+ return state == END_ELEMENT_STATE;
+ }
+
+ public boolean isCharacters() {
+ return state == TEXT_STATE;
+ }
+
+ public boolean isWhiteSpace() {
+ return false; // no whitespaces here
+ }
+
+ /**
+ * Test whether the xsi namespace is present
+ */
+ private boolean isXsiNamespacePresent() {
+ return namespaceContext.getNamespaceURI(NIL_QNAME.getPrefix()) != null;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValuePairStreamReader.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValuePairStreamReader.java
new file mode 100644
index 0000000000..fdc3c4139b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NameValuePairStreamReader.java
@@ -0,0 +1,347 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
+
+
+public class NameValuePairStreamReader implements XMLFragmentStreamReader {
+
+ private static final int START_ELEMENT_STATE = 0;
+ private static final int TEXT_STATE = 1;
+ private static final int END_ELEMENT_STATE = 2;
+
+ private DelegatingNamespaceContext namespaceContext = new DelegatingNamespaceContext();
+
+ private QName name;
+ private String value;
+
+ private int state = START_ELEMENT_STATE;
+ // initiate at the start element state
+
+ // keeps track whether the namespace is declared
+ // false by default
+ private boolean nsDeclared;
+
+ public NameValuePairStreamReader(QName name, String value) {
+ this.name = name;
+ this.value = value;
+ }
+
+ public Object getProperty(String key) throws IllegalArgumentException {
+ return null;
+ }
+
+ public int next() throws XMLStreamException {
+ // no need to handle null here. it should have been handled
+ // already
+ switch (state) {
+ case START_ELEMENT_STATE:
+ state = TEXT_STATE;
+ return CHARACTERS;
+ case END_ELEMENT_STATE:
+ // oops, not supposed to happen!
+ throw new XMLStreamException("end already reached!");
+ case TEXT_STATE:
+ state = END_ELEMENT_STATE;
+ return END_ELEMENT;
+ default:
+ throw new XMLStreamException("unknown event type!");
+ }
+ }
+
+ public void require(int i, String string, String string1) throws XMLStreamException {
+ // not implemented
+ }
+
+ public String getElementText() throws XMLStreamException {
+ if (state == START_ELEMENT) {
+ // move to the end state and return the value
+ state = END_ELEMENT_STATE;
+ return value;
+ } else {
+ throw new XMLStreamException();
+ }
+
+ }
+
+ public int nextTag() throws XMLStreamException {
+ return 0; // TODO
+ }
+
+ public boolean hasNext() throws XMLStreamException {
+ return state != END_ELEMENT_STATE;
+ }
+
+ public void close() throws XMLStreamException {
+ // Do nothing - we've nothing to free here
+ }
+
+ public String getNamespaceURI(String prefix) {
+ return namespaceContext.getNamespaceURI(prefix);
+ }
+
+ public boolean isStartElement() {
+ return state == START_ELEMENT_STATE;
+ }
+
+ public boolean isEndElement() {
+ return state == END_ELEMENT_STATE;
+ }
+
+ public boolean isCharacters() {
+ return state == TEXT_STATE;
+ }
+
+ public boolean isWhiteSpace() {
+ return false; // no whitespaces here
+ }
+
+ public String getAttributeValue(String string, String string1) {
+ return null;
+ }
+
+ public int getAttributeCount() {
+ return 0;
+ }
+
+ public QName getAttributeName(int i) {
+ return null;
+ }
+
+ public String getAttributeNamespace(int i) {
+ return null;
+ }
+
+ public String getAttributeLocalName(int i) {
+ return null;
+ }
+
+ public String getAttributePrefix(int i) {
+ return null;
+ }
+
+ public String getAttributeType(int i) {
+ return null;
+ }
+
+ public String getAttributeValue(int i) {
+ return null;
+ }
+
+ public boolean isAttributeSpecified(int i) {
+ return false; // no attributes here
+ }
+
+ public int getNamespaceCount() {
+ return nsDeclared ? 1 : 0;
+ }
+
+ public String getNamespacePrefix(int i) {
+ return (nsDeclared && i == 0) ? name.getPrefix() : null;
+ }
+
+ public String getNamespaceURI(int i) {
+ return (nsDeclared && i == 0) ? name.getNamespaceURI() : null;
+ }
+
+ public NamespaceContext getNamespaceContext() {
+ return this.namespaceContext;
+ }
+
+ public int getEventType() {
+ switch (state) {
+ case START_ELEMENT_STATE:
+ return START_ELEMENT;
+ case END_ELEMENT_STATE:
+ return END_ELEMENT;
+ case TEXT_STATE:
+ return CHARACTERS;
+ default:
+ throw new UnsupportedOperationException();
+ // we've no idea what this is!!!!!
+ }
+
+ }
+
+ public String getText() {
+ if (state == TEXT_STATE) {
+ return value;
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public char[] getTextCharacters() {
+ if (state == TEXT_STATE) {
+ return value.toCharArray();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public int getTextCharacters(int i, char[] chars, int i1, int i2) throws XMLStreamException {
+ // not implemented
+ throw new UnsupportedOperationException();
+ }
+
+ public int getTextStart() {
+ if (state == TEXT_STATE) {
+ return 0;
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public int getTextLength() {
+ if (state == TEXT_STATE) {
+ return value.length();
+ } else {
+ throw new IllegalStateException();
+ }
+
+ }
+
+ public String getEncoding() {
+ return null;
+ }
+
+ public boolean hasText() {
+ return state == TEXT_STATE;
+ }
+
+ public Location getLocation() {
+ return new Location() {
+ public int getLineNumber() {
+ return 0;
+ }
+
+ public int getColumnNumber() {
+ return 0;
+ }
+
+ public int getCharacterOffset() {
+ return 0;
+ }
+
+ public String getPublicId() {
+ return null;
+ }
+
+ public String getSystemId() {
+ return null;
+ }
+ };
+ }
+
+ public QName getName() {
+ if (state != TEXT_STATE) {
+ return name;
+ } else {
+ return null;
+ }
+ }
+
+ public String getLocalName() {
+ if (state != TEXT_STATE) {
+ return name.getLocalPart();
+ } else {
+ return null;
+ }
+ }
+
+ public boolean hasName() {
+ return state != TEXT_STATE;
+
+ }
+
+ public String getNamespaceURI() {
+ if (state != TEXT_STATE) {
+ return name.getNamespaceURI();
+ } else {
+ return null;
+ }
+
+ }
+
+ public String getPrefix() {
+ if (state != TEXT_STATE) {
+ return name.getPrefix();
+ } else {
+ return null;
+ }
+ }
+
+ public String getVersion() {
+ return null; // TODO 1.0 ?
+ }
+
+ public boolean isStandalone() {
+ return false;
+ }
+
+ public boolean standaloneSet() {
+ return false;
+ }
+
+ public String getCharacterEncodingScheme() {
+ return null;
+ }
+
+ public String getPITarget() {
+ return null;
+ }
+
+ public String getPIData() {
+ return null;
+ }
+
+ public boolean isDone() {
+ return state == END_ELEMENT_STATE;
+ }
+
+ public void setParentNamespaceContext(NamespaceContext nsContext) {
+ this.namespaceContext.setParentNsContext(nsContext);
+ }
+
+ public void init() {
+ // just add the current elements namespace and prefix to the this
+ // elements nscontext
+ addToNsMap(name.getPrefix(), name.getNamespaceURI());
+
+ }
+
+ /**
+ * @param prefix
+ * @param uri
+ */
+ private void addToNsMap(String prefix, String uri) {
+ // TODO - need to fix this up to cater for cases where
+ // namespaces are having no prefixes
+ if (!uri.equals(namespaceContext.getNamespaceURI(prefix))) {
+ // this namespace is not there. Need to declare it
+ namespaceContext.pushNamespace(prefix, uri);
+ nsDeclared = true;
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NamedProperty.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NamedProperty.java
new file mode 100644
index 0000000000..04d7d65a0d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NamedProperty.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+/**
+ * A named property
+ *
+ * @version $Rev$ $Date$
+ */
+public class NamedProperty implements Map.Entry<QName, Object> {
+ private QName key;
+
+ private Object value;
+
+ public NamedProperty(QName key, Object value) {
+ this.key = key;
+ this.value = value;
+ }
+
+ public NamedProperty(String key, Object value) {
+ this.key = new QName(key);
+ this.value = value;
+ }
+
+ public QName getKey() {
+ return key;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public Object setValue(Object value) {
+ Object v = this.value;
+ this.value = value;
+ return v;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NilElementStreamReader.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NilElementStreamReader.java
new file mode 100644
index 0000000000..abc4bf3785
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/NilElementStreamReader.java
@@ -0,0 +1,279 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
+
+public class NilElementStreamReader implements XMLFragmentStreamReader {
+
+ private static final int END_ELEMENT_STATE = 2;
+
+ private static final int START_ELEMENT_STATE = 1;
+ private int currentState = START_ELEMENT;
+
+ private QName elementQName;
+
+ public NilElementStreamReader(QName elementQName) {
+ this.elementQName = elementQName;
+ }
+
+ public void setParentNamespaceContext(NamespaceContext nsContext) {
+ // NOOP
+ }
+
+ public void close() throws XMLStreamException {
+ // do nothing
+ }
+
+ public int getAttributeCount() {
+ return 1;
+ }
+
+ public String getAttributeLocalName(int i) {
+ return (i == 0) ? NIL_QNAME.getLocalPart() : null;
+ }
+
+ public QName getAttributeName(int i) {
+ return (i == 0) ? NIL_QNAME : null;
+ }
+
+ public String getAttributeNamespace(int i) {
+ return (i == 0) ? NIL_QNAME.getNamespaceURI() : null;
+ }
+
+ public String getAttributePrefix(int i) {
+ return (i == 0) ? NIL_QNAME.getPrefix() : null;
+ }
+
+ public String getAttributeType(int i) {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getAttributeValue(int i) {
+ return (i == 0) ? NIL_VALUE_TRUE : null;
+ }
+
+ public String getAttributeValue(String string, String string1) {
+ if (string == null && NIL_QNAME.getLocalPart().equals(string1)) {
+ return NIL_VALUE_TRUE;
+ }
+ return null;
+ }
+
+ public String getCharacterEncodingScheme() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getElementText() throws XMLStreamException {
+ return null;
+ }
+
+ public String getEncoding() {
+ return null;
+ }
+
+ public int getEventType() {
+ int returnEvent = START_DOCUMENT;
+ switch (currentState) {
+ case START_ELEMENT_STATE:
+ returnEvent = START_ELEMENT;
+ break;
+ case END_ELEMENT_STATE:
+ returnEvent = END_ELEMENT;
+ break;
+ }
+ return returnEvent;
+ }
+
+ public String getLocalName() {
+ return elementQName.getLocalPart();
+ }
+
+ public Location getLocation() {
+ return new Location() {
+ public int getCharacterOffset() {
+ return 0;
+ }
+
+ public int getColumnNumber() {
+ return 0;
+ }
+
+ public int getLineNumber() {
+ return 0;
+ }
+
+ public String getPublicId() {
+ return null;
+ }
+
+ public String getSystemId() {
+ return null;
+ }
+ };
+ }
+
+ public QName getName() {
+ return elementQName;
+ }
+
+ public NamespaceContext getNamespaceContext() {
+ throw new UnsupportedOperationException();
+ }
+
+ public int getNamespaceCount() {
+ return 0;
+ }
+
+ public String getNamespacePrefix(int i) {
+ return null;
+ }
+
+ public String getNamespaceURI() {
+ return elementQName.getNamespaceURI();
+ }
+
+ public String getNamespaceURI(int i) {
+ return null;
+ }
+
+ public String getNamespaceURI(String string) {
+ if (elementQName.getPrefix() != null && elementQName.getPrefix().equals(string)) {
+ return elementQName.getNamespaceURI();
+ } else {
+ return null;
+ }
+ }
+
+ public String getPIData() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getPITarget() {
+ throw new UnsupportedOperationException();
+ }
+
+ public String getPrefix() {
+ return elementQName.getPrefix();
+ }
+
+ public Object getProperty(String key) throws IllegalArgumentException {
+ // since optimization is a global property
+ // we've to implement it everywhere
+ return null;
+ }
+
+ public String getText() {
+ return null;
+ }
+
+ public char[] getTextCharacters() {
+ return new char[0];
+ }
+
+ public int getTextCharacters(int i, char[] chars, int i1, int i2) throws XMLStreamException {
+ return 0;
+ }
+
+ public int getTextLength() {
+ return 0;
+ }
+
+ public int getTextStart() {
+ return 0;
+ }
+
+ public String getVersion() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean hasName() {
+ return true;
+ }
+
+ public boolean hasNext() throws XMLStreamException {
+ return currentState != END_ELEMENT_STATE;
+
+ }
+
+ public boolean hasText() {
+ return false;
+ }
+
+ public void init() {
+ // NOOP
+ }
+
+ public boolean isAttributeSpecified(int i) {
+ return i == 0;
+ }
+
+ public boolean isCharacters() {
+ return false;
+ }
+
+ public boolean isDone() {
+ return currentState == END_ELEMENT_STATE;
+ }
+
+ public boolean isEndElement() {
+ return currentState == END_ELEMENT_STATE;
+ }
+
+ public boolean isStandalone() {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean isStartElement() {
+ return currentState == START_ELEMENT_STATE;
+ }
+
+ public boolean isWhiteSpace() {
+ return false;
+ }
+
+ public int next() throws XMLStreamException {
+ int returnEvent = START_DOCUMENT;
+ switch (currentState) {
+ case START_ELEMENT_STATE:
+ currentState = END_ELEMENT_STATE;
+ returnEvent = END_ELEMENT;
+ break;
+ case END_ELEMENT_STATE:
+ throw new XMLStreamException("parser completed!");
+
+ }
+ return returnEvent;
+ }
+
+ public int nextTag() throws XMLStreamException {
+ throw new UnsupportedOperationException();
+ }
+
+ public void require(int i, String string, String string1) throws XMLStreamException {
+ // nothing
+ }
+
+ public boolean standaloneSet() {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2OutputStream.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2OutputStream.java
new file mode 100644
index 0000000000..5500d0bcca
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2OutputStream.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.io.OutputStream;
+
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.tuscany.sca.databinding.PushTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.w3c.dom.Node;
+
+/**
+ * Push DOM Node to OutputStream
+ *
+ * @version $Rev$ $Date$
+ */
+public class Node2OutputStream extends BaseTransformer<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);
+ }
+ }
+
+ @Override
+ protected Class<Node> getSourceType() {
+ return Node.class;
+ }
+
+ @Override
+ protected Class<OutputStream> getTargetType() {
+ return OutputStream.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2SimpleJavaType.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2SimpleJavaType.java
new file mode 100644
index 0000000000..d5bf7e76b5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2SimpleJavaType.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import org.apache.tuscany.sca.databinding.impl.SimpleType2JavaTransformer;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * Transformer to convert data from a simple java Object to OMElement.
+ *
+ * @version $Rev$ $Date$
+ */
+public class Node2SimpleJavaType extends SimpleType2JavaTransformer<Node> {
+
+ @Override
+ protected String getText(Node source) {
+ if (source instanceof Document) {
+ source = ((Document)source).getDocumentElement();
+ }
+ return source.getTextContent();
+
+ }
+
+ @Override
+ public Class getSourceType() {
+ return Node.class;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2SourceTransformer.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2SourceTransformer.java
new file mode 100644
index 0000000000..3c9022bc3c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2SourceTransformer.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.w3c.dom.Node;
+
+/**
+ * Transform TrAX Node to Source
+ *
+ * @version $Rev$ $Date$
+ */
+public class Node2SourceTransformer extends BaseTransformer<Node, Source> implements
+ PullTransformer<Node, Source> {
+
+ public Source transform(Node source, TransformationContext context) {
+ try {
+ return new DOMSource(source);
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ @Override
+ protected Class<Node> getSourceType() {
+ return Node.class;
+ }
+
+ @Override
+ protected Class<Source> getTargetType() {
+ return Source.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2String.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2String.java
new file mode 100644
index 0000000000..1b54b1fd1e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2String.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.io.StringWriter;
+
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.w3c.dom.Node;
+
+/**
+ * Transform DOM Node to XML String
+ *
+ * @version $Rev$ $Date$
+ */
+public class Node2String extends BaseTransformer<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);
+ }
+ }
+
+ @Override
+ public Class<Node> getSourceType() {
+ return Node.class;
+ }
+
+ @Override
+ public Class<String> getTargetType() {
+ return String.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2Writer.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2Writer.java
new file mode 100644
index 0000000000..c9631595dc
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2Writer.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.io.Writer;
+
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.tuscany.sca.databinding.PushTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.w3c.dom.Node;
+
+/**
+ * Push DOM Node to Writer
+ *
+ * @version $Rev$ $Date$
+ */
+public class Node2Writer extends BaseTransformer<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);
+ }
+ }
+
+ @Override
+ protected Class<Node> getSourceType() {
+ return Node.class;
+ }
+
+ @Override
+ protected Class<Writer> getTargetType() {
+ return Writer.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2XMLStreamReader.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2XMLStreamReader.java
new file mode 100644
index 0000000000..1e8d14a151
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Node2XMLStreamReader.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.w3c.dom.Node;
+
+/**
+ * Transform DOM Node to XML XMLStreamReader
+ *
+ * @version $Rev$ $Date$
+ */
+public class Node2XMLStreamReader extends BaseTransformer<Node, XMLStreamReader> implements
+ PullTransformer<Node, XMLStreamReader> {
+
+ public XMLStreamReader transform(Node source, TransformationContext context) {
+ if (source == null) {
+ return null;
+ }
+ try {
+ DOMXMLStreamReader reader = new DOMXMLStreamReader(source);
+ return reader;
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ @Override
+ protected Class<Node> getSourceType() {
+ return Node.class;
+ }
+
+ @Override
+ protected Class<XMLStreamReader> getTargetType() {
+ return XMLStreamReader.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2Node.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2Node.java
new file mode 100644
index 0000000000..70387fa862
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2Node.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.io.Reader;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMResult;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.w3c.dom.Node;
+
+/**
+ * Push DOM Reader to Node
+ *
+ * @version $Rev$ $Date$
+ */
+public class Reader2Node extends BaseTransformer<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);
+ }
+ }
+
+ @Override
+ protected Class<Reader> getSourceType() {
+ return Reader.class;
+ }
+
+ @Override
+ protected Class<Node> getTargetType() {
+ return Node.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2SAX.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2SAX.java
new file mode 100644
index 0000000000..188ecaffa3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Reader2SAX.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.io.Reader;
+
+import org.apache.tuscany.sca.databinding.PushTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+
+/**
+ * Transform XML string to SAX
+ *
+ * @version $Rev$ $Date$
+ */
+public class Reader2SAX extends BaseTransformer<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);
+ }
+ }
+
+ @Override
+ protected Class<Reader> getSourceType() {
+ return Reader.class;
+ }
+
+ @Override
+ protected Class<ContentHandler> getTargetType() {
+ return ContentHandler.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOM.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOM.java
new file mode 100644
index 0000000000..38c61d64c8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOM.java
@@ -0,0 +1,246 @@
+/*
+ * Copyright 2001-2004 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Stack;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.tuscany.sca.databinding.impl.DOMHelper;
+import org.w3c.dom.Comment;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.ProcessingInstruction;
+import org.w3c.dom.Text;
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.ext.LexicalHandler;
+
+/**
+ * SAX2DOM adapter
+ *
+ * @version $Rev$ $Date$
+ */
+public class SAX2DOM implements ContentHandler, LexicalHandler {
+ public static final String EMPTYSTRING = "";
+ public static final String XML_PREFIX = "xml";
+ public static final String XMLNS_PREFIX = "xmlns";
+ public static final String XMLNS_STRING = "xmlns:";
+ public static final String XMLNS_URI = "http://www.w3.org/2000/xmlns/";
+
+ private Node root;
+
+ private Document document;
+
+ private Node nextSibling;
+
+ private Stack<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 = nodeStk.peek();
+
+ // No text nodes can be children of root (DOM006 exception)
+ if (last != document) {
+ final String text = new String(ch, start, length);
+ if (lastSibling != null && lastSibling.getNodeType() == Node.TEXT_NODE) {
+ ((Text)lastSibling).appendData(text);
+ } else if (last == root && nextSibling != null) {
+ lastSibling = last.insertBefore(document.createTextNode(text), nextSibling);
+ } else {
+ lastSibling = last.appendChild(document.createTextNode(text));
+ }
+
+ }
+ }
+
+ public void startDocument() {
+ nodeStk.push(root);
+ }
+
+ public void endDocument() {
+ nodeStk.pop();
+ }
+
+ public void startElement(String namespace, String localName, String qName, Attributes attrs) {
+ final Element tmp = document.createElementNS(namespace, qName);
+
+ // Add namespace declarations first
+ if (namespaceDecls != null) {
+ final int nDecls = namespaceDecls.size();
+ for (int i = 0; i < nDecls; i++) {
+ final String prefix = namespaceDecls.get(i++);
+
+ if (prefix == null || prefix.equals(EMPTYSTRING)) {
+ tmp.setAttributeNS(XMLNS_URI, XMLNS_PREFIX, namespaceDecls.get(i));
+ } else {
+ tmp.setAttributeNS(XMLNS_URI, XMLNS_STRING + prefix, namespaceDecls.get(i));
+ }
+ }
+ namespaceDecls.clear();
+ }
+
+ // Add attributes to element
+ final int nattrs = attrs.getLength();
+ for (int i = 0; i < nattrs; i++) {
+ if (attrs.getLocalName(i) == null) {
+ tmp.setAttribute(attrs.getQName(i), attrs.getValue(i));
+ } else {
+ tmp.setAttributeNS(attrs.getURI(i), attrs.getQName(i), attrs.getValue(i));
+ }
+ }
+
+ // Append this new node onto current stack node
+ Node last = nodeStk.peek();
+
+ // If the SAX2DOM is created with a non-null next sibling node,
+ // insert the result nodes before the next sibling under the root.
+ if (last == root && nextSibling != null) {
+ last.insertBefore(tmp, nextSibling);
+ } else {
+ last.appendChild(tmp);
+ }
+
+ // Push this node onto stack
+ nodeStk.push(tmp);
+ lastSibling = null;
+ }
+
+ public void endElement(String namespace, String localName, String qName) {
+ nodeStk.pop();
+ lastSibling = null;
+ }
+
+ public void startPrefixMapping(String prefix, String uri) {
+ if (namespaceDecls == null) {
+ namespaceDecls = new ArrayList<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 = nodeStk.peek();
+ ProcessingInstruction pi = document.createProcessingInstruction(target, data);
+ if (pi != null) {
+ if (last == root && nextSibling != null) {
+ last.insertBefore(pi, nextSibling);
+ } else {
+ last.appendChild(pi);
+ }
+
+ lastSibling = pi;
+ }
+ }
+
+ /**
+ * This class is only used internally so this method should never be called.
+ */
+ public void setDocumentLocator(Locator locator) {
+ }
+
+ /**
+ * This class is only used internally so this method should never be called.
+ */
+ public void skippedEntity(String name) {
+ }
+
+ /**
+ * Lexical Handler method to create comment node in DOM tree.
+ */
+ public void comment(char[] ch, int start, int length) {
+ final Node last = nodeStk.peek();
+ Comment comment = document.createComment(new String(ch, start, length));
+ if (comment != null) {
+ if (last == root && nextSibling != null) {
+ last.insertBefore(comment, nextSibling);
+ } else {
+ last.appendChild(comment);
+ }
+
+ lastSibling = comment;
+ }
+ }
+
+ // Lexical Handler methods- not implemented
+ public void startCDATA() {
+ }
+
+ public void endCDATA() {
+ }
+
+ public void startEntity(java.lang.String name) {
+ }
+
+ public void endDTD() {
+ }
+
+ public void endEntity(String name) {
+ }
+
+ public void startDTD(String name, String publicId, String systemId) throws SAXException {
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOMPipe.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOMPipe.java
new file mode 100644
index 0000000000..cb9d538389
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SAX2DOMPipe.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.tuscany.sca.databinding.DataPipe;
+import org.apache.tuscany.sca.databinding.DataPipeTransformer;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.w3c.dom.Node;
+import org.xml.sax.ContentHandler;
+
+public class SAX2DOMPipe extends BaseTransformer<ContentHandler, Node> implements DataPipeTransformer<ContentHandler, Node> {
+
+ /**
+ *
+ */
+ public SAX2DOMPipe() {
+ super();
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.DataPipeTransformer#newInstance()
+ */
+ public DataPipe<ContentHandler, Node> newInstance() {
+ return new Pipe();
+ }
+
+ @Override
+ protected Class<Node> getTargetType() {
+ return Node.class;
+ }
+
+ @Override
+ protected Class<ContentHandler> getSourceType() {
+ return ContentHandler.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 30;
+ }
+
+ private static class Pipe implements DataPipe<ContentHandler, Node> {
+ private SAX2DOM pipe;
+
+ public Pipe() {
+ super();
+ try {
+ this.pipe = new SAX2DOM();
+ } catch (ParserConfigurationException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ public Node getResult() {
+ return pipe.getDOM();
+ }
+
+ public ContentHandler getSink() {
+ return pipe;
+ }
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SimpleJavaType2Node.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SimpleJavaType2Node.java
new file mode 100644
index 0000000000..d2625fba11
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SimpleJavaType2Node.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.impl.DOMHelper;
+import org.apache.tuscany.sca.databinding.impl.Java2SimpleTypeTransformer;
+import org.apache.tuscany.sca.databinding.javabeans.Java2XMLMapperException;
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * Transformer to convert data from an simple OMElement to Java Object
+ *
+ * @version $Rev$ $Date$
+ */
+public class SimpleJavaType2Node extends Java2SimpleTypeTransformer<Node> {
+
+ private Document factory;
+
+ public SimpleJavaType2Node() {
+ super();
+ try {
+ factory = DOMHelper.newDocument();
+ } catch (ParserConfigurationException e) {
+ throw new Java2XMLMapperException(e);
+ }
+ }
+
+ @Override
+ protected Node createElement(QName element, String text, TransformationContext context) {
+ if (element == null) {
+ element = DOMDataBinding.ROOT_ELEMENT;
+ }
+ Node root = DOMHelper.createElement(factory, element);
+ if (text != null) {
+ root.appendChild(factory.createTextNode(text));
+ } else {
+ Attr nil = factory.createAttributeNS("http://www.w3.org/2001/XMLSchema-instance", "xsi:nil");
+ nil.setValue("true");
+ root.appendChild(nil);
+ }
+ return root;
+ }
+
+ @Override
+ public Class getTargetType() {
+ return Node.class;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SimpleXmlNodeImpl.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SimpleXmlNodeImpl.java
new file mode 100644
index 0000000000..e041f85214
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/SimpleXmlNodeImpl.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class SimpleXmlNodeImpl implements XmlNode {
+ private static final String XSI_PREFIX = "xsi";
+ private static final String XSI_NS = "http://www.w3.org/2001/XMLSchema-instance";
+ private static final QName XSI_NIL = new QName(XSI_NS, "nil", XSI_PREFIX);
+ private static final Map<String, String> NS_MAP = new HashMap<String, String>();
+ static {
+ NS_MAP.put(XSI_PREFIX, XSI_NS);
+ }
+
+ protected Type type;
+ protected QName name;
+ protected Object value;
+
+ public SimpleXmlNodeImpl(QName name, Object value) {
+ this(name, value, name != null ? Type.ELEMENT : Type.CHARACTERS);
+ }
+
+ public SimpleXmlNodeImpl(QName name, Object value, Type type) {
+ super();
+ this.type = type;
+ this.name = name;
+ this.value = value;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.xml.XmlNode#attributes()
+ */
+ public List<XmlNode> attributes() {
+ if (type == Type.ELEMENT && value == null) {
+ // Nil element
+ XmlNode attr = new SimpleXmlNodeImpl(XSI_NIL, "true");
+ return Arrays.asList(attr);
+ }
+ return null;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.xml.XmlNode#children()
+ */
+ public Iterator<XmlNode> children() {
+ if (type == Type.ELEMENT && value != null) {
+ // Nil element
+ XmlNode node = new SimpleXmlNodeImpl(null, value);
+ return Arrays.asList(node).iterator();
+ }
+ return null;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.xml.XmlNode#getName()
+ */
+ public QName getName() {
+ return name;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.xml.XmlNode#getValue()
+ */
+ public String getValue() {
+ return value == null ? null : String.valueOf(value);
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.xml.XmlNode#namespaces()
+ */
+ public Map<String, String> namespaces() {
+ if (type == Type.ELEMENT && value == null) {
+ return NS_MAP;
+ }
+ return null;
+ }
+
+ public Type getType() {
+ return type;
+ }
+
+ public void setType(Type type) {
+ this.type = type;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2NodeTransformer.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2NodeTransformer.java
new file mode 100644
index 0000000000..ee9aa1bb76
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2NodeTransformer.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMResult;
+
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.apache.tuscany.sca.databinding.impl.DOMHelper;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * Transform TrAX Source to Node
+ *
+ * @version $Rev$ $Date$
+ */
+public class Source2NodeTransformer extends BaseTransformer<Source, Node> implements
+ PullTransformer<Source, Node> {
+ private static final TransformerFactory FACTORY = TransformerFactory.newInstance();
+
+ public Node transform(Source source, TransformationContext context) {
+ try {
+ javax.xml.transform.Transformer transformer = FACTORY.newTransformer();
+ DOMResult result = new DOMResult();
+ transformer.transform(source, result);
+ Document doc = (Document) result.getNode();
+ return DOMHelper.adjustElementName(context, doc.getDocumentElement());
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ @Override
+ protected Class<Source> getSourceType() {
+ return Source.class;
+ }
+
+ @Override
+ protected Class<Node> getTargetType() {
+ return Node.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2ResultTransformer.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2ResultTransformer.java
new file mode 100644
index 0000000000..8a2b6b39aa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2ResultTransformer.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerFactory;
+
+import org.apache.tuscany.sca.databinding.PushTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+
+/**
+ * Transform TrAX Source to Result
+ *
+ * @version $Rev$ $Date$
+ */
+public class Source2ResultTransformer extends BaseTransformer<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);
+ }
+ }
+
+ @Override
+ protected Class<Source> getSourceType() {
+ return Source.class;
+ }
+
+ @Override
+ protected Class<Result> getTargetType() {
+ return Result.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2StringTransformer.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2StringTransformer.java
new file mode 100644
index 0000000000..2ed548ad76
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Source2StringTransformer.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.io.StringWriter;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.stream.StreamResult;
+
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+
+/**
+ * Transform TrAX Source to String
+ *
+ * @version $Rev$ $Date$
+ */
+public class Source2StringTransformer extends BaseTransformer<Source, String> implements
+ PullTransformer<Source, String> {
+ private static final TransformerFactory FACTORY = TransformerFactory.newInstance();
+
+ public String transform(Source source, TransformationContext context) {
+ try {
+ javax.xml.transform.Transformer transformer = FACTORY.newTransformer();
+ StringWriter sw = new StringWriter();
+ StreamResult result = new StreamResult(sw);
+ transformer.transform(source, result);
+ return sw.toString();
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ @Override
+ protected Class<Source> getSourceType() {
+ return Source.class;
+ }
+
+ @Override
+ protected Class<String> getTargetType() {
+ return String.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAX2SAXAdapter.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAX2SAXAdapter.java
new file mode 100644
index 0000000000..6257681091
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAX2SAXAdapter.java
@@ -0,0 +1,256 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+/**
+ * Adapter that converts from StAX to SAX event streams. Currently the following
+ * SAX events are not generated:
+ * <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/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAXDataBinding.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAXDataBinding.java
new file mode 100644
index 0000000000..52a1d02631
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAXDataBinding.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.xml;
+
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.databinding.impl.BaseDataBinding;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+
+/**
+ * A DataBinding for the StAX
+ *
+ * @version $Rev$ $Date$
+ */
+public class StAXDataBinding extends BaseDataBinding {
+ public static final String NAME = XMLStreamReader.class.getName();
+ public static final String[] ALIASES = new String[] {"stax"};
+
+ public StAXDataBinding() {
+ super(NAME, ALIASES, XMLStreamReader.class);
+ }
+
+ @Override
+ public boolean introspect(DataType type, Operation operation) {
+ if (super.introspect(type, operation)) {
+ type.setLogical(XMLType.UNKNOWN);
+ type.setDataBinding(NAME);
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAXHelper.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAXHelper.java
new file mode 100644
index 0000000000..103ecbd7d1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StAXHelper.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.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 javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import 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() {
+ }
+
+ 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/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StreamDataPipe.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StreamDataPipe.java
new file mode 100644
index 0000000000..f8967e35b6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/StreamDataPipe.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.tuscany.sca.databinding.DataPipe;
+import org.apache.tuscany.sca.databinding.DataPipeTransformer;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+
+public class StreamDataPipe extends BaseTransformer<OutputStream, InputStream> implements
+ DataPipeTransformer<OutputStream, InputStream> {
+
+ public DataPipe<OutputStream, InputStream> newInstance() {
+ return new Pipe();
+ }
+
+ @Override
+ protected Class<InputStream> getTargetType() {
+ return InputStream.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 50;
+ }
+
+ @Override
+ protected Class<OutputStream> getSourceType() {
+ return OutputStream.class;
+ }
+
+ public static class Pipe implements DataPipe<OutputStream, InputStream> {
+ private ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+
+ public InputStream getResult() {
+ return new ByteArrayInputStream(outputStream.toByteArray());
+ }
+
+ public OutputStream getSink() {
+ return outputStream;
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2Node.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2Node.java
new file mode 100644
index 0000000000..062e10cc45
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/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.sca.databinding.xml;
+
+import java.io.StringReader;
+
+import javax.xml.parsers.DocumentBuilder;
+
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.apache.tuscany.sca.databinding.impl.DOMHelper;
+import org.w3c.dom.Node;
+import org.xml.sax.InputSource;
+
+public class String2Node extends BaseTransformer<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);
+ }
+ }
+
+ @Override
+ protected Class<String> getSourceType() {
+ return String.class;
+ }
+
+ @Override
+ protected Class<Node> getTargetType() {
+ return Node.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 50;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2SAX.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2SAX.java
new file mode 100644
index 0000000000..c56dba1843
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2SAX.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.io.StringReader;
+
+import org.apache.tuscany.sca.databinding.PushTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+
+/**
+ * Transform XML string to SAX
+ *
+ * @version $Rev$ $Date$
+ */
+public class String2SAX extends BaseTransformer<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);
+ }
+ }
+
+ @Override
+ protected Class<String> getSourceType() {
+ return String.class;
+ }
+
+ @Override
+ protected Class<ContentHandler> getTargetType() {
+ return ContentHandler.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2SourceTransformer.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2SourceTransformer.java
new file mode 100644
index 0000000000..c2de202a9b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2SourceTransformer.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.io.StringReader;
+
+import javax.xml.transform.Source;
+import javax.xml.transform.stream.StreamSource;
+
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+
+/**
+ * Transform XML String to Source
+ *
+ * @version $Rev$ $Date$
+ */
+public class String2SourceTransformer extends BaseTransformer<String, Source> implements
+ PullTransformer<String, Source> {
+
+ public Source transform(String source, TransformationContext context) {
+ try {
+ return new StreamSource(new StringReader(source));
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ @Override
+ protected Class<String> getSourceType() {
+ return String.class;
+ }
+
+ @Override
+ protected Class<Source> getTargetType() {
+ return Source.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2XMLStreamReader.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/String2XMLStreamReader.java
new file mode 100644
index 0000000000..a7364006d0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/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.sca.databinding.xml;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+
+public class String2XMLStreamReader extends BaseTransformer<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);
+ }
+ }
+
+ @Override
+ protected Class<String> getSourceType() {
+ return String.class;
+ }
+
+ @Override
+ protected Class<XMLStreamReader> getTargetType() {
+ return XMLStreamReader.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 50;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/WrappingXMLStreamReader.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/WrappingXMLStreamReader.java
new file mode 100644
index 0000000000..d73e495798
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/WrappingXMLStreamReader.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.util.StreamReaderDelegate;
+
+public class WrappingXMLStreamReader extends StreamReaderDelegate implements XMLFragmentStreamReader {
+
+ private boolean done;
+ private int level;
+
+ public WrappingXMLStreamReader(XMLStreamReader realReader) throws XMLStreamException {
+ super(realReader);
+ if (realReader == null) {
+ throw new UnsupportedOperationException("Reader cannot be null");
+ }
+
+ if (realReader instanceof XMLFragmentStreamReader) {
+ ((XMLFragmentStreamReader)realReader).init();
+ }
+
+ if (realReader.getEventType() == START_DOCUMENT) {
+ // Position to the 1st element
+ realReader.nextTag();
+ }
+ if (realReader.getEventType() != START_ELEMENT) {
+ throw new IllegalStateException("The reader is not positioned at START_DOCUMENT or START_ELEMENT");
+ }
+ this.done = false;
+ this.level = 1;
+ }
+
+ @Override
+ public boolean hasNext() throws XMLStreamException {
+ return !done && super.hasNext();
+ }
+
+ @Override
+ public int next() throws XMLStreamException {
+ if (!hasNext()) {
+ throw new IllegalStateException("No more events");
+ }
+ int event = super.next();
+ if (!super.hasNext()) {
+ done = true;
+ }
+ if (event == START_ELEMENT) {
+ level++;
+ } else if (event == END_ELEMENT) {
+ level--;
+ if (level == 0) {
+ done = true;
+ }
+ }
+ return event;
+ }
+
+ @Override
+ public int nextTag() throws XMLStreamException {
+ int event = 0;
+ while (true) {
+ event = next();
+ if (event == START_ELEMENT || event == END_ELEMENT) {
+ return event;
+ }
+ }
+ }
+
+ public void setParentNamespaceContext(NamespaceContext nsContext) {
+ // nothing to do here
+ }
+
+ public void init() {
+ // Nothing to do here
+ }
+
+ public boolean isDone() {
+ return done;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Writer2ReaderDataPipe.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Writer2ReaderDataPipe.java
new file mode 100644
index 0000000000..5ab7272d58
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/Writer2ReaderDataPipe.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+
+import org.apache.tuscany.sca.databinding.DataPipe;
+import org.apache.tuscany.sca.databinding.DataPipeTransformer;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+
+public class Writer2ReaderDataPipe extends BaseTransformer<Writer, Reader> implements DataPipeTransformer<Writer, Reader> {
+
+ public DataPipe<Writer, Reader> newInstance() {
+ return new Pipe();
+ }
+
+ @Override
+ protected Class<Reader> getTargetType() {
+ return Reader.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 50;
+ }
+
+ @Override
+ protected Class<Writer> getSourceType() {
+ return Writer.class;
+ }
+
+ private static class Pipe implements DataPipe<Writer, Reader> {
+ private StringWriter writer = new StringWriter();
+
+ public Reader getResult() {
+ return new StringReader(writer.toString());
+ }
+
+ public Writer getSink() {
+ return writer;
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLDocumentStreamReader.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLDocumentStreamReader.java
new file mode 100644
index 0000000000..cd33e64176
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLDocumentStreamReader.java
@@ -0,0 +1,482 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.util.NoSuchElementException;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * This class is derived from Apache Axis2 class
+ * org.apache.axis2.util.StreamWrapper</a>. It's used wrap a XMLStreamReader to
+ * create a XMLStreamReader representing a document and it will produce
+ * START_DOCUMENT, END_DOCUMENT events.
+ *
+ * @version $Rev$ $Date$
+ */
+public class XMLDocumentStreamReader implements XMLStreamReader {
+ private static final int STATE_COMPLETE_AT_NEXT = 2; // The wrapper
+ // will produce
+ // END_DOCUMENT
+
+ private static final int STATE_COMPLETED = 3; // Done
+
+ private static final int STATE_INIT = 0; // The wrapper will produce
+ // START_DOCUMENT
+
+ private static final int STATE_SWITCHED = 1; // The real reader will
+ // produce events
+
+ private XMLStreamReader realReader;
+ private boolean fragment;
+ private int level = 0;
+
+ private int state = STATE_INIT;
+
+ public XMLDocumentStreamReader(XMLStreamReader realReader) {
+ if (realReader == null) {
+ throw new UnsupportedOperationException("Reader cannot be null");
+ }
+
+ this.realReader = realReader;
+
+ if (realReader instanceof XMLFragmentStreamReader) {
+ ((XMLFragmentStreamReader)realReader).init();
+ }
+
+ // If the real reader is positioned at START_DOCUMENT, always use
+ // the real reader
+ if (realReader.getEventType() == START_DOCUMENT) {
+ fragment = false;
+ state = STATE_SWITCHED;
+ }
+ }
+
+ public void close() throws XMLStreamException {
+ realReader.close();
+ }
+
+ public int getAttributeCount() {
+ if (isDelegating()) {
+ return realReader.getAttributeCount();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeLocalName(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributeLocalName(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public QName getAttributeName(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributeName(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeNamespace(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributeNamespace(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributePrefix(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributePrefix(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeType(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributeType(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeValue(int i) {
+ if (isDelegating()) {
+ return realReader.getAttributeValue(i);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getAttributeValue(String s, String s1) {
+ if (isDelegating()) {
+ return realReader.getAttributeValue(s, s1);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public String getCharacterEncodingScheme() {
+ 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;
+ }
+ if (fragment && returnEvent == END_ELEMENT) {
+ level--;
+ if (level == 0) {
+ // We are now at the end of the top-level element in the fragment
+ state = STATE_COMPLETE_AT_NEXT;
+ }
+ }
+ if (fragment && returnEvent == START_ELEMENT) {
+ level++;
+ }
+ break;
+ case STATE_INIT:
+ state = STATE_SWITCHED;
+ returnEvent = realReader.getEventType();
+ if (returnEvent == START_ELEMENT) {
+ // The real reader is positioned at the top-level element in the fragment
+ level = 0;
+ fragment = true;
+ }
+ break;
+ case STATE_COMPLETE_AT_NEXT:
+ state = STATE_COMPLETED;
+ returnEvent = END_DOCUMENT;
+ break;
+ case STATE_COMPLETED:
+ // oops - no way we can go beyond this
+ throw new NoSuchElementException("End of stream has reached.");
+ default:
+ throw new UnsupportedOperationException();
+ }
+
+ return returnEvent;
+ }
+
+ public int nextTag() throws XMLStreamException {
+ if (isDelegating()) {
+ int returnEvent = realReader.nextTag();
+ if (fragment && returnEvent == END_ELEMENT) {
+ level--;
+ if (level == 0) {
+ // We are now at the end of the top-level element in the fragment
+ state = STATE_COMPLETE_AT_NEXT;
+ }
+ }
+ if (fragment && returnEvent == START_ELEMENT) {
+ level++;
+ }
+ return returnEvent;
+ } else {
+ throw new XMLStreamException();
+ }
+ }
+
+ public void require(int i, String s, String s1) throws XMLStreamException {
+ if (isDelegating()) {
+ realReader.require(i, s, s1);
+ }
+ }
+
+ public boolean standaloneSet() {
+ if (isDelegating()) {
+ return realReader.standaloneSet();
+ } else {
+ return false;
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLFragmentStreamReader.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLFragmentStreamReader.java
new file mode 100644
index 0000000000..a42d6acc9a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLFragmentStreamReader.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+
+public interface XMLFragmentStreamReader extends XMLStreamReader {
+ QName NIL_QNAME = new QName("http://www.w3.org/2001/XMLSchema-instance", "nil", "xsi");
+ String NIL_VALUE_TRUE = "true";
+
+ /**
+ * this will help to handle Text within the current element. user should
+ * pass the element text to the property list as this ELEMENT_TEXT as the
+ * key. This key deliberately has a space in it so that it is not a valid
+ * XML name
+ */
+ String ELEMENT_TEXT = "Element Text";
+
+ /**
+ * Extra method to query the state of the pullparser
+ */
+ boolean isDone();
+
+ /**
+ * add the parent namespace context to this parser
+ */
+ void setParentNamespaceContext(NamespaceContext nsContext);
+
+ /**
+ * Initiate the parser - this will do whatever the needed tasks to initiate
+ * the parser and must be called before attempting any specific parsing
+ * using this parser
+ */
+ void init();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLFragmentStreamReaderImpl.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLFragmentStreamReaderImpl.java
new file mode 100644
index 0000000000..f1084cf2a3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLFragmentStreamReaderImpl.java
@@ -0,0 +1,857 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * This is the new implementation of the XMLFramentStreamReader. The approach
+ * here is simple When the pull parser needs to generate events for a particular
+ * name-value(s) pair it always hands over (delegates) the task to another pull
+ * parser which knows how to deal with it The common types of name value pairs
+ * we'll come across are
+ * <ul>
+ * <li> String name/QName name - String value
+ * <li> String name/QName name - String[] value
+ * <li> QName name/String name - XMLStreamReader value
+ * <li> QName name/String name - XMLStreamable value
+ * <li> QName name/String name - Java bean
+ * <li> QName name/String name - Datahandler
+ *
+ * </ul>
+ * <p/> As for the attributes, these are the possible combinations in the array
+ * <ul>
+ * <li> String name/QName name - String value
+ * </ul>
+ * Note that certain array methods have been deliberately removed to avoid
+ * complications. The generated code will take the trouble to lay the elements
+ * of the array in the correct order <p/> <p/> Hence there will be a parser impl
+ * that knows how to handle these types, and this parent parser will always
+ * delegate these tasks to the child pullparasers in effect this is one huge
+ * state machine that has only a few states and delegates things down to the
+ * child parsers whenever possible <p/>
+ *
+ * @version $Rev$ $Date$
+ */
+public class XMLFragmentStreamReaderImpl implements XMLFragmentStreamReader {
+
+ private static final int DELEGATED_STATE = 2;
+ private static final int END_ELEMENT_STATE = 1;
+ // states for this pullparser - it can only have four states
+ private static final int START_ELEMENT_STATE = 0;
+ private static final int TEXT_STATE = 3;
+
+ protected NamedProperty[] attributes;
+
+ // reference to the child reader
+ protected XMLFragmentStreamReader childReader;
+ // current property index
+ // initialized at zero
+ protected int index;
+ protected Map<String, String> declaredNamespaceMap = new HashMap<String, String>();
+ protected QName elementQName;
+
+ // we always create a new namespace context
+ protected DelegatingNamespaceContext namespaceContext = new DelegatingNamespaceContext();
+
+ protected NamedProperty[] elements;
+
+ // integer field that keeps the state of this
+ // parser.
+ protected int state = START_ELEMENT_STATE;
+
+ /*
+ * 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!
+ */
+ public XMLFragmentStreamReaderImpl(QName elementQName, NamedProperty[] elements, NamedProperty[] attributes) {
+ // validate the lengths, since both the arrays are supposed
+ // to have
+ this.elements = elements == null ? new NamedProperty[0] : elements;
+ this.elementQName = elementQName;
+ this.attributes = attributes == null ? new NamedProperty[0] : attributes;
+ }
+
+ protected XMLFragmentStreamReaderImpl(QName elementQName) {
+ this.elementQName = elementQName;
+ }
+
+ /**
+ * add the namespace context
+ */
+
+ public void setParentNamespaceContext(NamespaceContext nsContext) {
+ // register the namespace context passed in to this
+ this.namespaceContext.setParentNsContext(nsContext);
+
+ }
+
+ protected NamedProperty[] getElements() {
+ return elements;
+ }
+
+ protected NamedProperty[] getAttributes() {
+ return attributes;
+ }
+
+ protected QName[] getNamespaces() {
+ return new QName[0];
+ }
+
+ /**
+ * @param prefix
+ * @param uri
+ */
+ protected void addToNsMap(String prefix, String uri) {
+ if (!uri.equals(namespaceContext.getNamespaceURI(prefix))) {
+ namespaceContext.pushNamespace(prefix, uri);
+ declaredNamespaceMap.put(prefix, uri);
+ }
+ }
+
+ public void close() throws XMLStreamException {
+ // do nothing here - we have no resources to free
+ }
+
+ public int getAttributeCount() {
+ return (state == DELEGATED_STATE) ? childReader.getAttributeCount() : (state == START_ELEMENT_STATE
+ ? getAttributes().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
+ */
+ public QName getAttributeName(int i) {
+ if (state == DELEGATED_STATE) {
+ return childReader.getAttributeName(i);
+ } else if (state == START_ELEMENT_STATE) {
+ if ((i >= (getAttributes().length)) || i < 0) { // out of range
+ return null;
+ } else {
+ // get the attribute pointer
+ QName attribPointer = getAttributes()[i].getKey();
+ // case one - attrib name is null
+ // this should be the pointer to the OMAttribute then
+ if (attribPointer == null) {
+ throw new UnsupportedOperationException();
+ } else if (attribPointer instanceof QName) {
+ return 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 ((i >= (getAttributes().length)) || i < 0) { // out of range
+ return null;
+ } else {
+ // get the attribute pointer
+ QName attribPointer = getAttributes()[i].getKey();
+ Object omAttribObj = getAttributes()[i].getValue();
+ // case one - attrib name is null
+ // this should be the pointer to the OMAttribute then
+ if (attribPointer == null) {
+ throw new UnsupportedOperationException();
+ } 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
+ *
+ * @throws XMLStreamException
+ */
+ public String getElementText() throws XMLStreamException {
+ if (state == DELEGATED_STATE) {
+ return childReader.getElementText();
+ } else {
+ return null;
+ }
+
+ }
+
+ // /////////////////////////////////////////////////////////////////////////
+ // / attribute handling
+ // /////////////////////////////////////////////////////////////////////////
+
+ 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;
+ }
+ }
+
+ public int getEventType() {
+ if (state == START_ELEMENT_STATE) {
+ return START_ELEMENT;
+ } else if (state == END_ELEMENT_STATE) {
+ return END_ELEMENT;
+ } else if (state == TEXT_STATE) {
+ return CHARACTERS;
+ } 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();
+ }
+ }
+
+ /**
+ */
+ 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
+ */
+ 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();
+ }
+ }
+
+ // /////////////////////////////////////////////////////////////////////////
+ // //////////// end of attribute handling
+ // /////////////////////////////////////////////////////////////////////////
+
+ // //////////////////////////////////////////////////////////////////////////
+ // //////////// namespace handling
+ // //////////////////////////////////////////////////////////////////////////
+
+ 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();
+ }
+
+ }
+
+ 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 {
+ String prefix = elementQName.getPrefix();
+ return "".equals(prefix) ? null : prefix;
+ }
+ }
+
+ // /////////////////////////////////////////////////////////////////////////
+ // /////// end of namespace handling
+ // /////////////////////////////////////////////////////////////////////////
+
+ /**
+ * @param key
+ * @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;
+ }
+
+ }
+
+ public String getText() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getText();
+ } else if (state == TEXT_STATE) {
+ return (String)getElements()[index - 1].getValue();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public char[] getTextCharacters() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getTextCharacters();
+ } else if (state == TEXT_STATE) {
+ return getElements()[index - 1].getValue() == null ? new char[0] : ((String)getElements()[index - 1]
+ .getValue()).toCharArray();
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ private int copy(int sourceStart, char[] target, int targetStart, int length) {
+ char[] source = getTextCharacters();
+ if (sourceStart > source.length) {
+ throw new IndexOutOfBoundsException("source start > source length");
+ }
+ int sourceLen = source.length - sourceStart;
+ if (length > sourceLen) {
+ length = sourceLen;
+ }
+ System.arraycopy(source, sourceStart, target, targetStart, length);
+ return sourceLen;
+ }
+
+ 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) {
+ return copy(i, chars, i1, i2);
+ } else {
+ throw new IllegalStateException();
+ }
+ }
+
+ public int getTextLength() {
+ if (state == DELEGATED_STATE) {
+ return childReader.getTextLength();
+ } else if (state == TEXT_STATE) {
+ return getTextCharacters().length;
+ } 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;
+ }
+ }
+
+ /**
+ * @throws XMLStreamException
+ */
+ public boolean hasNext() throws XMLStreamException {
+ if (state == DELEGATED_STATE) {
+ if (childReader.isDone()) {
+ // 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
+ */
+ 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 separately
+ * 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();
+ }
+
+ /**
+ * are we done ?
+ */
+ public boolean isDone() {
+ return state == END_ELEMENT_STATE;
+ }
+
+ public boolean isEndElement() {
+ if (state == START_ELEMENT_STATE) {
+ return false;
+ } else if (state == END_ELEMENT_STATE) {
+ return true;
+ }
+ return childReader.isEndElement();
+ }
+
+ 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 HashTable and take that into an array
+ */
+ private String[] makePrefixArray() {
+ String[] prefixes = declaredNamespaceMap.keySet().toArray(new String[declaredNamespaceMap.size()]);
+ Arrays.sort(prefixes);
+ return prefixes;
+ }
+
+ /**
+ * By far this should be the most important method in this class this method
+ * changes the state of the parser
+ */
+ public int next() 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 (getElements() == null || getElements().length == 0) {
+ // no properties - move to the end element state
+ // straight away
+ 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.isDone()) {
+ // we've reached the end!
+ if (index > (getElements().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 (index > (getElements().length - 1)) {
+ state = END_ELEMENT_STATE;
+ returnEvent = END_ELEMENT;
+ } else {
+ returnEvent = processProperties();
+ }
+ break;
+ }
+ return returnEvent;
+ }
+
+ // /////////////////////////////////////////////////////////////////////////
+ // / Other utility methods
+ // ////////////////////////////////////////////////////////////////////////
+
+ /**
+ * TODO implement this
+ *
+ * @throws XMLStreamException
+ */
+ public int nextTag() throws XMLStreamException {
+ return 0;
+ }
+
+ /**
+ * Populates a namespace context
+ */
+ private void populateNamespaceContext() {
+
+ // first add the current element namespace to the namespace context
+ // declare it if not found
+ addToNsMap(elementQName.getPrefix(), elementQName.getNamespaceURI());
+
+ for (QName n : getNamespaces()) {
+ addToNsMap(n.getPrefix(), n.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
+
+ for (int i = 0; i < getAttributes().length; i++) { // jump in two
+ QName attrQName = getAttributes()[i].getKey();
+ if (!"".equals(attrQName.getNamespaceURI())) {
+ addToNsMap(attrQName.getPrefix(), attrQName.getNamespaceURI());
+ }
+ }
+ }
+
+ /**
+ * 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
+ QName propertyQName = getElements()[index].getKey();
+ boolean textFound = false;
+ if (propertyQName == null) {
+ throw new XMLStreamException("property key cannot be null!");
+ } else if (ELEMENT_TEXT.equals(propertyQName.getLocalPart())) {
+ // propPointer being a String has a special case
+ // that is it can be a the special constant ELEMENT_TEXT that
+ // says this text event
+ textFound = true;
+ }
+
+ // OK! we got the key. Now look at the value
+ Object propertyValue = getElements()[index].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;
+ ++index;
+ return CHARACTERS;
+ } else if (propertyValue == null) {
+ // if the value is null we delegate the work to a nullable
+ // parser
+ childReader = new NilElementStreamReader(propertyQName);
+ childReader.setParentNamespaceContext(this.namespaceContext);
+ childReader.init();
+ } else if (propertyValue instanceof String) {
+ // strings are handled by the NameValuePairStreamReader
+ childReader = new NameValuePairStreamReader(propertyQName, (String)propertyValue);
+ childReader.setParentNamespaceContext(this.namespaceContext);
+ childReader.init();
+ } else if (propertyValue instanceof String[]) {
+ // string[] are handled by the NameValueArrayStreamReader
+ // if the array is empty - skip it
+ if (((String[])propertyValue).length == 0) {
+ // advance the index
+ ++index;
+ return processProperties();
+ } else {
+ childReader = new NameValueArrayStreamReader(propertyQName, (String[])propertyValue);
+ childReader.setParentNamespaceContext(this.namespaceContext);
+ childReader.init();
+ }
+
+ } else if (propertyValue instanceof XMLStreamable) {
+ // ADBbean has it's own method to get a reader
+ XMLStreamReader reader = ((XMLStreamable)propertyValue).getXMLStreamReader(propertyQName);
+ // we know for sure that this is an ADB XMLStreamreader.
+ // However we need to make sure that it is compatible
+ if (reader instanceof XMLFragmentStreamReader) {
+ childReader = (XMLFragmentStreamReader)reader;
+ childReader.setParentNamespaceContext(this.namespaceContext);
+ childReader.init();
+ } else {
+ // wrap it to make compatible
+ childReader = new WrappingXMLStreamReader(reader);
+ }
+ } else if (propertyValue instanceof XMLStreamReader) {
+ XMLStreamReader reader = (XMLStreamReader)propertyValue;
+ if (reader instanceof XMLFragmentStreamReader) {
+ childReader = (XMLFragmentStreamReader)reader;
+ childReader.setParentNamespaceContext(this.namespaceContext);
+ childReader.init();
+ } else {
+ // wrap it to make compatible
+ childReader = new WrappingXMLStreamReader(reader);
+ }
+
+ } else {
+ // all special possibilities has been tried! Let's treat
+ // the thing as a bean and try generating events from it
+ childReader = new WrappingXMLStreamReader(new BeanXMLStreamReaderImpl(propertyQName, propertyValue));
+ // we cannot register the namespace context here
+ }
+
+ // set the state here
+ state = DELEGATED_STATE;
+ // we are done with the delegation
+ // increment the property index
+ ++index;
+ return childReader.getEventType();
+ }
+
+ public void require(int i, String string, String string1) throws XMLStreamException {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean standaloneSet() {
+ return true;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLGroupDataBinding.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLGroupDataBinding.java
new file mode 100644
index 0000000000..f7c895db1e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLGroupDataBinding.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.databinding.impl.GroupDataBinding;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.InputSource;
+
+/**
+ * A Group DataBinding
+ *
+ * @version $Rev$ $Date$
+ */
+public class XMLGroupDataBinding extends GroupDataBinding {
+
+ public XMLGroupDataBinding() {
+ super(new Class[] {InputStream.class, OutputStream.class, Reader.class, Writer.class,
+ // Source.class, Result.class,
+ InputSource.class, ContentHandler.class, XMLStreamReader.class,
+ XMLStreamWriter.class, XMLEventReader.class, XMLEventWriter.class});
+ }
+
+ @Override
+ protected Object getLogical(Class<?> markerType, Operation operation) {
+ return XMLType.UNKNOWN;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamReader2Node.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamReader2Node.java
new file mode 100644
index 0000000000..e2d0416aec
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamReader2Node.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.databinding.DataPipe;
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.apache.tuscany.sca.databinding.impl.DOMHelper;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.xml.sax.ContentHandler;
+
+/**
+ * Transform DOM Node to XML XMLStreamReader
+ *
+ * @version $Rev$ $Date$
+ */
+public class XMLStreamReader2Node extends BaseTransformer<XMLStreamReader, Node> implements
+ PullTransformer<XMLStreamReader, Node> {
+
+ private XMLStreamReader2SAX stax2sax = new XMLStreamReader2SAX();
+
+ public Node transform(XMLStreamReader source, TransformationContext context) {
+ try {
+ DataPipe<ContentHandler, Node> pipe = new SAX2DOMPipe().newInstance();
+ stax2sax.transform(source, pipe.getSink(), context);
+ Node node = pipe.getResult();
+ source.close();
+ if (node instanceof Document) {
+ Document doc = (Document)node;
+ return DOMHelper.adjustElementName(context, doc.getDocumentElement());
+ } else {
+ return node;
+ }
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ @Override
+ protected Class<XMLStreamReader> getSourceType() {
+ return XMLStreamReader.class;
+ }
+
+ @Override
+ protected Class<Node> getTargetType() {
+ return Node.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamReader2SAX.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamReader2SAX.java
new file mode 100644
index 0000000000..9b39f039b1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamReader2SAX.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.databinding.PushTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.xml.sax.ContentHandler;
+
+/**
+ * XMLStreamReader to SAX events
+ *
+ * @version $Rev$ $Date$
+ */
+public class XMLStreamReader2SAX extends BaseTransformer<XMLStreamReader, ContentHandler> implements
+ PushTransformer<XMLStreamReader, ContentHandler> {
+
+ @Override
+ protected Class<ContentHandler> getTargetType() {
+ return ContentHandler.class;
+ }
+
+ @Override
+ protected Class<XMLStreamReader> getSourceType() {
+ return XMLStreamReader.class;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.PushTransformer#getWeight()
+ */
+ @Override
+ public int getWeight() {
+ return 20;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.PushTransformer#transform(java.lang.Object,
+ * java.lang.Object,
+ * org.apache.tuscany.sca.databinding.TransformationContext)
+ */
+ public void transform(XMLStreamReader source, ContentHandler sink, TransformationContext context) {
+ StAX2SAXAdapter adapter = new StAX2SAXAdapter(false);
+ try {
+ adapter.parse(source, sink);
+ source.close();
+ } catch (Exception e) {
+ throw new TransformationException(e);
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamReader2String.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamReader2String.java
new file mode 100644
index 0000000000..6db731bc9f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamReader2String.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.databinding.PullTransformer;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformationException;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+
+public class XMLStreamReader2String extends BaseTransformer<XMLStreamReader, String> implements
+ PullTransformer<XMLStreamReader, String> {
+
+ public String transform(XMLStreamReader source, TransformationContext context) {
+ try {
+ String str = StAXHelper.save(source);
+ source.close();
+ return str;
+ } catch (XMLStreamException e) {
+ throw new TransformationException(e);
+ }
+ }
+
+ @Override
+ protected Class<XMLStreamReader> getSourceType() {
+ return XMLStreamReader.class;
+ }
+
+ @Override
+ protected Class<String> getTargetType() {
+ return String.class;
+ }
+
+ @Override
+ public int getWeight() {
+ return 40;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamSerializer.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamSerializer.java
new file mode 100644
index 0000000000..920ebb511c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamSerializer.java
@@ -0,0 +1,287 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.xml;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+/**
+ * The XMLStreamSerializer pulls events from the XMLStreamReader and dumps into the XMLStreamWriter
+ *
+ * @version $Rev$ $Date$
+ */
+public class XMLStreamSerializer implements XMLStreamConstants {
+ public static final String NAMESPACE_PREFIX = "ns";
+ private static int namespaceSuffix;
+
+ /*
+ * The behavior of the Serializer is such that it returns when it encounters the starting element for the second
+ * time. The depth variable tracks the depth of the Serializer 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.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 declaring the new
+ // prefix
+ // as a namespace declaration
+ } else if (prefix != null && !"".equals(prefix) && !prefix.equals(writerPrefix)) {
+ writer.writeNamespace(prefix, namespaceName);
+ writer.writeAttribute(prefix, namespaceName, reader.getAttributeLocalName(i), reader
+ .getAttributeValue(i));
+
+ // prefix is null (or empty), but the namespace name is
+ // valid! it has not
+ // being written previously also. So we need to generate
+ // a prefix
+ // here
+ } else if (prefix == null || prefix.equals("")) {
+ prefix = generateUniquePrefix(writer.getNamespaceContext());
+ writer.writeNamespace(prefix, namespaceName);
+ writer.writeAttribute(prefix, namespaceName, reader.getAttributeLocalName(i), reader
+ .getAttributeValue(i));
+ } else {
+ writer.writeAttribute(prefix, namespaceName, reader.getAttributeLocalName(i), reader
+ .getAttributeValue(i));
+ }
+ } else {
+ // empty namespace is equal to no namespace!
+ writer.writeAttribute(reader.getAttributeLocalName(i), reader.getAttributeValue(i));
+ }
+
+ }
+ }
+
+ /**
+ * Method serializeCData.
+ *
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeCData(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
+ writer.writeCData(reader.getText());
+ }
+
+ /**
+ * Method serializeComment.
+ *
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeComment(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
+ writer.writeComment(reader.getText());
+ }
+
+ /**
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeElement(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
+ String prefix = reader.getPrefix();
+ String nameSpaceName = reader.getNamespaceURI();
+ if (nameSpaceName != null) {
+ String writerPrefix = writer.getPrefix(nameSpaceName);
+ if (writerPrefix != null) {
+ writer.writeStartElement(nameSpaceName, reader.getLocalName());
+ } else {
+ if (prefix != null) {
+ writer.writeStartElement(prefix, reader.getLocalName(), nameSpaceName);
+ writer.writeNamespace(prefix, nameSpaceName);
+ // writer.setPrefix(prefix, nameSpaceName);
+ } else {
+ // [rfeng] We need to set default NS 1st before calling writeStateElement
+ writer.setDefaultNamespace(nameSpaceName);
+ writer.writeStartElement(nameSpaceName, reader.getLocalName());
+ writer.writeDefaultNamespace(nameSpaceName);
+ }
+ }
+ } else {
+ writer.writeStartElement(reader.getLocalName());
+ }
+
+ // add the namespaces
+ int count = reader.getNamespaceCount();
+ String namespacePrefix;
+ for (int i = 0; i < count; i++) {
+ namespacePrefix = reader.getNamespacePrefix(i);
+ // [rfeng] The following is commented out to allow to default ns
+ // if (namespacePrefix != null && namespacePrefix.length() == 0) {
+ // continue;
+ // }
+
+ serializeNamespace(namespacePrefix, reader.getNamespaceURI(i), writer);
+ }
+
+ // add attributes
+ serializeAttributes(reader, writer);
+
+ }
+
+ /**
+ * Method serializeEndElement.
+ *
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeEndElement(XMLStreamWriter writer) throws XMLStreamException {
+ writer.writeEndElement();
+ }
+
+ /**
+ * Method serializeNamespace.
+ *
+ * @param prefix
+ * @param uri
+ * @param writer
+ * @throws XMLStreamException
+ */
+ private void serializeNamespace(String prefix, String uri, XMLStreamWriter writer) throws XMLStreamException {
+ String prefix1 = writer.getPrefix(uri);
+ if (prefix1 == null) {
+ writer.writeNamespace(prefix, uri);
+ // writer.setPrefix(prefix, uri);
+ }
+ }
+
+ /**
+ * Method serializeNode.
+ *
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeNode(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
+ while (true) {
+ int event = reader.getEventType();
+ if (event == START_ELEMENT) {
+ serializeElement(reader, writer);
+ depth++;
+ } else if (event == ATTRIBUTE) {
+ serializeAttributes(reader, writer);
+ } else if (event == CHARACTERS) {
+ serializeText(reader, writer);
+ } else if (event == COMMENT) {
+ serializeComment(reader, writer);
+ } else if (event == CDATA) {
+ serializeCData(reader, writer);
+ } else if (event == END_ELEMENT) {
+ serializeEndElement(writer);
+ depth--;
+ } else if (event == START_DOCUMENT) {
+ depth++; // if a start document is found then increment
+ writer.writeStartDocument();
+ // the depth
+ } else if (event == END_DOCUMENT) {
+ if (depth != 0) {
+ depth--; // for the end document - reduce the depth
+ }
+ writer.writeEndDocument();
+ }
+ if (depth == 0) {
+ break;
+ }
+ if (reader.hasNext()) {
+ reader.next();
+ } else {
+ break;
+ }
+ }
+ }
+
+ /**
+ * @param reader
+ * @param writer
+ * @throws XMLStreamException
+ */
+ protected void serializeText(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
+ writer.writeCharacters(reader.getText());
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamable.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamable.java
new file mode 100644
index 0000000000..f32f93d098
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStreamable.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ * An interface represents data that can be read using StAX streaming
+ *
+ * @version $Rev$ $Date$
+ */
+public interface XMLStreamable {
+ /**
+ * Get the XMLStreamReader for StAX processing
+ *
+ * @param rootElementName the name of the element to be generated
+ * @return Returns a pull parser.
+ */
+ XMLStreamReader getXMLStreamReader(QName rootElementName);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStringDataBinding.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStringDataBinding.java
new file mode 100644
index 0000000000..36cf5e9c9b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XMLStringDataBinding.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.xml;
+
+
+import org.apache.tuscany.sca.databinding.impl.BaseDataBinding;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+
+/**
+ * A DataBinding for the XML string
+ *
+ * @version $Rev$ $Date$
+ */
+public class XMLStringDataBinding extends BaseDataBinding {
+ public static final String NAME = String.class.getName();
+ public static final String[] ALIASES = new String[] {"xml.string"};
+
+ public XMLStringDataBinding() {
+ super(NAME, ALIASES, String.class);
+ }
+
+ @Override
+ public boolean introspect(DataType type, Operation operation) {
+ if (type.getPhysical() == String.class && NAME.equals(type.getDataBinding()) || ALIASES[0].equals(type.getDataBinding())) {
+ type.setDataBinding(NAME);
+ type.setLogical(XMLType.UNKNOWN);
+ return true;
+ } else {
+ return false;
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlNode.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlNode.java
new file mode 100644
index 0000000000..86ebd627f7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlNode.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface XmlNode {
+ enum Type {ELEMENT, ATTRIBUTE, CHARACTERS, READER};
+ /**
+ * Returns the children of the receiver as an <code>Iterator</code>.
+ */
+ Iterator<XmlNode> children();
+
+ /**
+ * Returns the attributes of the element as an <code>List</code>. Namespace declarations
+ * should be excluded.
+ *
+ * @return
+ */
+ List<XmlNode> attributes();
+
+ /**
+ * Returns a map of prefix to namespace URI
+ * @return
+ */
+ Map<String, String> namespaces();
+
+ /**
+ * Return the QName of the element. If it's for a text node, the name is null.
+ * @return
+ */
+ QName getName();
+
+ /**
+ * Return the text value of the leaf element
+ * @return
+ */
+ <T> T getValue();
+
+ /**
+ * Return the type of the XML node
+ * @return
+ */
+ Type getType();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlNodeIterator.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlNodeIterator.java
new file mode 100644
index 0000000000..3dd125463e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlNodeIterator.java
@@ -0,0 +1,355 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.util.ArrayList;
+import java.util.EmptyStackException;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.NamespaceContext;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class XmlNodeIterator implements Iterator<XmlNode> {
+ public static final int START = 0;
+ public static final int END = 1;
+
+ protected FastStack<ElementHolder> stack;
+ protected int state;
+ protected NamespaceContextImpl nsContext;
+
+ public XmlNodeIterator(XmlNode rootNode) {
+ super();
+ List<XmlNode> v = new ArrayList<XmlNode>(1);
+ v.add(rootNode);
+ stack = new FastStack<ElementHolder>();
+ Iterator<XmlNode> i = v.iterator();
+ stack.push(new ElementHolder(null, i));
+ this.state = START;
+ this.nsContext = new NamespaceContextImpl(null);
+ }
+
+ public boolean hasNext() {
+ return !(stack.empty() || (state == END && stack.peek().parent == null));
+ }
+
+ public XmlNode next() {
+ this.state = START;
+ ElementHolder element = stack.peek();
+ Iterator<XmlNode> it = element.children;
+ if (it == null || (!it.hasNext())) {
+ // End of the children, return END event of parent
+ stack.pop();
+ this.state = END;
+ this.nsContext = (NamespaceContextImpl)nsContext.getParent();
+ return element.parent;
+ }
+ XmlNode node = it.next();
+ stack.push(new ElementHolder(node, node.children()));
+ this.nsContext = new NamespaceContextImpl(this.nsContext);
+ populateNamespaces(node);
+ return node;
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ public int getState() {
+ return state;
+ }
+
+ public NamespaceContext getNamespaceContext() {
+ return nsContext;
+ }
+
+ private void populateNamespaces(XmlNode element) {
+ if (element.getName() != null) {
+ if (element.namespaces() != null) {
+ for (Map.Entry<String, String> e : element.namespaces().entrySet()) {
+ nsContext.register(e.getKey(), e.getValue());
+ }
+ }
+ }
+ }
+
+ private static class ElementHolder {
+ private XmlNode parent;
+ private Iterator<XmlNode> children;
+
+ public ElementHolder(XmlNode parent, Iterator<XmlNode> children) {
+ this.parent = parent;
+ this.children = children;
+ }
+ }
+
+ private static class NamespaceContextImpl implements NamespaceContext {
+ private NamespaceContext parent;
+ private Map<String, String> map = new HashMap<String, String>();
+
+ /**
+ * @param parent
+ */
+ public NamespaceContextImpl(NamespaceContext parent) {
+ super();
+ this.parent = parent;
+ if (parent == null) {
+ map.put("xml", "http://www.w3.org/XML/1998/namespace");
+ map.put("xmlns", "http://www.w3.org/2000/xmlns/");
+ }
+ }
+
+ public String getNamespaceURI(String prefix) {
+ if (prefix == null) {
+ throw new IllegalArgumentException("Prefix is null");
+ }
+
+ String ns = (String)map.get(prefix);
+ if (ns != null) {
+ return ns;
+ }
+ if (parent != null) {
+ return parent.getNamespaceURI(prefix);
+ }
+ return null;
+ }
+
+ public String getPrefix(String nsURI) {
+ if (nsURI == null)
+ throw new IllegalArgumentException("Namespace is null");
+ for (Iterator<Map.Entry<String, String>> i = map.entrySet().iterator(); i.hasNext();) {
+ Map.Entry<String, String> entry = i.next();
+ if (entry.getValue().equals(nsURI)) {
+ return entry.getKey();
+ }
+ }
+ if (parent != null) {
+ return parent.getPrefix(nsURI);
+ }
+ return null;
+ }
+
+ public Iterator getPrefixes(String nsURI) {
+ List<String> prefixList = new ArrayList<String>();
+ for (Iterator<Map.Entry<String, String>> i = map.entrySet().iterator(); i.hasNext();) {
+ Map.Entry<String, String> entry = i.next();
+ if (entry.getValue().equals(nsURI)) {
+ prefixList.add(entry.getKey());
+ }
+ }
+ final Iterator currentIterator = prefixList.iterator();
+ final Iterator parentIterator = parent != null ? null : parent.getPrefixes(nsURI);
+ return new Iterator() {
+
+ public boolean hasNext() {
+ return currentIterator.hasNext() || (parentIterator != null && parentIterator.hasNext());
+ }
+
+ public Object next() {
+ if (!hasNext()) {
+ throw new IllegalStateException("End of iterator has reached");
+ }
+ return currentIterator.hasNext() ? currentIterator.next() : parentIterator.next();
+ }
+
+ public void remove() {
+ throw new UnsupportedOperationException();
+ }
+
+ };
+
+ }
+
+ public void register(String prefix, String ns) {
+ map.put(prefix, ns);
+ }
+
+ public NamespaceContext getParent() {
+ return parent;
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer sb = new StringBuffer(map.toString());
+ if (parent != null) {
+ sb.append("\nParent: ");
+ sb.append(parent);
+ }
+ return sb.toString();
+ }
+ }
+
+ /**
+ * An implementation of the {@link java.util.Stack} API that is based on an <code>ArrayList</code> instead of a
+ * <code>Vector</code>, so it is not synchronized to protect against multi-threaded access. The implementation is
+ * therefore operates faster in environments where you do not need to worry about multiple thread contention.
+ * <p>
+ * The removal order of an <code>ArrayStack</code> is based on insertion order: The most recently added element is
+ * removed first. The iteration order is <i>not</i> the same as the removal order. The iterator returns elements
+ * from the bottom up, whereas the {@link #remove()} method removes them from the top down.
+ * <p>
+ * Unlike <code>Stack</code>, <code>ArrayStack</code> accepts null entries.
+ */
+ public static class FastStack<T> extends ArrayList<T> {
+
+ /** Ensure Serialization compatibility */
+ private static final long serialVersionUID = 2130079159931574599L;
+
+ /**
+ * Constructs a new empty <code>ArrayStack</code>. The initial size is controlled by <code>ArrayList</code>
+ * and is currently 10.
+ */
+ public FastStack() {
+ super();
+ }
+
+ /**
+ * Constructs a new empty <code>ArrayStack</code> with an initial size.
+ *
+ * @param initialSize the initial size to use
+ * @throws IllegalArgumentException if the specified initial size is negative
+ */
+ public FastStack(int initialSize) {
+ super(initialSize);
+ }
+
+ /**
+ * Return <code>true</code> if this stack is currently empty.
+ * <p>
+ * This method exists for compatibility with <code>java.util.Stack</code>. New users of this class should use
+ * <code>isEmpty</code> instead.
+ *
+ * @return true if the stack is currently empty
+ */
+ public boolean empty() {
+ return isEmpty();
+ }
+
+ /**
+ * Returns the top item off of this stack without removing it.
+ *
+ * @return the top item on the stack
+ * @throws EmptyStackException if the stack is empty
+ */
+ public T peek() throws EmptyStackException {
+ int n = size();
+ if (n <= 0) {
+ throw new EmptyStackException();
+ } else {
+ return get(n - 1);
+ }
+ }
+
+ /**
+ * Returns the n'th item down (zero-relative) from the top of this stack without removing it.
+ *
+ * @param n the number of items down to go
+ * @return the n'th item on the stack, zero relative
+ * @throws EmptyStackException if there are not enough items on the stack to satisfy this request
+ */
+ public T peek(int n) throws EmptyStackException {
+ int m = (size() - n) - 1;
+ if (m < 0) {
+ throw new EmptyStackException();
+ } else {
+ return get(m);
+ }
+ }
+
+ /**
+ * Pops the top item off of this stack and return it.
+ *
+ * @return the top item on the stack
+ * @throws EmptyStackException if the stack is empty
+ */
+ public T pop() throws EmptyStackException {
+ int n = size();
+ if (n <= 0) {
+ throw new EmptyStackException();
+ } else {
+ return remove(n - 1);
+ }
+ }
+
+ /**
+ * Pushes a new item onto the top of this stack. The pushed item is also returned. This is equivalent to calling
+ * <code>add</code>.
+ *
+ * @param item the item to be added
+ * @return the item just pushed
+ */
+ public Object push(T item) {
+ add(item);
+ return item;
+ }
+
+ /**
+ * Returns the top-most index for the object in the stack
+ *
+ * @param object the object to be searched for
+ * @return top-most index, or -1 if not found
+ */
+ public int search(T object) {
+ int i = size() - 1; // Current index
+ while (i >= 0) {
+ T current = get(i);
+ if ((object == null && current == null) || (object != null && object.equals(current))) {
+ return i;
+ }
+ i--;
+ }
+ return -1;
+ }
+
+ /**
+ * Returns the element on the top of the stack.
+ *
+ * @return the element on the top of the stack
+ * @throws EmptyStackException if the stack is empty
+ */
+ public T get() {
+ int size = size();
+ if (size == 0) {
+ throw new EmptyStackException();
+ }
+ return get(size - 1);
+ }
+
+ /**
+ * Removes the element on the top of the stack.
+ *
+ * @return the removed element
+ * @throws EmptyStackException if the stack is empty
+ */
+ public T remove() {
+ int size = size();
+ if (size == 0) {
+ throw new EmptyStackException();
+ }
+ return remove(size - 1);
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderImpl.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderImpl.java
new file mode 100644
index 0000000000..f4bc357c7d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderImpl.java
@@ -0,0 +1,531 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class XmlTreeStreamReaderImpl implements XMLStreamReader {
+
+ protected int state;
+ protected XmlNodeIterator iterator;
+ protected XmlNode current;
+
+ protected XMLStreamReader reader;
+
+ /*
+ * 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!
+ */
+ public XmlTreeStreamReaderImpl(XmlNode root) {
+ this.iterator = new XmlNodeIterator(root);
+ this.current = null;
+ this.state = START_DOCUMENT;
+ this.reader = null;
+ }
+
+ public void close() throws XMLStreamException {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+
+ private void checkElementState() {
+ if (getEventType() != START_ELEMENT && getEventType() != END_ELEMENT) {
+ throw new IllegalStateException();
+ }
+ }
+
+ private List<XmlNode> getAttributes() {
+ if (current != null && current.attributes() != null) {
+ return current.attributes();
+ } else {
+ return Collections.emptyList();
+ }
+ }
+
+ public int getAttributeCount() {
+ checkElementState();
+ if (reader != null) {
+ return reader.getAttributeCount();
+ }
+ return getAttributes().size();
+ }
+
+ public String getAttributeLocalName(int i) {
+ checkElementState();
+ if (reader != null) {
+ return reader.getAttributeLocalName(i);
+ }
+ return getAttributes().get(i).getName().getLocalPart();
+ }
+
+ /**
+ * @param i
+ */
+ public QName getAttributeName(int i) {
+ checkElementState();
+ if (reader != null) {
+ return reader.getAttributeName(i);
+ }
+ return getAttributes().get(i).getName();
+ }
+
+ public String getAttributeNamespace(int i) {
+ checkElementState();
+ if (reader != null) {
+ return reader.getAttributeNamespace(i);
+ }
+ return getAttributes().get(i).getName().getNamespaceURI();
+ }
+
+ public String getAttributePrefix(int i) {
+ checkElementState();
+ if (reader != null) {
+ return reader.getAttributePrefix(i);
+ }
+ return getAttributes().get(i).getName().getPrefix();
+ }
+
+ public String getAttributeType(int i) {
+ if (reader != null) {
+ return reader.getAttributeType(i);
+ }
+ return null; // not supported
+ }
+
+ public String getAttributeValue(int i) {
+ checkElementState();
+ if (reader != null) {
+ return reader.getAttributeValue(i);
+ }
+ return getAttributes().get(i).getValue();
+ }
+
+ public String getAttributeValue(String nsUri, String localName) {
+ checkElementState();
+ if (reader != null) {
+ return reader.getAttributeValue(nsUri, localName);
+ }
+ int count = getAttributeCount();
+ String value = null;
+ QName attrQName;
+ for (int i = 0; i < count; i++) {
+ attrQName = getAttributeName(i);
+ if (nsUri == null) {
+ if (localName.equals(attrQName.getLocalPart())) {
+ value = getAttributeValue(i);
+ break;
+ }
+ } else {
+ if (localName.equals(attrQName.getLocalPart()) && nsUri.equals(attrQName.getNamespaceURI())) {
+ value = getAttributeValue(i);
+ break;
+ }
+ }
+
+ }
+
+ return value;
+ }
+
+ public String getCharacterEncodingScheme() {
+ if (reader != null) {
+ return reader.getCharacterEncodingScheme();
+ }
+ return "UTF-8";
+ }
+
+ public String getElementText() throws XMLStreamException {
+ checkElementState();
+ if (reader != null) {
+ return reader.getElementText();
+ }
+ return current.getValue();
+ }
+
+ public String getEncoding() {
+ if (reader != null) {
+ return reader.getEncoding();
+ }
+ return "UTF-8";
+ }
+
+ public int getEventType() {
+ return state;
+ }
+
+ public String getLocalName() {
+ checkElementState();
+ if (reader != null) {
+ return reader.getLocalName();
+ }
+ return current.getName().getLocalPart();
+ }
+
+ /**
+ */
+ public Location getLocation() {
+ if (reader != null) {
+ return reader.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() {
+ checkElementState();
+ if (reader != null) {
+ return reader.getName();
+ }
+ return current.getName();
+ }
+
+ public NamespaceContext getNamespaceContext() {
+ if (reader != null) {
+ return reader.getNamespaceContext();
+ }
+ return iterator.getNamespaceContext();
+ }
+
+ private Map<String, String> getNamespaces() {
+ if (current != null && current.namespaces() != null) {
+ return current.namespaces();
+ } else {
+ return Collections.emptyMap();
+ }
+ }
+
+ public int getNamespaceCount() {
+ checkElementState();
+ if (reader != null) {
+ return reader.getNamespaceCount();
+ }
+ return getNamespaces().size();
+ }
+
+ /**
+ * @param i
+ */
+ public String getNamespacePrefix(int i) {
+ checkElementState();
+ if (reader != null) {
+ return reader.getNamespacePrefix(i);
+ }
+ return new ArrayList<Map.Entry<String, String>>(getNamespaces().entrySet()).get(i).getKey();
+ }
+
+ public String getNamespaceURI() {
+ checkElementState();
+ if (reader != null) {
+ return reader.getNamespaceURI();
+ }
+ return current.getName().getNamespaceURI();
+ }
+
+ public String getNamespaceURI(int i) {
+ checkElementState();
+ if (reader != null) {
+ return reader.getNamespaceURI(i);
+ }
+ return new ArrayList<Map.Entry<String, String>>(getNamespaces().entrySet()).get(i).getValue();
+ }
+
+ public String getNamespaceURI(String prefix) {
+ if (reader != null) {
+ return reader.getNamespaceURI(prefix);
+ }
+ return getNamespaceContext().getNamespaceURI(prefix);
+ }
+
+ public String getPIData() {
+ if (reader != null) {
+ return reader.getPIData();
+ }
+ throw new UnsupportedOperationException("Yet to be implemented !!");
+ }
+
+ public String getPITarget() {
+ if (reader != null) {
+ return reader.getPITarget();
+ }
+ throw new UnsupportedOperationException("Yet to be implemented !!");
+ }
+
+ public String getPrefix() {
+ if (reader != null) {
+ return reader.getPrefix();
+ }
+ if (state == START_ELEMENT || state == END_ELEMENT) {
+ String prefix = current.getName().getPrefix();
+ return "".equals(prefix) ? null : prefix;
+ } else if (state == START_DOCUMENT) {
+ return null;
+ } else {
+ throw new IllegalStateException("State==" + state);
+ }
+ }
+
+ /**
+ * @param key
+ * @throws IllegalArgumentException
+ */
+ public Object getProperty(String key) throws IllegalArgumentException {
+ if (reader != null) {
+ return reader.getProperty(key);
+ }
+ return null;
+ }
+
+ public String getText() {
+ if (reader != null) {
+ return reader.getText();
+ }
+ return current.getValue();
+ }
+
+ public char[] getTextCharacters() {
+ if (reader != null) {
+ return reader.getTextCharacters();
+ }
+ String value = current.getValue();
+ return value == null ? new char[0] : value.toCharArray();
+ }
+
+ private int copy(int sourceStart, char[] target, int targetStart, int length) {
+ char[] source = getTextCharacters();
+ if (sourceStart > source.length) {
+ throw new IndexOutOfBoundsException("source start > source length");
+ }
+ int sourceLen = source.length - sourceStart;
+ if (length > sourceLen) {
+ length = sourceLen;
+ }
+ System.arraycopy(source, sourceStart, target, targetStart, length);
+ return sourceLen;
+ }
+
+ public int getTextCharacters(int i, char[] chars, int i1, int i2) throws XMLStreamException {
+ if (reader != null) {
+ return reader.getTextCharacters(i, chars, i1, i2);
+ }
+ return copy(i, chars, i1, i2);
+ }
+
+ public int getTextLength() {
+ if (reader != null) {
+ return reader.getTextLength();
+ }
+ return getTextCharacters().length;
+ }
+
+ public int getTextStart() {
+ if (reader != null) {
+ return reader.getTextStart();
+ }
+ return 0;
+ }
+
+ public String getVersion() {
+ return "1.0";
+ }
+
+ public boolean hasName() {
+ if (reader != null) {
+ return reader.hasName();
+ }
+ return current.getName() != null;
+ }
+
+ /**
+ * @throws XMLStreamException
+ */
+ public boolean hasNext() throws XMLStreamException {
+ return iterator.hasNext() || state != END_DOCUMENT || (reader != null && reader.hasNext());
+ }
+
+ public boolean hasText() {
+ if (reader != null) {
+ return reader.hasText();
+ }
+ return current.getType() == XmlNode.Type.CHARACTERS;
+ }
+
+ public boolean isAttributeSpecified(int i) {
+ if (reader != null) {
+ return reader.isAttributeSpecified(i);
+ }
+ return false; // not supported
+ }
+
+ public boolean isCharacters() {
+ if (reader != null) {
+ return reader.isCharacters();
+ }
+ return current.getType() == XmlNode.Type.CHARACTERS;
+ }
+
+ public boolean isEndElement() {
+ if (reader != null) {
+ return reader.isEndElement();
+ }
+ return getEventType() == END_ELEMENT;
+ }
+
+ public boolean isStandalone() {
+ return true;
+ }
+
+ public boolean isStartElement() {
+ if (reader != null) {
+ return reader.isStartElement();
+ }
+ return getEventType() == START_ELEMENT;
+ }
+
+ public boolean isWhiteSpace() {
+ if (reader != null) {
+ return reader.isWhiteSpace();
+ }
+ return false;
+ }
+
+ /**
+ * By far this should be the most important method in this class this method
+ * changes the state of the parser
+ */
+ public int next() throws XMLStreamException {
+ if (!hasNext()) {
+ throw new IllegalStateException("No more events");
+ }
+ if (reader != null) {
+ if (!reader.hasNext()) {
+ this.reader = null;
+ } else {
+ // Go to the delegation mode
+ state = reader.next();
+ return state;
+ }
+ }
+ if (!iterator.hasNext()) {
+ state = END_DOCUMENT;
+ current = null;
+ return state;
+ }
+ current = iterator.next();
+ XmlNode.Type type = current.getType();
+
+ int itState = iterator.getState();
+ if (itState == XmlNodeIterator.END) {
+ if (type == XmlNode.Type.ELEMENT) {
+ state = END_ELEMENT;
+ } else {
+ // Ignore the pop
+ state = next();
+ }
+ }
+ if (itState == XmlNodeIterator.START) {
+ if (type == XmlNode.Type.ELEMENT) {
+ state = START_ELEMENT;
+ } else if (type == XmlNode.Type.CHARACTERS) {
+ state = CHARACTERS;
+ } else if (type == XmlNode.Type.READER) {
+ XMLStreamReader value = current.getValue();
+ this.reader = new WrappingXMLStreamReader(value);
+ state = reader.getEventType();
+ return state;
+ }
+ }
+ return state;
+ }
+
+ /**
+ * TODO implement this
+ *
+ * @throws XMLStreamException
+ */
+ public int nextTag() throws XMLStreamException {
+ while (true) {
+ int event = next();
+ if (event == START_ELEMENT || event == END_ELEMENT) {
+ return event;
+ }
+ }
+ }
+
+ public void require(int i, String ns, String localPart) throws XMLStreamException {
+ if (reader != null) {
+ reader.require(i, ns, localPart);
+ return;
+ }
+ int event = getEventType();
+ if (event != i) {
+ throw new IllegalStateException("Event type is " + event + " (!=" + i + ")");
+ }
+ QName name = getName();
+ String ns1 = name.getNamespaceURI();
+ String localName1 = name.getLocalPart();
+
+ if (ns != null && !ns.equals(ns1)) {
+ throw new IllegalStateException("Namespace URI is " + ns1 + " (!=" + ns + ")");
+ }
+
+ if (localPart != null && !localPart.equals(localName1)) {
+ throw new IllegalStateException("Local name is " + localName1 + " (!=" + localPart + ")");
+ }
+
+ }
+
+ public boolean standaloneSet() {
+ return true;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding
new file mode 100644
index 0000000000..10e6082b34
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBinding
@@ -0,0 +1,25 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# implementation classes for the databindings
+org.apache.tuscany.sca.databinding.xml.DOMDataBinding;type=org.w3c.dom.Node,name=dom
+org.apache.tuscany.sca.databinding.xml.XMLStringDataBinding;type=java.lang.String,name=xml.string
+org.apache.tuscany.sca.databinding.xml.XMLGroupDataBinding;type=databinding:group
+org.apache.tuscany.sca.databinding.javabeans.JavaBeansDataBinding;type=java:complexType
+org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding;type=java:simpleType
+org.apache.tuscany.sca.databinding.javabeans.JavaExceptionDataBinding;type=java:exception
+org.apache.tuscany.sca.databinding.externalizable.ExternalizableDataBinding;type=java.io.Externalizable,name=externalizable
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBindingExtensionPoint b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBindingExtensionPoint
new file mode 100644
index 0000000000..568e04f9de
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.DataBindingExtensionPoint
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.databinding.DefaultDataBindingExtensionPoint
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
new file mode 100644
index 0000000000..96115be404
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PullTransformer
@@ -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.
+
+# Implementation classes for the transformers
+org.apache.tuscany.sca.databinding.xml.InputSource2Node;source=org.xml.sax.InputSource,target=org.w3c.dom.Node,weight=80
+org.apache.tuscany.sca.databinding.xml.InputStream2Node;source=java.io.InputStream,target=org.w3c.dom.Node,weight=80
+# org.apache.tuscany.sca.databinding.javabeans.DOMNode2JavaBeanTransformer;source=org.w3c.dom.Node,target=java:complexType,weight=80000
+org.apache.tuscany.sca.databinding.xml.Node2String;source=org.w3c.dom.Node,target=java.lang.String,weight=80
+org.apache.tuscany.sca.databinding.xml.Node2XMLStreamReader;source=org.w3c.dom.Node,target=javax.xml.stream.XMLStreamReader,weight=80
+# org.apache.tuscany.sca.databinding.javabeans.JavaBean2DOMNodeTransformer;source=java:complexType,target=org.w3c.dom.Node,weight=80000
+# org.apache.tuscany.sca.databinding.javabeans.JavaBean2XMLStreamReaderTransformer;source=java:complexType,target=javax.xml.stream.XMLStreamReader,weight=79000
+org.apache.tuscany.sca.databinding.xml.Reader2Node;source=java.io.Reader,target=org.w3c.dom.Node,weight=80
+org.apache.tuscany.sca.databinding.xml.SAX2DOMPipe;source=org.xml.sax.ContentHandler,target=org.w3c.dom.Node,weight=70
+org.apache.tuscany.sca.databinding.xml.StreamDataPipe;source=java.io.OutputStream,target=java.io.InputStream,weight=90
+org.apache.tuscany.sca.databinding.xml.String2Node;source=java.lang.String,target=org.w3c.dom.Node,weight=90
+org.apache.tuscany.sca.databinding.xml.String2XMLStreamReader;source=java.lang.String,target=javax.xml.stream.XMLStreamReader,weight=90
+org.apache.tuscany.sca.databinding.xml.Writer2ReaderDataPipe;source=java.io.Writer,target=java.io.Reader,weight=90
+org.apache.tuscany.sca.databinding.xml.XMLStreamReader2Node;source=javax.xml.stream.XMLStreamReader,target=org.w3c.dom.Node,weight=80
+org.apache.tuscany.sca.databinding.xml.XMLStreamReader2String;source=javax.xml.stream.XMLStreamReader,target=java.lang.String,weight=80
+# org.apache.tuscany.sca.databinding.xml.Node2SimpleJavaType;source=org.w3c.dom.Node,target=java:simpleType,weight=80000
+# org.apache.tuscany.sca.databinding.xml.SimpleJavaType2Node;source=java:simpleType,target=org.w3c.dom.Node,weight=80000
+org.apache.tuscany.sca.databinding.xml.Source2NodeTransformer;source=javax.xml.transform.Source,target=org.w3c.dom.Node,weight=80
+org.apache.tuscany.sca.databinding.xml.Source2StringTransformer;source=javax.xml.transform.Source,target=java.lang.String,weight=80
+
+org.apache.tuscany.sca.databinding.xml.Node2SourceTransformer;source=org.w3c.dom.Node,target=javax.xml.transform.Source,weight=80
+org.apache.tuscany.sca.databinding.xml.String2SourceTransformer;source=java.lang.String,target=javax.xml.transform.Source,weight=80
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer
new file mode 100644
index 0000000000..e02cd5c934
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.PushTransformer
@@ -0,0 +1,26 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation classes for the transformers
+org.apache.tuscany.sca.databinding.xml.InputSource2SAX;source=org.xml.sax.InputSource,target=org.xml.sax.ContentHandler,weight=80
+org.apache.tuscany.sca.databinding.xml.InputStream2SAX;source=java.io.InputStream,target=org.xml.sax.ContentHandler,weight=80
+org.apache.tuscany.sca.databinding.xml.Node2OutputStream;source=org.w3c.dom.Node,target=java.io.OutputStream,weight=80
+org.apache.tuscany.sca.databinding.xml.Node2Writer;source=org.w3c.dom.Node,target=java.io.Writer,weight=80
+org.apache.tuscany.sca.databinding.xml.Reader2SAX;source=java.io.Reader,target=org.xml.sax.ContentHandler,weight=80
+org.apache.tuscany.sca.databinding.xml.Source2ResultTransformer;source=javax.xml.transform.Source,target=javax.xml.transform.Result,weight=80
+org.apache.tuscany.sca.databinding.xml.String2SAX;source=java.lang.String,target=org.xml.sax.ContentHandler,weight=80
+org.apache.tuscany.sca.databinding.xml.XMLStreamReader2SAX;source=javax.xml.stream.XMLStreamReader,target=org.xml.sax.ContentHandler,weight=70
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.TransformerExtensionPoint b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.TransformerExtensionPoint
new file mode 100644
index 0000000000..7d8642fb1e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/main/resources/META-INF/services/org.apache.tuscany.sca.databinding.TransformerExtensionPoint
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.databinding.DefaultTransformerExtensionPoint
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DOMHelperTestCase.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DOMHelperTestCase.java
new file mode 100644
index 0000000000..8c710062ad
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DOMHelperTestCase.java
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.extension;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.databinding.impl.DOMHelper;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class DOMHelperTestCase extends TestCase {
+ private static final QName FOO_NAME = new QName("http://foo", "foo");
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ 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/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DataBindingExtensionTestCase.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DataBindingExtensionTestCase.java
new file mode 100644
index 0000000000..f9e331fbf3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/DataBindingExtensionTestCase.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.extension;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.databinding.impl.BaseDataBinding;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
+import org.easymock.EasyMock;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataBindingExtensionTestCase extends TestCase {
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testExtension() {
+ DataBinding1 binding1 = new DataBinding1(Node.class);
+ assertEquals(Node.class.getName(), binding1.getName());
+ DataType dt1 = new DataTypeImpl<Class>(Element.class, null);
+ assertTrue(binding1.introspect(dt1, null));
+ DataType dt2 = new DataTypeImpl<Class>(String.class, null);
+ assertFalse(binding1.introspect(dt2, null));
+ assertNull(binding1.getWrapperHandler());
+
+ DataBindingExtensionPoint registry = EasyMock.createMock(DataBindingExtensionPoint.class);
+ registry.addDataBinding(binding1);
+ EasyMock.expect(registry.getDataBinding(Node.class.getName())).andReturn(binding1);
+ EasyMock.replay(registry);
+
+ assertNotNull(registry.getDataBinding(Node.class.getName()));
+
+ DataBinding1 binding2 = new DataBinding1("dom", Node.class);
+ assertEquals("dom", binding2.getName());
+ }
+
+ private static class DataBinding1 extends BaseDataBinding {
+
+ /**
+ * @param baseType
+ */
+ public DataBinding1(Class<?> baseType) {
+ super(baseType);
+ }
+
+ /**
+ * @param name
+ * @param baseType
+ */
+ public DataBinding1(String name, Class<?> baseType) {
+ super(name, baseType);
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/SimpleTypeMapperExtensionTestCase.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/SimpleTypeMapperExtensionTestCase.java
new file mode 100644
index 0000000000..562c22354c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/SimpleTypeMapperExtensionTestCase.java
@@ -0,0 +1,124 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.extension;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.NamespaceContext;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl;
+import org.apache.tuscany.sca.interfacedef.util.TypeInfo;
+import org.easymock.EasyMock;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+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");
+ if (System.getProperty("java.vendor").toUpperCase().contains("SUN") && System.getProperty("java.version").contains("1.5.0")
+ ||
+ System.getProperty("java.vendor").toUpperCase().contains("APPLE INC.") && System.getProperty("java.version").contains("1.5.0")) {
+
+ // Work around a bug in SUN JDK (including Mac OS JDK)
+ SAMPLE_VALUES.put("gMonth", "--02--");
+ } else {
+ 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()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testMap() throws Exception {
+ SimpleTypeMapperImpl extension = new SimpleTypeMapperImpl();
+ TransformationContext context = EasyMock.createMock(TransformationContext.class);
+ Map<String, Object> metaData = new HashMap<String, 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.getName(), namespaceContext);
+ for (TypeInfo simpleType : SimpleTypeMapperImpl.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.getQName(), s, context);
+ String str = extension.toXMLLiteral(simpleType.getQName(), obj, context);
+ assertNotNull(str);
+ // assertTrue("[" + name + "] " + s + " " + str,
+ // str.contains((String) s));
+ }
+ } else if (value instanceof String) {
+ Object obj = extension.toJavaObject(simpleType.getQName(), (String)value, context);
+ String str = extension.toXMLLiteral(simpleType.getQName(), obj, context);
+ assertNotNull(str);
+ // assertTrue("[" + name + "] " + value + " " + str,
+ // str.contains((String) value));
+ }
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/TransformerExtensionTestCase.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/TransformerExtensionTestCase.java
new file mode 100644
index 0000000000..243ac71201
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/TransformerExtensionTestCase.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.extension;
+
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.databinding.Transformer;
+import org.apache.tuscany.sca.databinding.TransformerExtensionPoint;
+import org.apache.tuscany.sca.databinding.impl.BaseTransformer;
+import org.easymock.EasyMock;
+import org.w3c.dom.Node;
+
+/**
+ * Test case for TransformerExtension
+ *
+ * @version $Rev$ $Date$
+ */
+public class TransformerExtensionTestCase extends TestCase {
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ 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());
+ TransformerExtensionPoint registry = EasyMock.createMock(TransformerExtensionPoint.class);
+ registry.addTransformer(EasyMock.isA(Transformer.class), EasyMock.eq(true));
+ EasyMock
+ .expect(registry.getTransformer(transformer.getSourceDataBinding(), transformer.getTargetDataBinding()))
+ .andReturn(transformer);
+ EasyMock.replay(registry);
+ registry.addTransformer(transformer, true);
+ assertSame(transformer, registry.getTransformer(transformer.getSourceDataBinding(), transformer
+ .getTargetDataBinding()));
+ }
+
+ private static class MyTransformer extends BaseTransformer<Node, XMLStreamReader> {
+
+ @Override
+ protected Class<Node> getSourceType() {
+ return Node.class;
+ }
+
+ @Override
+ protected Class<XMLStreamReader> getTargetType() {
+ return XMLStreamReader.class;
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/XSDDataTypeConverterTestCase.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/XSDDataTypeConverterTestCase.java
new file mode 100644
index 0000000000..07ee0b0ca4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/extension/XSDDataTypeConverterTestCase.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.extension;
+
+import java.math.BigInteger;
+import java.util.Calendar;
+import java.util.GregorianCalendar;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.databinding.impl.XSDDataTypeConverter;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class XSDDataTypeConverterTestCase extends TestCase {
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ 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 = c.parseDate(s);
+ assertEquals(s, c.printDate(calendar));
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingRegistryImplTestCase.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingRegistryImplTestCase.java
new file mode 100644
index 0000000000..db210683dd
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingRegistryImplTestCase.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.impl;
+
+import 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.TestCase;
+
+import org.apache.tuscany.sca.databinding.DataBinding;
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.databinding.DefaultDataBindingExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
+import org.easymock.EasyMock;
+import org.xml.sax.ContentHandler;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataBindingRegistryImplTestCase extends TestCase {
+ private DataBindingExtensionPoint registry;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ registry = new DefaultDataBindingExtensionPoint();
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testRegistry() {
+ DataBinding db1 = createMock(DataBinding.class);
+ expect(db1.getAliases()).andReturn(new String[] {"db1"}).anyTimes();
+ expect(db1.getName()).andReturn(ContentHandler.class.getName()).anyTimes();
+ DataType<Class> dataType1 = new DataTypeImpl<Class>(ContentHandler.class, ContentHandler.class);
+ expect(db1.introspect(dataType1, null)).andReturn(true);
+ expect(db1.introspect(EasyMock.not(EasyMock.same(dataType1)), (Operation) EasyMock.isNull()))
+ .andReturn(false).anyTimes();
+ replay(db1);
+
+ registry.addDataBinding(db1);
+
+ DataBinding db2 = createMock(DataBinding.class);
+ expect(db2.getAliases()).andReturn(new String[] {"db2"}).anyTimes();
+ expect(db2.getName()).andReturn(XMLStreamReader.class.getName()).anyTimes();
+ DataType<Class> dataType2 = new DataTypeImpl<Class>(XMLStreamReader.class, XMLStreamReader.class);
+ expect(db2.introspect(dataType2, null)).andReturn(true);
+ expect(db2.introspect(EasyMock.not(EasyMock.same(dataType2)), (Operation) EasyMock.isNull()))
+ .andReturn(false).anyTimes();
+ replay(db2);
+
+ registry.addDataBinding(db2);
+
+ // Lookup by name
+ String name = db1.getName();
+ DataBinding db3 = registry.getDataBinding(name);
+ assertSame(db1, db3);
+
+ // Look up by alias
+ DataBinding db5 = registry.getDataBinding("db1");
+ assertSame(db1, db5);
+
+ DataType dt = new DataTypeImpl<Class>(ContentHandler.class, null);
+ registry.introspectType(dt, null);
+ assertEquals(dataType1.getLogical(), ContentHandler.class);
+ //FIXME does not match with dynamically loaded databindings
+ //assertTrue(dt.getDataBinding().equalsIgnoreCase("java.lang.Object"));
+
+ registry.removeDataBinding(name);
+ DataBinding db4 = registry.getDataBinding(name);
+ assertNull(db4);
+
+ dt = new DataTypeImpl<Class>(null, String.class, null);
+ registry.introspectType(dt, null);
+ //FIXME does not match with dynamically loaded databindings
+ //assertEquals("java.lang.Object", dt.getDataBinding());
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingTestCase.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DataBindingTestCase.java
new file mode 100644
index 0000000000..7c882c0285
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/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.sca.databinding.impl;
+
+import java.lang.reflect.Method;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.databinding.annotation.DataBinding;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataBindingTestCase extends TestCase {
+ @SuppressWarnings("unused")
+ public void testDataType() throws Exception {
+ Class<Test> testClass = Test.class;
+ DataBinding d = testClass.getAnnotation(DataBinding.class);
+ Assert.assertEquals(d.value(), "sdo");
+
+ Method method = testClass.getMethod("test", new Class[] {Object.class});
+ DataBinding d2 = method.getAnnotation(DataBinding.class);
+ Assert.assertEquals(d2.value(), "jaxb");
+ }
+
+ @DataBinding("sdo")
+ private static interface Test {
+ @DataBinding("jaxb")
+ Object test(Object object);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DirectedGraphTestCase.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DirectedGraphTestCase.java
new file mode 100644
index 0000000000..053e4f2a59
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/DirectedGraphTestCase.java
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.impl;
+
+import java.util.Arrays;
+import java.util.List;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.databinding.impl.DirectedGraph.Edge;
+import org.apache.tuscany.sca.databinding.impl.DirectedGraph.Vertex;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class DirectedGraphTestCase extends TestCase {
+ private DirectedGraph<String, Object> graph;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ graph = new DirectedGraph<String, Object>();
+ }
+
+ public void testGraph() {
+ graph.addEdge("a", "b", null, 3, true);
+ graph.addEdge("b", "c", null, 1, true);
+ // graph.addEdge("a", "c", null, 8, true);
+ graph.addEdge("a", "d", null, 3, true);
+ graph.addEdge("b", "d", null, 2, true);
+ graph.addEdge("d", "c", null, 3, true);
+ graph.addEdge("c", "b", null, 1, true);
+ graph.addEdge("c", "d", null, 2, true);
+ graph.addEdge("d", "b", null, 1, true);
+ graph.addEdge("a", "e", null, 8, true);
+ graph.addEdge("c", "c", null, 2, true);
+ graph.addEdge("f", "g", null, 2, false);
+ graph.addEdge("f", "h", null, 8, true);
+ graph.addEdge("g", "j", null, 2, false);
+ graph.addEdge("j", "i", null, 2, true);
+ graph.addEdge("h", "i", null, 8, true);
+
+ 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);
+
+ DirectedGraph<String, Object>.Path path5 = graph.getShortestPath("f", "i");
+ Assert.assertTrue(path5.getWeight() == 16 && path5.getEdges().size() == 2);
+
+ }
+
+ public void testSort() {
+ graph.addEdge("a", "b");
+ graph.addEdge("a", "c");
+ graph.addEdge("c", "d");
+ graph.addEdge("b", "c");
+ List<String> order = graph.topologicalSort(true);
+ assertEquals(Arrays.asList("a", "b", "c", "d"), order);
+ assertTrue(!graph.getVertices().isEmpty());
+
+ graph.addEdge("d", "a");
+ try {
+ order = graph.topologicalSort(true);
+ assertTrue("Should have failed", false);
+ } catch (IllegalArgumentException e) {
+ assertTrue(true);
+ }
+
+ graph.removeEdge("d", "a");
+ order = graph.topologicalSort(false);
+ assertEquals(Arrays.asList("a", "b", "c", "d"), order);
+ assertTrue(graph.getVertices().isEmpty());
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/MediatorImplTestCase.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/MediatorImplTestCase.java
new file mode 100644
index 0000000000..6cc8868397
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/MediatorImplTestCase.java
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.impl;
+
+import java.io.StringWriter;
+import java.io.Writer;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.databinding.DefaultDataBindingExtensionPoint;
+import org.apache.tuscany.sca.databinding.DefaultTransformerExtensionPoint;
+import org.apache.tuscany.sca.databinding.TransformationContext;
+import org.apache.tuscany.sca.databinding.TransformerExtensionPoint;
+import org.apache.tuscany.sca.databinding.xml.Node2String;
+import org.apache.tuscany.sca.databinding.xml.Node2Writer;
+import org.apache.tuscany.sca.databinding.xml.SAX2DOMPipe;
+import org.apache.tuscany.sca.databinding.xml.String2SAX;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Test case for MediatorImpl
+ *
+ * @version $Rev$ $Date$
+ */
+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;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ DataBindingExtensionPoint dataBindingRegistry = new DefaultDataBindingExtensionPoint();
+ TransformerExtensionPoint registry = new DefaultTransformerExtensionPoint();
+
+ registry.addTransformer(new String2SAX(), true);
+ registry.addTransformer(new SAX2DOMPipe(), true);
+ registry.addTransformer(new Node2String(), true);
+ registry.addTransformer(new Node2Writer(), true);
+
+ mediator = new MediatorImpl(dataBindingRegistry, registry);
+ }
+
+ private TransformationContext createTransformationContext(Class sourceType, Class targetType) {
+ TransformationContext context = new TransformationContextImpl();
+ DataType sourceDataType = new DataTypeImpl<Class>(sourceType.getName(), sourceType, sourceType);
+ DataType targetDataType = new DataTypeImpl<Class>(targetType.getName(), 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/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/TransformerRegistryImplTestCase.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/TransformerRegistryImplTestCase.java
new file mode 100644
index 0000000000..31c3fd4f00
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/TransformerRegistryImplTestCase.java
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.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.sca.databinding.DefaultTransformerExtensionPoint;
+import org.apache.tuscany.sca.databinding.Transformer;
+import org.apache.tuscany.sca.databinding.TransformerExtensionPoint;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class TransformerRegistryImplTestCase extends TestCase {
+ private TransformerExtensionPoint registry;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ registry = new DefaultTransformerExtensionPoint();
+ }
+
+ public void testRegisterTransformer1() {
+ Transformer transformer = createMock(Transformer.class);
+ registry.addTransformer("a", "b", 10, transformer, true);
+ 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.addTransformer(transformer, true);
+ Transformer t = registry.getTransformer("a", "b");
+ Assert.assertSame(t, transformer);
+ }
+
+ public void testUnregisterTransformer() {
+ Transformer transformer = createMock(Transformer.class);
+ registry.addTransformer("a", "b", 10, transformer, true);
+ boolean result = registry.removeTransformer("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.addTransformer(t1, true);
+ registry.addTransformer(t2, true);
+ registry.addTransformer(t3, true);
+
+ 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() == 1 && l2.get(0) == t3);
+ List<Transformer> l3 = registry.getTransformerChain("a", "d");
+ Assert.assertNull(l3);
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/XMLDocumentStreamReaderTestCase.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/XMLDocumentStreamReaderTestCase.java
new file mode 100644
index 0000000000..dd3d000798
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/impl/XMLDocumentStreamReaderTestCase.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.impl;
+
+import java.io.StringReader;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.databinding.xml.XMLDocumentStreamReader;
+import org.apache.tuscany.sca.databinding.xml.XMLStreamReader2String;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class XMLDocumentStreamReaderTestCase {
+ private static final String xml = "<e1><e2 a2=\"a2\"><e4>E4</e4></e2><e3 a3=\"a3\"/></e1>";
+
+ @org.junit.Test
+ public void testReader() throws Exception {
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ XMLStreamReader r1 = factory.createXMLStreamReader(new StringReader(xml));
+ XMLDocumentStreamReader r2 = new XMLDocumentStreamReader(r1);
+ XMLStreamReader2String t1 = new XMLStreamReader2String();
+ String result = t1.transform(r2, null);
+ System.out.println(result);
+ XMLStreamReader r3 = factory.createXMLStreamReader(new StringReader(xml));
+ r3.nextTag();
+ r3.nextTag();
+ Assert.assertEquals(XMLStreamConstants.START_ELEMENT, r3.getEventType());
+ Assert.assertEquals(new QName(null, "e2"), r3.getName());
+ XMLDocumentStreamReader r4 = new XMLDocumentStreamReader(r3);
+ result = t1.transform(r4, null);
+ System.out.println(result);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/BeanXMLStreamReaderTestCase.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/BeanXMLStreamReaderTestCase.java
new file mode 100644
index 0000000000..bdc9690285
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/BeanXMLStreamReaderTestCase.java
@@ -0,0 +1,192 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.custommonkey.xmlunit.Diff;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class BeanXMLStreamReaderTestCase extends TestCase {
+ private static final String XML_RESULT =
+ "<?xml version='1.0' encoding='UTF-8'?>" + "<MyBean xmlns=\"http://xml.databinding.sca.tuscany.apache.org/\">"
+ + "<arr>1</arr><arr>2</arr><arr>3</arr><bean><name>Name</name></bean><i>1</i>"
+ + "<list>Item1</list><list>Item2</list>"
+ + "<map><entry><key>key1</key><value>value1</value></entry>"
+ + "<entry><key>key2</key><value>value2</value></entry></map>"
+ + "<nil xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:nil=\"true\" />"
+ + "<str>ABC</str></MyBean>";
+
+ // The map entries can come in a different order
+ private static final String XML_RESULT1 =
+ "<?xml version='1.0' encoding='UTF-8'?>" + "<MyBean xmlns=\"http://xml.databinding.sca.tuscany.apache.org/\">"
+ + "<arr>1</arr><arr>2</arr><arr>3</arr><bean><name>Name</name></bean><i>1</i>"
+ + "<list>Item1</list><list>Item2</list>"
+ + "<map><entry><key>key2</key><value>value2</value></entry>"
+ + "<entry><key>key1</key><value>value1</value></entry></map>"
+ + "<nil xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:nil=\"true\" />"
+ + "<str>ABC</str></MyBean>";
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testTransformation() throws Exception {
+ MyBean bean = new MyBean();
+ bean.str = "ABC";
+ bean.i = 1;
+ bean.arr = new long[] {1, 2, 3};
+ bean.bean = new AnotherBean();
+ bean.bean.setName("Name");
+ bean.list.add("Item1");
+ bean.list.add("Item2");
+ bean.map.put("key1", "value1");
+ bean.map.put("key2", "value2");
+ XMLStreamReader reader = new BeanXMLStreamReaderImpl(null, bean);
+ XMLStreamReader2String t3 = new XMLStreamReader2String();
+ String xml = t3.transform(reader, null);
+ Diff diff = new Diff(XML_RESULT, xml);
+ Diff diff1 = new Diff(XML_RESULT1, xml);
+ assertTrue(diff.similar() || diff1.similar());
+ }
+
+ private static class MyBean {
+ private long arr[];
+ private String str;
+ private int i;
+ private String nil;
+ private List<String> list = new ArrayList();
+ private AnotherBean bean;
+ private Map<String, String> map = new HashMap<String, String>();
+
+ /**
+ * @return the i
+ */
+ public int getI() {
+ return i;
+ }
+
+ /**
+ * @param i the i to set
+ */
+ public void setI(int i) {
+ this.i = i;
+ }
+
+ /**
+ * @return the arr
+ */
+ public long[] getArr() {
+ return arr;
+ }
+
+ /**
+ * @param arr the arr to set
+ */
+ public void setArr(long[] arr) {
+ this.arr = arr;
+ }
+
+ /**
+ * @return the str
+ */
+ public String getStr() {
+ return str;
+ }
+
+ /**
+ * @param str the str to set
+ */
+ public void setStr(String str) {
+ this.str = str;
+ }
+
+ /**
+ * @return the bean
+ */
+ public AnotherBean getBean() {
+ return bean;
+ }
+
+ /**
+ * @param bean the bean to set
+ */
+ public void setBean(AnotherBean bean) {
+ this.bean = bean;
+ }
+
+ public List<String> getList() {
+ return list;
+ }
+
+ public void setList(List<String> list) {
+ this.list = list;
+ }
+
+ public String getNil() {
+ return nil;
+ }
+
+ public void setNil(String nil) {
+ this.nil = nil;
+ }
+
+ public Map<String, String> getMap() {
+ return map;
+ }
+
+ public void setMap(Map<String, String> map) {
+ this.map = map;
+ }
+
+ }
+
+ private static class AnotherBean {
+ private String name;
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DOM2StAXTestCase.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DOM2StAXTestCase.java
new file mode 100644
index 0000000000..9e9dabcea7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DOM2StAXTestCase.java
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.custommonkey.xmlunit.XMLAssert;
+import org.w3c.dom.Node;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+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>";
+
+ private static final String CRAZY_XML =
+ "<p:e1 xmlns=\"http://ns0\" xmlns:p=\"http://p1\">" + "<p:e2 xmlns:p=\"http://p2\"/><e3/><e4 xmlns=\"\">E4</e4></p:e1>";
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testTransformation() throws Exception {
+ 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);
+ XMLAssert.assertXMLEqual(IPO_XML, xml);
+ // assertTrue(xml != null && xml.indexOf("<shipDate>1999-12-05</shipDate>") != -1);
+ }
+
+ public void testTransformation2() throws Exception {
+ String2Node t1 = new String2Node();
+ Node node = t1.transform(CRAZY_XML, null);
+ Node2XMLStreamReader t2 = new Node2XMLStreamReader();
+ XMLStreamReader reader = t2.transform(node, null);
+ XMLStreamReader2String t3 = new XMLStreamReader2String();
+ String xml = t3.transform(reader, null);
+ // System.out.println(xml);
+ XMLAssert.assertXMLEqual(CRAZY_XML, xml);
+ assertTrue(xml.contains("<p:e2 xmlns:p=\"http://p2\""));
+ }
+
+ public void testTransformation3() throws Exception {
+ String2Node t1 = new String2Node();
+ Node node = t1.transform(IPO_XML, null);
+ DOMXmlNodeImpl element = new DOMXmlNodeImpl(node);
+ XmlTreeStreamReaderImpl reader = new XmlTreeStreamReaderImpl(element);
+ XMLStreamReader2String t3 = new XMLStreamReader2String();
+ String xml = t3.transform(reader, null);
+ XMLAssert.assertXMLEqual(IPO_XML, xml);
+ // assertTrue(xml != null && xml.indexOf("<shipDate>1999-12-05</shipDate>") != -1);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DataPipeTestCase.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DataPipeTestCase.java
new file mode 100644
index 0000000000..f3b37c86db
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/DataPipeTestCase.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.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.sca.databinding.DataPipe;
+import org.apache.tuscany.sca.databinding.DataPipeTransformer;
+import org.apache.tuscany.sca.databinding.impl.DOMHelper;
+import org.apache.tuscany.sca.databinding.impl.PipedTransformer;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Test case for DataPipe
+ *
+ * @version $Rev$ $Date$
+ */
+public class DataPipeTestCase extends TestCase {
+
+ public final void testStreamPipe() throws IOException {
+ byte[] bytes = new byte[] {1, 2, 3};
+ DataPipeTransformer<OutputStream, InputStream> pipe = new StreamDataPipe();
+ DataPipe<OutputStream, InputStream> dataPipe = pipe.newInstance();
+ OutputStream os = dataPipe.getSink();
+ os.write(bytes);
+ byte[] newBytes = new byte[16];
+ int count = dataPipe.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());
+ DataPipe<Writer, Reader> dataPipe = pipe.newInstance();
+ dataPipe.getSink().write(str);
+ char[] buf = new char[16];
+ int count = dataPipe.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/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/JavaBean2XMLStreamReaderTestCase.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/JavaBean2XMLStreamReaderTestCase.java
new file mode 100644
index 0000000000..3a287a5bb7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/JavaBean2XMLStreamReaderTestCase.java
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.databinding.javabeans.JavaBean2XMLStreamReaderTransformer;
+import org.custommonkey.xmlunit.XMLAssert;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaBean2XMLStreamReaderTestCase extends TestCase {
+ private static final String XML_RESULT =
+ "<?xml version='1.0' encoding='UTF-8'?>"
+ + "<MyBean xmlns=\"http://xml.databinding.sca.tuscany.apache.org/\">"
+ + "<arr>1</arr><arr>2</arr><arr>3</arr><bean><name>Name</name></bean><i>1</i><str>ABC</str>"
+ + "</MyBean>";
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testTransformation() throws Exception {
+ JavaBean2XMLStreamReaderTransformer t2 = new JavaBean2XMLStreamReaderTransformer();
+ MyBean bean = new MyBean();
+ bean.str = "ABC";
+ bean.i = 1;
+ bean.arr = new long[] {1, 2, 3};
+ bean.bean = new AnotherBean();
+ bean.bean.setName("Name");
+ XMLStreamReader reader = t2.transform(bean, null);
+ XMLStreamReader2String t3 = new XMLStreamReader2String();
+ String xml = t3.transform(reader, null);
+ XMLAssert.assertXMLEqual(XML_RESULT, xml);
+
+ }
+
+ private static class MyBean {
+ private String str;
+ private int i;
+ private long arr[];
+ private AnotherBean bean;
+
+ /**
+ * @return the arr
+ */
+ public long[] getArr() {
+ return arr;
+ }
+
+ /**
+ * @param arr the arr to set
+ */
+ public void setArr(long[] arr) {
+ this.arr = arr;
+ }
+
+ /**
+ * @return the i
+ */
+ public int getI() {
+ return i;
+ }
+
+ /**
+ * @param i the i to set
+ */
+ public void setI(int i) {
+ this.i = i;
+ }
+
+ /**
+ * @return the str
+ */
+ public String getStr() {
+ return str;
+ }
+
+ /**
+ * @param str the str to set
+ */
+ public void setStr(String str) {
+ this.str = str;
+ }
+
+ /**
+ * @return the bean
+ */
+ public AnotherBean getBean() {
+ return bean;
+ }
+
+ /**
+ * @param bean the bean to set
+ */
+ public void setBean(AnotherBean bean) {
+ this.bean = bean;
+ }
+
+ }
+
+ private static class AnotherBean {
+ private String name;
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/Node2StringTestCase.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/Node2StringTestCase.java
new file mode 100644
index 0000000000..cc1f9375c8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/Node2StringTestCase.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.databinding.impl.DOMHelper;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+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/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/PushTransformationTestCase.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/PushTransformationTestCase.java
new file mode 100644
index 0000000000..5ae0616577
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/PushTransformationTestCase.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.databinding.xml;
+
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.databinding.impl.PipedTransformer;
+import org.w3c.dom.Node;
+import org.xml.sax.ContentHandler;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+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()
+ */
+ @Override
+ 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/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/StAXHelperTestCase.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/StAXHelperTestCase.java
new file mode 100644
index 0000000000..9ca490f2d8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/StAXHelperTestCase.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.xml;
+
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.custommonkey.xmlunit.XMLAssert;
+
+/**
+ * Test Case for StAXHelper
+ *
+ * @version $Rev$ $Date$
+ */
+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()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ public void testHelper() throws Exception {
+ XMLStreamReader reader = StAXHelper.createXMLStreamReader(XML);
+ String xml = StAXHelper.save(reader);
+ XMLAssert.assertXMLEqual(XML, xml);
+ reader = StAXHelper.createXMLStreamReader(xml);
+ assertNotNull(reader);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/TraxTransformerTestCase.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/TraxTransformerTestCase.java
new file mode 100644
index 0000000000..ff6f8c1406
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/TraxTransformerTestCase.java
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.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;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class TraxTransformerTestCase extends TestCase {
+ private URL url;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ 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/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderTestCase.java b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderTestCase.java
new file mode 100644
index 0000000000..0463e7d9f5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/java/org/apache/tuscany/sca/databinding/xml/XmlTreeStreamReaderTestCase.java
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.databinding.xml;
+
+import java.io.StringReader;
+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.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.Assert;
+
+import org.custommonkey.xmlunit.XMLAssert;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class XmlTreeStreamReaderTestCase {
+ 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 static final String XML_RESULT =
+ "<?xml version='1.0' encoding='UTF-8'?>" + "<p1:e1 xmlns:p1=\"http://ns\">"
+ + "<p2:e11 xmlns:p2=\"http://ns1\">MyText</p2:e11>"
+ + "<p1:e12><p1:e121 /></p1:e12>"
+ + "<ipo:purchaseOrder xmlns:ipo=\"http://www.example.com/IPO\" "
+ + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
+ + "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></p1:e1>";
+ private XmlNodeImpl root;
+
+ @Before
+ public void setUp() throws Exception {
+ root = new XmlNodeImpl();
+ root.name = new QName("http://ns", "e1", "p1");
+
+ XmlNodeImpl e11 = new XmlNodeImpl();
+ e11.name = new QName("http://ns1", "e11", "p2");
+
+ XmlNodeImpl e12 = new XmlNodeImpl();
+ e12.name = new QName("http://ns", "e12");
+
+ root.children.add(e11);
+ root.children.add(e12);
+
+ XmlNodeImpl e121 = new XmlNodeImpl();
+ e121.name = new QName("http://ns", "e121");
+ e12.children.add(e121);
+
+ XmlNodeImpl e111 = new XmlNodeImpl();
+ e111.value = "MyText";
+ e11.children.add(e111);
+
+ XmlNodeImpl e13 = new XmlNodeImpl();
+ e13.value = XMLInputFactory.newInstance().createXMLStreamReader(new StringReader(IPO_XML));
+ root.children.add(e13);
+
+ }
+
+ @Test
+ public void testIterator() {
+ List<QName> elements = new ArrayList<QName>();
+ XmlNodeIterator i = new XmlNodeIterator(root);
+ for (; i.hasNext();) {
+ XmlNode e = i.next();
+ elements.add(e.getName());
+ }
+ // System.out.println(elements);
+ QName[] names =
+ {new QName("http://ns", "e1"), new QName("http://ns1", "e11"), null, null, new QName("http://ns1", "e11"),
+ new QName("http://ns", "e12"), new QName("http://ns", "e121"), new QName("http://ns", "e121"),
+ new QName("http://ns", "e12"), null, null, new QName("http://ns", "e1")};
+ Assert.assertEquals(Arrays.asList(names), elements);
+ }
+
+ @Test
+ public void testReader() throws Exception {
+ XmlTreeStreamReaderImpl reader = new XmlTreeStreamReaderImpl(root);
+ XMLStreamReader2String t = new XMLStreamReader2String();
+ String xml = t.transform(reader, null);
+ XMLAssert.assertXMLEqual(XML_RESULT, xml);
+ }
+
+ private static class XmlNodeImpl implements XmlNode {
+ private List<XmlNode> children = new ArrayList<XmlNode>();
+ private List<XmlNode> attrs = new ArrayList<XmlNode>();
+ private Map<String, String> namespaces = new HashMap<String, String>();
+ private QName name;
+ private Object value = "123";
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.xml.XmlNode#attributes()
+ */
+ public List<XmlNode> attributes() {
+ return attrs;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.xml.XmlNode#children()
+ */
+ public Iterator<XmlNode> children() {
+ return children.iterator();
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.xml.XmlNode#getName()
+ */
+ public QName getName() {
+ return name;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.xml.XmlNode#getValue()
+ */
+ public <T> T getValue() {
+ return (T)value;
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.databinding.xml.XmlNode#namespaces()
+ */
+ public Map<String, String> namespaces() {
+ return namespaces;
+ }
+
+ @Override
+ public String toString() {
+ return String.valueOf(name);
+ }
+
+ public Type getType() {
+ if (value instanceof XMLStreamReader) {
+ return Type.READER;
+ }
+ return name == null ? Type.CHARACTERS : Type.ELEMENT;
+ }
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/databinding/src/test/resources/org/apache/tuscany/sca/databinding/impl/ipo.xsd b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/resources/org/apache/tuscany/sca/databinding/impl/ipo.xsd
new file mode 100644
index 0000000000..92a576fb98
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/resources/org/apache/tuscany/sca/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/sca-java-1.x/branches/sca-android/modules/databinding/src/test/resources/org/apache/tuscany/sca/databinding/impl/order.wsdl b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/resources/org/apache/tuscany/sca/databinding/impl/order.wsdl
new file mode 100644
index 0000000000..100890e10b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/resources/org/apache/tuscany/sca/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/sca-java-1.x/branches/sca-android/modules/databinding/src/test/resources/org/apache/tuscany/sca/databinding/xml/foo.xml b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/resources/org/apache/tuscany/sca/databinding/xml/foo.xml
new file mode 100644
index 0000000000..0ba8ade1e0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/databinding/src/test/resources/org/apache/tuscany/sca/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/sca-java-1.x/branches/sca-android/modules/definitions-xml/LICENSE b/sca-java-1.x/branches/sca-android/modules/definitions-xml/LICENSE
new file mode 100644
index 0000000000..6e529a25c4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/definitions-xml/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/definitions-xml/META-INF/README b/sca-java-1.x/branches/sca-android/modules/definitions-xml/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/definitions-xml/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/definitions-xml/NOTICE b/sca-java-1.x/branches/sca-android/modules/definitions-xml/NOTICE
new file mode 100644
index 0000000000..1325efd8bf
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/definitions-xml/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/definitions-xml/pom.xml b/sca-java-1.x/branches/sca-android/modules/definitions-xml/pom.xml
new file mode 100644
index 0000000000..75db3b51b0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/definitions-xml/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.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-definitions-xml</artifactId>
+ <name>Apache Tuscany SCA Definitions XML Model</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-policy</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-policy-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-definitions</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly-xsd</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.definitions.xml</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.definitions.xml*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/SCADefinitionsDocumentProcessor.java b/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/SCADefinitionsDocumentProcessor.java
new file mode 100644
index 0000000000..0b760ef712
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/SCADefinitionsDocumentProcessor.java
@@ -0,0 +1,197 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.definitions.xml;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLConnection;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+
+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;
+
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.definitions.impl.SCADefinitionsImpl;
+import org.apache.tuscany.sca.definitions.util.SCADefinitionsUtil;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ * A SCA Definitions Document processor.
+ *
+ * @version $Rev$ $Date$
+ */
+public class SCADefinitionsDocumentProcessor implements URLArtifactProcessor<SCADefinitions> {
+ private StAXArtifactProcessor<Object> extensionProcessor;
+ private XMLInputFactory inputFactory;
+ private static final String TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.0";
+ private static final String DEFINITIONS = "definitions";
+ private static final QName DEFINITIONS_QNAME = new QName(TUSCANY_NS, DEFINITIONS);
+ private Monitor monitor;
+
+ /**
+ * Construct a new SCADefinitions processor
+ * @param assemblyFactory
+ * @param policyFactory
+ * @param staxProcessor
+ */
+ public SCADefinitionsDocumentProcessor(StAXArtifactProcessor<Object> staxProcessor,
+ XMLInputFactory inputFactory,
+ Monitor monitor) {
+ this.extensionProcessor = (StAXArtifactProcessor<Object>)staxProcessor;
+ this.inputFactory = inputFactory;
+ this.monitor = monitor;
+ }
+
+ /**
+ * Constructs a new SCADefinitions processor.
+ *
+ * @param modelFactories
+ * @param staxProcessor
+ */
+ public SCADefinitionsDocumentProcessor(ModelFactoryExtensionPoint modelFactories,
+ StAXArtifactProcessor<Object> staxProcessor,
+ Monitor monitor) {
+ this.extensionProcessor = (StAXArtifactProcessor<Object>)staxProcessor;
+ this.inputFactory = modelFactories.getFactory(XMLInputFactory.class);
+ this.monitor = monitor;
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "definitions-xml-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "definitions-xml-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
+
+ public SCADefinitions read(URL contributionURL, final URI uri, final URL url) throws ContributionReadException {
+ InputStream urlStream = null;
+ try {
+ // Allow privileged access to open URL stream. Add FilePermission to added to security
+ // policy file.
+ try {
+ urlStream = AccessController.doPrivileged(new PrivilegedExceptionAction<InputStream>() {
+ public InputStream run() throws IOException {
+ URLConnection connection = url.openConnection();
+ connection.setUseCaches(false);
+ return connection.getInputStream();
+ }
+ });
+ } catch (PrivilegedActionException e) {
+ error("PrivilegedActionException", url, (IOException)e.getException());
+ throw (IOException)e.getException();
+ }
+
+ //urlStream = createInputStream(url);
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(url.toString(), urlStream);
+
+ SCADefinitions definitions = new SCADefinitionsImpl();
+ QName name = null;
+ int event;
+ while ( reader.hasNext() ) {
+ event = reader.next();
+
+ if ( event == XMLStreamConstants.START_ELEMENT ||
+ event == XMLStreamConstants.END_ELEMENT ) {
+ name = reader.getName();
+ if ( name.equals(DEFINITIONS_QNAME) ) {
+ if ( event == XMLStreamConstants.END_ELEMENT ) {
+ return definitions;
+ }
+ } else {
+ SCADefinitions aDefn = (SCADefinitions)extensionProcessor.read(reader);
+ SCADefinitionsUtil.aggregateSCADefinitions(aDefn, definitions);
+ }
+ }
+ }
+
+ return definitions;
+ } catch (XMLStreamException e) {
+ ContributionReadException ce = new ContributionReadException(e);
+ error("ContributionReadException", inputFactory, ce);
+ throw ce;
+ } catch (IOException e) {
+ ContributionReadException ce = new ContributionReadException(e);
+ error("ContributionReadException", inputFactory, ce);
+ throw ce;
+ } finally {
+
+ try {
+ if (urlStream != null) {
+ urlStream.close();
+ urlStream = null;
+ }
+ } catch (IOException ioe) {
+ //ignore
+ }
+ }
+ }
+
+ public void resolve(SCADefinitions scaDefinitions, ModelResolver resolver) throws ContributionResolveException {
+ SCADefinitionsUtil.stripDuplicates(scaDefinitions);
+ extensionProcessor.resolve(scaDefinitions, resolver);
+ }
+
+ public String getArtifactType() {
+ return "definitions.xml";
+ }
+
+ public Class<SCADefinitions> getModelType() {
+ return SCADefinitions.class;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/SCADefinitionsProcessor.java b/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/SCADefinitionsProcessor.java
new file mode 100644
index 0000000000..b87d890866
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/SCADefinitionsProcessor.java
@@ -0,0 +1,257 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.definitions.xml;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.definitions.impl.SCADefinitionsImpl;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.ProfileIntent;
+import org.apache.tuscany.sca.policy.QualifiedIntent;
+
+/**
+ * Processor for SCA Definitions
+ *
+ * @version $Rev$ $Date$
+ */
+public class SCADefinitionsProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<SCADefinitions> {
+
+ private StAXArtifactProcessor<Object> extensionProcessor;
+ private Monitor monitor;
+
+ public static final String BINDING = "binding";
+ public static final String IMPLEMENTATION = "implementation";
+ public static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0";
+ public static final String SCA_DEFINITIONS = "definitions";
+ public static final QName SCA_DEFINITIONS_QNAME = new QName(SCA10_NS, SCA_DEFINITIONS);
+ public static final String TARGET_NAMESPACE = "targetNamespace";
+ public static final String NAME = "name";
+
+ /**
+ * Construct a new definitions processor
+ * @param extensionProcessor
+ * @param modelResolver
+ */
+ public SCADefinitionsProcessor(StAXArtifactProcessor<Object> extensionProcessor,
+ ModelResolver modelResolver, Monitor monitor) {
+ this.extensionProcessor = extensionProcessor;
+ this.monitor = monitor;
+ }
+
+ public SCADefinitionsProcessor(ExtensionPointRegistry extensionPoints,
+ StAXArtifactProcessor<Object> extensionProcessor,
+ Monitor monitor) {
+ this.extensionProcessor = extensionProcessor;
+ this.monitor = monitor;
+ }
+
+ public SCADefinitions read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ QName name = null;
+ SCADefinitions definitions = null;
+ String targetNamespace = null;
+
+ while (reader.hasNext()) {
+ int event = reader.getEventType();
+ switch (event) {
+ case START_ELEMENT: {
+ name = reader.getName();
+ if ( SCA_DEFINITIONS_QNAME.equals(name)) {
+ definitions = new SCADefinitionsImpl();
+ targetNamespace = reader.getAttributeValue(null, TARGET_NAMESPACE);
+ definitions.setTargetNamespace(targetNamespace);
+ } else {
+ Object extension = extensionProcessor.read(reader);
+ if (extension != null) {
+ if ( extension instanceof Intent ) {
+ Intent intent = (Intent)extension;
+ intent.setName(new QName(targetNamespace,
+ intent.getName().getLocalPart()));
+ if ( intent instanceof QualifiedIntent ) {
+ QualifiedIntent qualifiedIntent = (QualifiedIntent)intent;
+ qualifiedIntent.getQualifiableIntent().
+ setName(new QName(targetNamespace,
+ qualifiedIntent.getQualifiableIntent().getName().getLocalPart()));
+ }
+
+ // FIXME: Workaround for TUSCANY-2499
+ intent.setUnresolved(false);
+
+ definitions.getPolicyIntents().add(intent);
+ } else if ( extension instanceof PolicySet ) {
+ PolicySet policySet = (PolicySet)extension;
+ policySet.setName(new QName(targetNamespace,
+ policySet.getName().getLocalPart()));
+ definitions.getPolicySets().add(policySet);
+ } else if ( extension instanceof Binding ) {
+ Binding binding = (Binding)extension;
+ definitions.getBindings().add(binding);
+ } else if ( extension instanceof IntentAttachPointType ) {
+ IntentAttachPointType type = (IntentAttachPointType)extension;
+ if ( type.getName().getLocalPart().startsWith(BINDING)) {
+ definitions.getBindingTypes().add((IntentAttachPointType)extension);
+ } else if ( type.getName().getLocalPart().startsWith(IMPLEMENTATION)) {
+ definitions.getImplementationTypes().add((IntentAttachPointType)extension);
+ }
+ }
+ }
+ break;
+ }
+ }
+
+ case XMLStreamConstants.CHARACTERS:
+ break;
+
+ case END_ELEMENT:
+ name = reader.getName();
+ if ( SCA_DEFINITIONS_QNAME.equals(name)) {
+ return definitions;
+ }
+ break;
+ }
+
+ //Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
+ }
+ return definitions;
+ }
+
+ public void write(SCADefinitions definitions, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+
+ writeStartDocument(writer, SCA10_NS, SCA_DEFINITIONS,
+ new XAttr(TARGET_NAMESPACE, definitions.getTargetNamespace()));
+
+ for (Intent policyIntent : definitions.getPolicyIntents()) {
+ extensionProcessor.write(policyIntent, writer);
+ }
+
+ for (PolicySet policySet : definitions.getPolicySets()) {
+ extensionProcessor.write(policySet, writer);
+ }
+
+ for (IntentAttachPointType bindingType : definitions.getBindingTypes()) {
+ extensionProcessor.write(bindingType, writer);
+ }
+
+ for (IntentAttachPointType implType : definitions.getImplementationTypes()) {
+ extensionProcessor.write(implType, writer);
+ }
+
+ writeEndDocument(writer);
+ }
+
+ public void resolve(SCADefinitions scaDefns, ModelResolver resolver) throws ContributionResolveException {
+ // start by adding all of the top level artifacts into the resolver as there
+ // are many cross artifact references in a definitions file and we don't want
+ // to be dependent on the order things appear
+
+ List<Intent> simpleIntents = new ArrayList<Intent>();
+ List<ProfileIntent> profileIntents = new ArrayList<ProfileIntent>();
+ List<QualifiedIntent> qualifiedIntents = new ArrayList<QualifiedIntent>();
+ List<PolicySet> simplePolicySets = new ArrayList<PolicySet>();
+ List<PolicySet> referredPolicySets = new ArrayList<PolicySet>();
+
+ for (Intent policyIntent : scaDefns.getPolicyIntents()) {
+ if (policyIntent instanceof ProfileIntent)
+ profileIntents.add((ProfileIntent)policyIntent);
+ else if (policyIntent instanceof QualifiedIntent)
+ qualifiedIntents.add((QualifiedIntent)policyIntent);
+ else simpleIntents.add(policyIntent);
+
+ resolver.addModel(policyIntent);
+ }
+
+ for (PolicySet policySet : scaDefns.getPolicySets()) {
+ if (policySet.getReferencedPolicySets().isEmpty())
+ simplePolicySets.add(policySet);
+ else referredPolicySets.add(policySet);
+
+ resolver.addModel(policySet);
+ }
+
+ for (IntentAttachPointType bindingType : scaDefns.getBindingTypes()) {
+ resolver.addModel(bindingType);
+ }
+
+ for (IntentAttachPointType implType : scaDefns.getImplementationTypes()) {
+ resolver.addModel(implType);
+ }
+
+ // now resolve everything to ensure that any references between
+ // artifacts are satisfied
+
+ for (Intent policyIntent : simpleIntents)
+ extensionProcessor.resolve(policyIntent, resolver);
+
+ for (ProfileIntent policyIntent : profileIntents)
+ extensionProcessor.resolve(policyIntent, resolver);
+
+ for (QualifiedIntent policyIntent : qualifiedIntents)
+ extensionProcessor.resolve(policyIntent, resolver);
+
+ for (PolicySet policySet : simplePolicySets)
+ extensionProcessor.resolve(policySet, resolver);
+
+ for (PolicySet policySet : referredPolicySets)
+ extensionProcessor.resolve(policySet, resolver);
+
+ for (int count = 0, size = scaDefns.getBindingTypes().size(); count < size; count++) {
+ IntentAttachPointType bindingType = scaDefns.getBindingTypes().get(count);
+ extensionProcessor.resolve(bindingType, resolver);
+ }
+
+ for (int count = 0, size = scaDefns.getImplementationTypes().size(); count < size; count++) {
+ IntentAttachPointType implType = scaDefns.getImplementationTypes().get(count);
+ extensionProcessor.resolve(implType, resolver);
+ }
+ }
+
+ public QName getArtifactType() {
+ return SCA_DEFINITIONS_QNAME;
+ }
+
+ public Class<SCADefinitions> getModelType() {
+ return SCADefinitions.class;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
new file mode 100644
index 0000000000..38fe3c5225
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for the artifact processor extension
+org.apache.tuscany.sca.definitions.xml.SCADefinitionsProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#definitions,model=org.apache.tuscany.sca.definitions.SCADefinitions
diff --git a/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor b/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor
new file mode 100644
index 0000000000..4392461df1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for the artifact processor extension
+org.apache.tuscany.sca.definitions.xml.SCADefinitionsDocumentProcessor;type=definitions.xml,model=org.apache.tuscany.sca.definitions.SCADefinitions
diff --git a/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/main/resources/definitions-xml-validation-messages.properties b/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/main/resources/definitions-xml-validation-messages.properties
new file mode 100644
index 0000000000..857887ec3f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/main/resources/definitions-xml-validation-messages.properties
@@ -0,0 +1,22 @@
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+ContributionReadException = ContributionReadException occured due to :
+PrivilegedActionException = Privileged Action Exception occured due to FilePermission in security policy file: \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/test/java/org/apache/tuscany/sca/definitions/Policy.java b/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/test/java/org/apache/tuscany/sca/definitions/Policy.java
new file mode 100644
index 0000000000..187b7fa9f8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/test/java/org/apache/tuscany/sca/definitions/Policy.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.definitions;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Interface that will abstract various types of policy specifications
+ * and attachments for example WS-Policy
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Policy {
+ QName getSchemaName();
+ void setUnresolved(boolean unresolved);
+ boolean isUnresolved();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/test/java/org/apache/tuscany/sca/definitions/ReadDocumentTestCase.java b/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/test/java/org/apache/tuscany/sca/definitions/ReadDocumentTestCase.java
new file mode 100644
index 0000000000..ec4ead8b87
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/test/java/org/apache/tuscany/sca/definitions/ReadDocumentTestCase.java
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.definitions;
+
+import java.net.URI;
+import java.net.URL;
+import java.util.Hashtable;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.ProfileIntent;
+import org.apache.tuscany.sca.policy.QualifiedIntent;
+
+/**
+ * Test reading SCA XML assembly documents.
+ *
+ * @version $Rev: 551296 $ $Date: 2007-06-28 01:18:35 +0530 (Thu, 28 Jun 2007) $
+ */
+public class ReadDocumentTestCase extends TestCase {
+
+ private URLArtifactProcessor<SCADefinitions> policyDefinitionsProcessor = null;
+ private SCADefinitions definitions;
+ Map<QName, Intent> intentTable = new Hashtable<QName, Intent>();
+ Map<QName, PolicySet> policySetTable = new Hashtable<QName, PolicySet>();
+ Map<QName, IntentAttachPointType> bindingTypesTable = new Hashtable<QName, IntentAttachPointType>();
+ Map<QName, IntentAttachPointType> implTypesTable = new Hashtable<QName, IntentAttachPointType>();
+ public static final String scaNamespace = "http://www.osoa.org/xmlns/sca/1.0";
+ public static final String namespace = "http://test";
+
+ private static final QName secureWsPolicy = new QName(namespace, "SecureWSPolicy");
+ private static final QName confidentiality = new QName(namespace, "confidentiality");
+ private static final QName integrity = new QName(namespace, "integrity");
+ private static final QName messageProtection = new QName(namespace, "messageProtection");
+ private static final QName confidentiality_transport = new QName(namespace, "confidentiality.transport");
+ private static final QName confidentiality_message = new QName(namespace, "confidentiality.message");
+ private static final QName secureReliablePolicy = new QName(namespace, "SecureReliablePolicy");
+ private static final QName secureMessagingPolicies = new QName(namespace, "SecureMessagingPolicies");
+ private static final QName securityPolicy = new QName(namespace, "SecurityPolicy");
+ private static final QName basicAuthMsgProtSecurity = new QName(namespace, "BasicAuthMsgProtSecurity");
+ private static final QName wsBinding = new QName(scaNamespace, "binding.ws");
+ private static final QName javaImpl = new QName(scaNamespace, "implementation.java");
+
+
+ @Override
+ public void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+
+ // Create StAX processors
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessors.addArtifactProcessor(new TestPolicyProcessor());
+
+ URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ policyDefinitionsProcessor = documentProcessors.getProcessor(SCADefinitions.class);
+
+ URL url = getClass().getResource("test_definitions.xml");
+ URI uri = URI.create("test_definitions.xml");
+ definitions = policyDefinitionsProcessor.read(null, uri, url);
+
+ for ( Intent intent : definitions.getPolicyIntents() ) {
+ intentTable.put(intent.getName(), intent);
+ }
+
+ for ( PolicySet policySet : definitions.getPolicySets() ) {
+ policySetTable.put(policySet.getName(), policySet);
+ }
+
+ for ( IntentAttachPointType bindingType : definitions.getBindingTypes() ) {
+ bindingTypesTable.put(bindingType.getName(), bindingType);
+ }
+
+ for ( IntentAttachPointType implType : definitions.getImplementationTypes() ) {
+ implTypesTable.put(implType.getName(), implType);
+ }
+ }
+
+ public void testReadSCADefinitions() throws Exception {
+ assertNotNull(definitions);
+
+ assertNotNull(intentTable.get(confidentiality));
+ assertNotNull(intentTable.get(messageProtection));
+ assertNotNull(intentTable.get(confidentiality_transport));
+ assertTrue(intentTable.get(confidentiality).getDescription().length() > 0 );
+
+ assertNotNull(policySetTable.get(secureReliablePolicy));
+ assertTrue(policySetTable.get(secureReliablePolicy).getProvidedIntents().size() == 2);
+ assertTrue(policySetTable.get(secureReliablePolicy).getPolicies().size() == 2);
+
+ assertNotNull(policySetTable.get(secureMessagingPolicies));
+ assertEquals(policySetTable.get(secureMessagingPolicies).getMappedPolicies().size(), 3);
+ //assertTrue(policySetTable.get(secureWsPolicy).getPolicies().get(0) instanceof org.apache.neethi.Policy);
+
+ assertEquals(bindingTypesTable.size(), 1);
+ assertNotNull(bindingTypesTable.get(wsBinding));
+ assertEquals(implTypesTable.size(), 1);
+ assertNotNull(implTypesTable.get(javaImpl));
+ }
+
+ public void testResolveSCADefinitions() throws Exception {
+ assertTrue(intentTable.get(messageProtection) instanceof ProfileIntent);
+ ProfileIntent profileIntent = (ProfileIntent)intentTable.get(new QName(namespace, "messageProtection"));
+ assertNull(profileIntent.getRequiredIntents().get(0).getDescription());
+
+ QName confidentiality_transport = new QName(namespace, "confidentiality.transport");
+ assertTrue(intentTable.get(confidentiality_transport) instanceof QualifiedIntent);
+ QualifiedIntent qualifiedIntent = (QualifiedIntent)intentTable.get(new QName(namespace, "confidentiality.transport"));
+ assertNull(qualifiedIntent.getQualifiableIntent().getDescription());
+
+ PolicySet secureReliablePolicySet = policySetTable.get(secureReliablePolicy);
+ PolicySet secureMessagingPolicySet = policySetTable.get(secureMessagingPolicies);
+ PolicySet securityPolicySet = policySetTable.get(securityPolicy);
+
+ assertEquals(secureReliablePolicySet.getProvidedIntents().get(1).getName(), integrity);
+ assertNull(secureReliablePolicySet.getProvidedIntents().get(1).getDescription());
+ assertTrue(secureMessagingPolicySet.isUnresolved());
+ assertEquals(securityPolicySet.getMappedPolicies().size(), 5);
+
+ //testing to ensure that inclusion of referred policy sets has not happened
+ PolicySet basicAuthMsgProtSecurityPolicySet = policySetTable.get(basicAuthMsgProtSecurity);
+ assertTrue(basicAuthMsgProtSecurityPolicySet.getPolicies().isEmpty());
+ assertTrue(basicAuthMsgProtSecurityPolicySet.getMappedPolicies().isEmpty());
+
+ IntentAttachPointType wsBindingType = bindingTypesTable.get(wsBinding);
+ assertNull(wsBindingType.getAlwaysProvidedIntents().get(0).getDescription());
+ assertNull(wsBindingType.getMayProvideIntents().get(0).getDescription());
+
+ IntentAttachPointType javaImplType = implTypesTable.get(javaImpl);
+ assertNull(javaImplType.getAlwaysProvidedIntents().get(0).getDescription());
+ assertNull(javaImplType.getMayProvideIntents().get(0).getDescription());
+
+ ModelResolver resolver = new DefaultModelResolver();
+ policyDefinitionsProcessor.resolve(definitions, resolver);
+ //builder.build(scaDefinitions);
+
+ //testing if policy intents have been linked have property been linked up
+ assertNotNull(profileIntent.getRequiredIntents().get(0).getDescription());
+ assertNotNull(qualifiedIntent.getQualifiableIntent().getDescription());
+ assertEquals(secureReliablePolicySet.getProvidedIntents().get(1).getName(), integrity);
+ assertNotNull(secureReliablePolicySet.getProvidedIntents().get(1).getDescription());
+
+ //testing if policysets have been properly linked up with intents
+ assertFalse(secureMessagingPolicySet.isUnresolved());
+ assertNotNull(secureMessagingPolicySet.getMappedPolicies().get(intentTable.get(confidentiality)));
+ assertNotNull(secureMessagingPolicySet.getMappedPolicies().get(intentTable.get(confidentiality_transport)));
+
+ //testing if intent maps have been properly mapped to policies
+ assertFalse(securityPolicySet.isUnresolved());
+ assertNotNull(securityPolicySet.getMappedPolicies().get(intentTable.get(confidentiality)));
+ assertNotNull(securityPolicySet.getMappedPolicies().get(intentTable.get(confidentiality_message)));
+
+ //testing for inclusion of referred policysets
+ assertFalse(basicAuthMsgProtSecurityPolicySet.getPolicies().isEmpty());
+ assertFalse(basicAuthMsgProtSecurityPolicySet.getMappedPolicies().isEmpty());
+ assertNotNull(basicAuthMsgProtSecurityPolicySet.getMappedPolicies().get(intentTable.get(confidentiality_transport)));
+
+ assertNotNull(wsBindingType.getAlwaysProvidedIntents().get(0).getDescription());
+ assertNotNull(wsBindingType.getMayProvideIntents().get(0).getDescription());
+
+ assertNotNull(javaImplType.getAlwaysProvidedIntents().get(0).getDescription());
+ assertNotNull(javaImplType.getMayProvideIntents().get(0).getDescription());
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/test/java/org/apache/tuscany/sca/definitions/TestPolicyProcessor.java b/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/test/java/org/apache/tuscany/sca/definitions/TestPolicyProcessor.java
new file mode 100644
index 0000000000..b4d7a8c584
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/test/java/org/apache/tuscany/sca/definitions/TestPolicyProcessor.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.definitions;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.policy.Policy;
+
+/**
+ * A PolicyProcessor used for testing.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestPolicyProcessor implements StAXArtifactProcessor<Policy> {
+
+ public QName getArtifactType() {
+ return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment");
+ }
+
+ public Policy read(XMLStreamReader arg0) throws ContributionReadException, XMLStreamException {
+ return new MockPolicyImplOne();
+ }
+
+ public void write(Policy arg0, XMLStreamWriter arg1) throws ContributionWriteException,
+ XMLStreamException {
+ }
+
+ public Class<Policy> getModelType() {
+ // TODO Auto-generated method stub
+ return Policy.class;
+ }
+
+ public void resolve(Policy arg0, ModelResolver arg1) throws ContributionResolveException {
+
+ }
+
+
+ public class MockPolicyImplOne implements Policy {
+ public QName getSchemaName() {
+ return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment");
+ }
+
+ public boolean isUnresolved() {
+ return false;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ }
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/test/resources/org/apache/tuscany/sca/definitions/test_definitions.xml b/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/test/resources/org/apache/tuscany/sca/definitions/test_definitions.xml
new file mode 100644
index 0000000000..f60047e769
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/definitions-xml/src/test/resources/org/apache/tuscany/sca/definitions/test_definitions.xml
@@ -0,0 +1,255 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT 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 xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ targetNamespace="http://test"
+ xmlns:test="http://test"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0">
+
+<!-- Extension Types Metadata -->
+<implementationType type="sca:implementation.java" alwaysProvides="test:logging"
+ mayProvide="test:tracing"/>
+<bindingType type="sca:binding.ws" alwaysProvides="test:confidentiality"
+ mayProvide="test:integrity"/>
+
+<!-- Intents and Policysets to assume targetnamespace -->
+<intent name="TestIntentOne"
+ constrains="sca:binding">
+ <description>
+ Test Intent
+ </description>
+ </intent>
+
+ <intent name="TestIntentTwo"
+ constrains="sca:binding"
+ requires="test:TestIntentOne">
+ <description>
+ Protect messages from unauthorized reading or modification
+ </description>
+ </intent>
+
+ <policySet name="TestPolicySetOne"
+ provides="test:TestIntentOne"
+ appliesTo="sca:binding.ws"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for
+ "basic authentication" -->
+ </wsp:PolicyAttachment>
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for
+ "reliability" -->
+ </wsp:PolicyAttachment>
+ </policySet>
+
+
+ <!-- qualified intents -->
+ <intent name="confidentiality.transport" />
+ <intent name="confidentiality.message" />
+ <intent name="confidentiality.message.whole" />
+ <intent name="confidentiality.message.body" />
+
+ <!-- POLICY SETS -->
+ <policySet name="SecureReliablePolicy"
+ provides="test:confidentiality.transport test:integrity"
+ appliesTo="sca:binding.ws"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for
+ "basic authentication" -->
+ </wsp:PolicyAttachment>
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for
+ "reliability" -->
+ </wsp:PolicyAttachment>
+ </policySet>
+
+ <policySet name="SecureMessagingPolicies"
+ provides="test:confidentiality"
+ appliesTo="binding.ws"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <intentMap provides="test:confidentiality" default="transport">
+ <qualifier name="transport">
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for "transport" alternative -->
+ </wsp:PolicyAttachment>
+ <wsp:PolicyAttachment>...</wsp:PolicyAttachment>
+ </qualifier>
+ <qualifier name="message">
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for "message" alternative" -->
+ </wsp:PolicyAttachment>
+ </qualifier>
+ </intentMap>
+</policySet>
+
+<policySet name="SecurityPolicy"
+ provides="test:confidentiality"
+ appliesTo="binding.ws"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" >
+ <intentMap provides="test:confidentiality" default="message">
+ <qualifier name="message">
+ <intentMap provides="message" default="whole">
+ <qualifier name="body">
+ <wsp:PolicyAttachment>
+ <!-- policy attachment for body encryption -->
+ </wsp:PolicyAttachment>
+ </qualifier>
+ <qualifier name="whole">
+ <wsp:PolicyAttachment>
+ <!-- policy attachment for whole message encryption -->
+ </wsp:PolicyAttachment>
+ </qualifier>
+ </intentMap>
+ </qualifier>
+ <qualifier name="transport">
+ <wsp:PolicyAttachment>
+ <!-- policy attachment for transport encryption -->
+ </wsp:PolicyAttachment>
+ </qualifier>
+ </intentMap>
+</policySet>
+
+<policySet name="BasicAuthMsgProtSecurity"
+ provides="test:authentication test:confidentiality"
+ appliesTo="binding.ws"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0">
+ <policySetReference name="test:AuthenticationPolicies"/>
+ <policySetReference name="test:ConfidentialityPolicies"/>
+</policySet>
+
+<policySet name="AuthenticationPolicies"
+ provides="test:authentication"
+ appliesTo="binding.ws"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for "basic
+ authentication" -->
+ </wsp:PolicyAttachment>
+</policySet>
+
+<policySet name="ConfidentialityPolicies"
+ provides="test:confidentiality"
+ appliesTo="binding.ws"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <intentMap provides="test:confidentiality" default="transport">
+ <qualifier name="transport">
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for "transport"
+ alternative -->
+ </wsp:PolicyAttachment>
+ <wsp:PolicyAttachment>...</wsp:PolicyAttachment>
+ </qualifier>
+ <qualifier name="message">
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for "message"
+ alternative" -->...
+ </wsp:PolicyAttachment>
+ </qualifier>
+ </intentMap>
+</policySet>
+
+<policySet name="SecureWSPolicy"
+ provides="test:confidentiality"
+ appliesTo="sca:binding.ws"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:sp="http://schemas.xmlsoap.org/ws/2002/12/secext"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <wsp:Policy>
+ <wsp:ExactlyOne>
+ <wsp:All>
+ <sp:SecurityToken>
+ <sp:TokenType>sp:X509v3</sp:TokenType>
+ </sp:SecurityToken>
+ <sp:UsernameToken />
+ <sp:SignedParts />
+ <sp:EncryptedParts>
+ <sp:Body />
+ </sp:EncryptedParts>
+ <sp:TransportBinding>
+ <sp:IncludeTimeStamp />
+ </sp:TransportBinding>
+ </wsp:All>
+ </wsp:ExactlyOne>
+ </wsp:Policy>
+ </policySet>
+
+<!-- profile intent -->
+ <intent name="reliableMessageProtection"
+ constrains="sca:binding"
+ requires="test:messageProtection">
+ <description>
+ Protect messages from unauthorized reading or modification
+ </description>
+ </intent>
+
+ <intent name="messageProtection"
+ constrains="sca:binding"
+ requires="test:confidentiality test:integrity">
+ <description>
+ Protect messages from unauthorized reading or modification
+ </description>
+ </intent>
+
+<!-- simple intent -->
+ <intent name="confidentiality"
+ constrains="sca:binding">
+ <description>
+ Communitcation thro this binding must prevent
+ unauthorized users from reading the messages.
+ </description>
+ </intent>
+
+ <intent name="integrity"
+ constrains="sca:binding">
+ <description>
+ Communitcation thro this binding must prevent
+ unauthorized modification of the messages.
+ </description>
+ </intent>
+
+ <intent name="authentication"
+ constrains="sca:binding">
+ <description>
+ Communitcation thro this binding required
+ Authentication.
+ </description>
+ </intent>
+
+ <intent name="logging"
+ constrains="sca:implementation">
+ <description>
+ All messages to and from this implementation must be logged
+ </description>
+ </intent>
+
+ <intent name="tracing"
+ constrains="sca:implementation.java">
+ <description>
+ Need to figure out some description for this
+ </description>
+ </intent>
+
+</definitions> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/definitions/LICENSE b/sca-java-1.x/branches/sca-android/modules/definitions/LICENSE
new file mode 100644
index 0000000000..6e529a25c4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/definitions/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/definitions/META-INF/README b/sca-java-1.x/branches/sca-android/modules/definitions/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/definitions/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/definitions/NOTICE b/sca-java-1.x/branches/sca-android/modules/definitions/NOTICE
new file mode 100644
index 0000000000..1325efd8bf
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/definitions/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/definitions/pom.xml b/sca-java-1.x/branches/sca-android/modules/definitions/pom.xml
new file mode 100644
index 0000000000..8e6d0cfebb
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/definitions/pom.xml
@@ -0,0 +1,70 @@
+<?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.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-definitions</artifactId>
+ <name>Apache Tuscany SCA Definitions</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-extensibility</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-policy</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly-xsd</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.definitions</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.definitions*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitions.java b/sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitions.java
new file mode 100644
index 0000000000..2039b9ecc9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitions.java
@@ -0,0 +1,82 @@
+ /*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.definitions;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicySet;
+
+
+/**
+ * Represents SCA Definitions.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface SCADefinitions {
+ /**
+ * Returns the target namespace for this SCA Definition
+ * @return the target namespace
+ */
+ String getTargetNamespace();
+
+ /**
+ * Sets the target names for this SCA Definition.
+ *
+ * @param ns the target namespace for this SCA Definition
+ */
+ void setTargetNamespace(String ns);
+
+ /**
+ * Returns a list of domain wide Policy Intents
+ *
+ * @return a list of domain wide Policy Intents
+ */
+ List<Intent> getPolicyIntents();
+
+ /**
+ * Returns a list of domain wide PolicySets
+ *
+ * @return a list of domain wide PolicySets
+ */
+ List<PolicySet> getPolicySets();
+
+ /**
+ * Returns a list of domain wide Binding Types
+ *
+ * @return a list of domain wide Binding Types
+ */
+ List<IntentAttachPointType> getBindingTypes();
+
+
+ /**
+ * Returns a list of domain wide Implementation Types
+ *
+ * @return a list of domain wide Implementation Types
+ */
+ List<IntentAttachPointType> getImplementationTypes();
+
+ /**
+ * Returns a list of domain wide binding definition objects
+ *
+ * @return a list of domain wide binding definition objects
+ */
+ List<Object> getBindings();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitionsBuilder.java b/sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitionsBuilder.java
new file mode 100644
index 0000000000..a41d7a6717
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitionsBuilder.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.definitions;
+
+
+/**
+ * Interface to abstract building of SCA Definitions for a Domain
+ *
+ * @version $Rev$ $Date$
+ */
+public interface SCADefinitionsBuilder {
+ /**
+ * Builds the SCA definitions
+ *
+ * @param scaDefns
+ */
+ void build(SCADefinitions scaDefns) throws SCADefinitionsBuilderException;
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitionsBuilderException.java b/sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitionsBuilderException.java
new file mode 100644
index 0000000000..85b9ad7f7d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitionsBuilderException.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.definitions;
+
+/**
+ * Builder Exception
+ *
+ * @version $Rev$ $Date$
+ */
+public class SCADefinitionsBuilderException extends Exception {
+ private static final long serialVersionUID = 2513219325230252783L;
+
+ public SCADefinitionsBuilderException() {
+ }
+
+ public SCADefinitionsBuilderException(String message) {
+ super(message);
+ }
+
+ public SCADefinitionsBuilderException(Throwable cause) {
+ super(cause);
+ }
+
+ public SCADefinitionsBuilderException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitionsBuilderImpl.java b/sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitionsBuilderImpl.java
new file mode 100644
index 0000000000..8b9ff3e1a9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/SCADefinitionsBuilderImpl.java
@@ -0,0 +1,309 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.definitions;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.ProfileIntent;
+import org.apache.tuscany.sca.policy.QualifiedIntent;
+
+/**
+ * Provides a concrete implementation for a SCADefinitionsBuilder
+ *
+ * @version $Rev$ $Date$
+ */
+public class SCADefinitionsBuilderImpl implements SCADefinitionsBuilder {
+
+ public void build(SCADefinitions scaDefns) throws SCADefinitionsBuilderException {
+ Map<QName, Intent> definedIntents = new HashMap<QName, Intent>();
+ for (Intent intent : scaDefns.getPolicyIntents()) {
+ definedIntents.put(intent.getName(), intent);
+ }
+
+ Map<QName, PolicySet> definedPolicySets = new HashMap<QName, PolicySet>();
+ for (PolicySet policySet : scaDefns.getPolicySets()) {
+ definedPolicySets.put(policySet.getName(), policySet);
+ }
+
+ Map<QName, IntentAttachPointType> definedBindingTypes = new HashMap<QName, IntentAttachPointType>();
+ for (IntentAttachPointType bindingType : scaDefns.getBindingTypes()) {
+ definedBindingTypes.put(bindingType.getName(), bindingType);
+ }
+
+ Map<QName, IntentAttachPointType> definedImplTypes = new HashMap<QName, IntentAttachPointType>();
+ for (IntentAttachPointType implType : scaDefns.getImplementationTypes()) {
+ definedImplTypes.put(implType.getName(), implType);
+ }
+
+ //filling up the maps removes all duplicate entries... so fill this unique lists
+ //into the scaDefns.
+ scaDefns.getPolicyIntents().clear();
+ scaDefns.getPolicySets().clear();
+ scaDefns.getBindingTypes().clear();
+ scaDefns.getImplementationTypes().clear();
+
+ scaDefns.getPolicyIntents().addAll(definedIntents.values());
+ scaDefns.getPolicySets().addAll(definedPolicySets.values());
+ scaDefns.getBindingTypes().addAll(definedBindingTypes.values());
+ scaDefns.getImplementationTypes().addAll(definedImplTypes.values());
+
+ buildPolicyIntents(scaDefns, definedIntents);
+ buildPolicySets(scaDefns, definedPolicySets, definedIntents);
+ buildBindingTypes(scaDefns, definedBindingTypes, definedIntents);
+ buildImplementationTypes(scaDefns, definedImplTypes, definedIntents);
+ }
+
+ private void buildBindingTypes(SCADefinitions scaDefns,
+ Map<QName, IntentAttachPointType> definedBindingTypes,
+ Map<QName, Intent> definedIntents) throws SCADefinitionsBuilderException {
+ for (IntentAttachPointType bindingType : scaDefns.getBindingTypes()) {
+ buildAlwaysProvidedIntents(bindingType, definedIntents);
+ buildMayProvideIntents(bindingType, definedIntents);
+ }
+
+ }
+
+ private void buildImplementationTypes(SCADefinitions scaDefns,
+ Map<QName, IntentAttachPointType> definedImplTypes,
+ Map<QName, Intent> definedIntents) throws SCADefinitionsBuilderException {
+ for (IntentAttachPointType implType : scaDefns.getImplementationTypes()) {
+ buildAlwaysProvidedIntents(implType, definedIntents);
+ buildMayProvideIntents(implType, definedIntents);
+ }
+ }
+
+
+ private void buildPolicyIntents(SCADefinitions scaDefns, Map<QName, Intent> definedIntents)
+ throws SCADefinitionsBuilderException {
+ for (Intent policyIntent : scaDefns.getPolicyIntents()) {
+ if (policyIntent instanceof ProfileIntent) {
+ buildProfileIntent((ProfileIntent)policyIntent, definedIntents);
+ }
+
+ if (policyIntent instanceof QualifiedIntent) {
+ buildQualifiedIntent((QualifiedIntent)policyIntent, definedIntents);
+ }
+ }
+ }
+
+ private void buildPolicySets(SCADefinitions scaDefns,
+ Map<QName, PolicySet> definedPolicySets,
+ Map<QName, Intent> definedIntents) throws SCADefinitionsBuilderException {
+
+ for (PolicySet policySet : scaDefns.getPolicySets()) {
+ buildProvidedIntents(policySet, definedIntents);
+ buildIntentsInMappedPolicies(policySet, definedIntents);
+ buildReferredPolicySets(policySet, definedPolicySets);
+ }
+
+ for (PolicySet policySet : scaDefns.getPolicySets()) {
+ for (PolicySet referredPolicySet : policySet.getReferencedPolicySets()) {
+ includeReferredPolicySets(policySet, referredPolicySet);
+ }
+ }
+ }
+
+ private void buildProfileIntent(ProfileIntent policyIntent, Map<QName, Intent> definedIntents)
+ throws SCADefinitionsBuilderException {
+ //FIXME: Need to check for cyclic references first i.e an A requiring B and then B requiring A...
+ if (policyIntent != null) {
+ //resolve all required intents
+ List<Intent> requiredIntents = new ArrayList<Intent>();
+ for (Intent requiredIntent : policyIntent.getRequiredIntents()) {
+ if (requiredIntent.isUnresolved()) {
+ Intent resolvedRequiredIntent = definedIntents.get(requiredIntent.getName());
+ if (resolvedRequiredIntent != null) {
+ requiredIntents.add(resolvedRequiredIntent);
+ } else {
+ throw new SCADefinitionsBuilderException("Required Intent - " + requiredIntent
+ + " not found for ProfileIntent "
+ + policyIntent);
+
+ }
+ } else {
+ requiredIntents.add(requiredIntent);
+ }
+ }
+ policyIntent.getRequiredIntents().clear();
+ policyIntent.getRequiredIntents().addAll(requiredIntents);
+ }
+ }
+
+ private void buildQualifiedIntent(QualifiedIntent policyIntent, Map<QName, Intent> definedIntents)
+ throws SCADefinitionsBuilderException {
+ if (policyIntent != null) {
+ //resolve the qualifiable intent
+ Intent qualifiableIntent = policyIntent.getQualifiableIntent();
+ if (qualifiableIntent.isUnresolved()) {
+ Intent resolvedQualifiableIntent = definedIntents.get(qualifiableIntent.getName());
+
+ if (resolvedQualifiableIntent != null) {
+ policyIntent.setQualifiableIntent(resolvedQualifiableIntent);
+ } else {
+ throw new SCADefinitionsBuilderException("Qualifiable Intent - " + qualifiableIntent
+ + " not found for QualifiedIntent "
+ + policyIntent);
+ }
+
+ }
+ }
+ }
+
+
+ private void buildAlwaysProvidedIntents(IntentAttachPointType extensionType,
+ Map<QName, Intent> definedIntents) throws SCADefinitionsBuilderException {
+ if (extensionType != null) {
+ // resolve all provided intents
+ List<Intent> alwaysProvided = new ArrayList<Intent>();
+ for (Intent providedIntent : extensionType.getAlwaysProvidedIntents()) {
+ if (providedIntent.isUnresolved()) {
+ Intent resolvedProvidedIntent = definedIntents.get(providedIntent.getName());
+ if (resolvedProvidedIntent != null) {
+ alwaysProvided.add(resolvedProvidedIntent);
+ } else {
+ throw new SCADefinitionsBuilderException(
+ "Always Provided Intent - " + providedIntent
+ + " not found for ExtensionType "
+ + extensionType);
+
+ }
+ } else {
+ alwaysProvided.add(providedIntent);
+ }
+ }
+ extensionType.getAlwaysProvidedIntents().clear();
+ extensionType.getAlwaysProvidedIntents().addAll(alwaysProvided);
+ }
+ }
+
+ private void buildMayProvideIntents(IntentAttachPointType extensionType,
+ Map<QName, Intent> definedIntents) throws SCADefinitionsBuilderException {
+ if (extensionType != null) {
+ // resolve all provided intents
+ List<Intent> mayProvide = new ArrayList<Intent>();
+ for (Intent providedIntent : extensionType.getMayProvideIntents()) {
+ if (providedIntent.isUnresolved()) {
+ Intent resolvedProvidedIntent = definedIntents.get(providedIntent.getName());
+ if (resolvedProvidedIntent != null) {
+ mayProvide.add(resolvedProvidedIntent);
+ } else {
+ throw new SCADefinitionsBuilderException(
+ "May Provide Intent - " + providedIntent
+ + " not found for ExtensionType "
+ + extensionType);
+
+ }
+ } else {
+ mayProvide.add(providedIntent);
+ }
+ }
+ extensionType.getMayProvideIntents().clear();
+ extensionType.getMayProvideIntents().addAll(mayProvide);
+ }
+ }
+
+ private void buildProvidedIntents(PolicySet policySet, Map<QName, Intent> definedIntents)
+ throws SCADefinitionsBuilderException {
+ if (policySet != null) {
+ //resolve all provided intents
+ List<Intent> providedIntents = new ArrayList<Intent>();
+ for (Intent providedIntent : policySet.getProvidedIntents()) {
+ if (providedIntent.isUnresolved()) {
+ Intent resolvedProvidedIntent = definedIntents.get(providedIntent.getName());
+ if (resolvedProvidedIntent != null) {
+ providedIntents.add(resolvedProvidedIntent);
+ } else {
+ throw new SCADefinitionsBuilderException("Provided Intent - " + providedIntent
+ + " not found for PolicySet "
+ + policySet);
+
+ }
+ } else {
+ providedIntents.add(providedIntent);
+ }
+ }
+ policySet.getProvidedIntents().clear();
+ policySet.getProvidedIntents().addAll(providedIntents);
+ }
+ }
+
+ private void buildIntentsInMappedPolicies(PolicySet policySet, Map<QName, Intent> definedIntents)
+ throws SCADefinitionsBuilderException {
+ Map<Intent, List<Object>> mappedPolicies = new Hashtable<Intent, List<Object>>();
+ for (Map.Entry<Intent, List<Object>> entry : policySet.getMappedPolicies().entrySet()) {
+ Intent mappedIntent = entry.getKey();
+ if (mappedIntent.isUnresolved()) {
+ Intent resolvedMappedIntent = definedIntents.get(mappedIntent.getName());
+
+ if (resolvedMappedIntent != null) {
+ mappedPolicies.put(resolvedMappedIntent, entry.getValue());
+ } else {
+ throw new SCADefinitionsBuilderException("Mapped Intent - " + mappedIntent
+ + " not found for PolicySet "
+ + policySet);
+
+ }
+ } else {
+ mappedPolicies.put(mappedIntent, entry.getValue());
+ }
+ }
+
+ policySet.getMappedPolicies().clear();
+ policySet.getMappedPolicies().putAll(mappedPolicies);
+ }
+
+ private void buildReferredPolicySets(PolicySet policySet, Map<QName, PolicySet> definedPolicySets)
+ throws SCADefinitionsBuilderException {
+
+ List<PolicySet> referredPolicySets = new ArrayList<PolicySet>();
+ for (PolicySet referredPolicySet : policySet.getReferencedPolicySets()) {
+ if (referredPolicySet.isUnresolved()) {
+ PolicySet resolvedReferredPolicySet = definedPolicySets.get(referredPolicySet.getName());
+ if (resolvedReferredPolicySet != null) {
+ referredPolicySets.add(resolvedReferredPolicySet);
+ } else {
+ throw new SCADefinitionsBuilderException("Referred PolicySet - " + referredPolicySet
+ + "not found for PolicySet - "
+ + policySet);
+ }
+ } else {
+ referredPolicySets.add(referredPolicySet);
+ }
+ }
+ policySet.getReferencedPolicySets().clear();
+ policySet.getReferencedPolicySets().addAll(referredPolicySets);
+ }
+
+ private void includeReferredPolicySets(PolicySet policySet, PolicySet referredPolicySet) {
+ for (PolicySet furtherReferredPolicySet : referredPolicySet.getReferencedPolicySets()) {
+ includeReferredPolicySets(referredPolicySet, furtherReferredPolicySet);
+ }
+ policySet.getPolicies().addAll(referredPolicySet.getPolicies());
+ policySet.getMappedPolicies().putAll(referredPolicySet.getMappedPolicies());
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/impl/SCADefinitionsImpl.java b/sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/impl/SCADefinitionsImpl.java
new file mode 100644
index 0000000000..a5178497a0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/impl/SCADefinitionsImpl.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.definitions.impl;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicySet;
+
+/**
+ * Provides a concrete implementation for SCADefinitions
+ *
+ * @version $Rev$ $Date$
+ */
+public class SCADefinitionsImpl implements SCADefinitions {
+ private String targetNamespace = null;
+ private List<Intent> policyIntents = new CopyOnWriteArrayList<Intent>();
+ private List<PolicySet> policySets = new CopyOnWriteArrayList<PolicySet>();
+ private List<IntentAttachPointType> bindingTypes = new CopyOnWriteArrayList<IntentAttachPointType>();
+ private List<IntentAttachPointType> implementationTypes = new CopyOnWriteArrayList<IntentAttachPointType>();
+ private List<Object> bindings = new CopyOnWriteArrayList<Object>();
+
+
+ public List<IntentAttachPointType> getBindingTypes() {
+ return bindingTypes;
+ }
+
+ public List<IntentAttachPointType> getImplementationTypes() {
+ return implementationTypes;
+ }
+
+ public List<Intent> getPolicyIntents() {
+ return policyIntents;
+ }
+
+ public List<PolicySet> getPolicySets() {
+ return policySets;
+ }
+
+ public String getTargetNamespace() {
+ return targetNamespace;
+ }
+
+ public void setTargetNamespace(String ns) {
+ this.targetNamespace = ns;
+ }
+
+ public List<Object> getBindings() {
+ return bindings;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/util/SCADefinitionsUtil.java b/sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/util/SCADefinitionsUtil.java
new file mode 100644
index 0000000000..8de6f63c05
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/definitions/src/main/java/org/apache/tuscany/sca/definitions/util/SCADefinitionsUtil.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.definitions.util;
+
+import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicySet;
+
+/**
+ * Some utility functions to deal with SCADefinitions
+ *
+ * @version $Rev$ $Date$
+ */
+public class SCADefinitionsUtil {
+
+ public static void stripDuplicates(SCADefinitions scaDefns) {
+ Map<QName, Intent> definedIntents = new HashMap<QName, Intent>();
+ for (Intent intent : scaDefns.getPolicyIntents()) {
+ definedIntents.put(intent.getName(), intent);
+ }
+
+ Map<QName, PolicySet> definedPolicySets = new HashMap<QName, PolicySet>();
+ for (PolicySet policySet : scaDefns.getPolicySets()) {
+ definedPolicySets.put(policySet.getName(), policySet);
+ }
+
+ Map<QName, IntentAttachPointType> definedBindingTypes = new HashMap<QName, IntentAttachPointType>();
+ for (IntentAttachPointType bindingType : scaDefns.getBindingTypes()) {
+ definedBindingTypes.put(bindingType.getName(), bindingType);
+ }
+
+ Map<QName, IntentAttachPointType> definedImplTypes = new HashMap<QName, IntentAttachPointType>();
+ for (IntentAttachPointType implType : scaDefns.getImplementationTypes()) {
+ definedImplTypes.put(implType.getName(), implType);
+ }
+
+ scaDefns.getPolicyIntents().clear();
+ scaDefns.getPolicyIntents().addAll(definedIntents.values());
+ scaDefns.getPolicySets().clear();
+ scaDefns.getPolicySets().addAll(definedPolicySets.values());
+ scaDefns.getBindingTypes().clear();
+ scaDefns.getBindingTypes().addAll(definedBindingTypes.values());
+ scaDefns.getImplementationTypes().clear();
+ scaDefns.getImplementationTypes().addAll(definedImplTypes.values());
+ }
+
+ public static void aggregateSCADefinitions(SCADefinitions source, SCADefinitions target) {
+ target.getPolicyIntents().addAll(source.getPolicyIntents());
+ target.getPolicySets().addAll(source.getPolicySets());
+ target.getBindingTypes().addAll(source.getBindingTypes());
+ target.getImplementationTypes().addAll(source.getImplementationTypes());
+ target.getBindings().addAll(source.getBindings());
+ }
+
+ public static boolean isSCADefnsFile(URI uri) {
+ int index = uri.toString().lastIndexOf("/");
+
+ index = (index != -1) ? index + 1 : 0;
+
+ return uri.toString().substring(index).equals("definitions.xml");
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/endpoint/LICENSE b/sca-java-1.x/branches/sca-android/modules/endpoint/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/endpoint/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/endpoint/META-INF/README b/sca-java-1.x/branches/sca-android/modules/endpoint/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/endpoint/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/endpoint/NOTICE b/sca-java-1.x/branches/sca-android/modules/endpoint/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/endpoint/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/endpoint/pom.xml b/sca-java-1.x/branches/sca-android/modules/endpoint/pom.xml
new file mode 100644
index 0000000000..31e8adc800
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/endpoint/pom.xml
@@ -0,0 +1,122 @@
+<?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.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>tuscany-endpoint</artifactId>
+ <name>Apache Tuscany SCA Default Endpoint Implementation</name>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core-spi</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-binding-sca</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-workspace-impl</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-implementation-java-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-interface-java-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-monitor-logging</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>2.2</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.endpoint</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.endpoint*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointResolverFactoryImpl.java b/sca-java-1.x/branches/sca-android/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointResolverFactoryImpl.java
new file mode 100644
index 0000000000..f0646e934e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointResolverFactoryImpl.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.endpoint.impl;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.endpointresolver.EndpointResolver;
+import org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory;
+
+/**
+ * The factory for creating endpoint Binding providers
+ *
+ * @version $Rev$ $Date$
+ */
+public class EndpointResolverFactoryImpl implements EndpointResolverFactory<Endpoint> {
+
+ private ExtensionPointRegistry extensionPoints;
+
+ public EndpointResolverFactoryImpl(ExtensionPointRegistry extensionPoints) {
+ this.extensionPoints = extensionPoints;
+ }
+
+ public EndpointResolver createEndpointResolver(Endpoint endpoint, Binding binding) {
+
+ return new EndpointResolverImpl(extensionPoints, endpoint);
+ }
+
+ public Class<Endpoint> getModelType() {
+ return Endpoint.class;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointResolverImpl.java b/sca-java-1.x/branches/sca-android/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointResolverImpl.java
new file mode 100644
index 0000000000..b76c4b82f0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/endpoint/src/main/java/org/apache/tuscany/sca/endpoint/impl/EndpointResolverImpl.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.endpoint.impl;
+
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.endpointresolver.EndpointResolver;
+import org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory;
+import org.apache.tuscany.sca.endpointresolver.EndpointResolverFactoryExtensionPoint;
+
+
+/**
+ * The endpoint resolver allows unresolved endpoints to be plumbed into
+ * the runtime start and message send processing as a hook to late resolution
+ * of target services
+ *
+ * @version $Rev$ $Date$
+ */
+public class EndpointResolverImpl implements EndpointResolver {
+
+ private final static Logger logger = Logger.getLogger(EndpointResolverImpl.class.getName());
+
+ private Endpoint endpoint;
+ private List<EndpointResolver> endpointResolvers = new ArrayList<EndpointResolver>();
+
+ public EndpointResolverImpl(ExtensionPointRegistry extensionPoints,
+ Endpoint endpoint) {
+ this.endpoint = endpoint;
+
+ EndpointResolverFactoryExtensionPoint resolverFactories =
+ extensionPoints.getExtensionPoint(EndpointResolverFactoryExtensionPoint.class);
+
+ for (Binding binding : endpoint.getCandidateBindings()){
+ EndpointResolverFactory resolverFactory = resolverFactories.getEndpointResolverFactory(binding.getClass());
+
+ // if the binding in question has a endpoint resolver factory they try and
+ // create an endpoint resolver
+ if (resolverFactory != null){
+ EndpointResolver resolver = resolverFactory.createEndpointResolver(endpoint, binding);
+
+ if (resolver != null){
+ endpointResolvers.add(resolver);
+ }
+ }
+ }
+ }
+
+ public void start(){
+ // do nothing
+ }
+
+ public void stop(){
+ // do nothing
+ }
+
+ public void resolve() {
+ if (endpoint.isUnresolved()){
+ // Resolve the endpoint binding here
+
+ // first do any general resolution that's required
+
+ // ask the bindings to resolve the endpoint one by one
+ for (EndpointResolver resolver : endpointResolvers){
+ resolver.resolve();
+ if (endpoint.isUnresolved() != true){
+ break;
+ }
+ }
+
+ if (endpoint.isUnresolved()){
+ // TODO: TUSCANY-2580: if its still unresolved use the first candidate binding
+ endpoint.setSourceBinding(endpoint.getCandidateBindings().get(0));
+ endpoint.getSourceBinding().setURI(endpoint.getTargetName());
+ }
+
+ if (endpoint.isUnresolved() != true){
+ // If we have to build the endpoint because we are matching
+ // intents and policies then we do that now. If the binding
+ // is just configured by setting its uri we can just do local binding
+ // configuration here
+
+ // EndpointBuilderImpl.build(endpoint);
+ } else {
+ // raise an exception saying the endpoint can't be resolved
+ }
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/endpoint/src/main/resources/META-INF/services/org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory b/sca-java-1.x/branches/sca-android/modules/endpoint/src/main/resources/META-INF/services/org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory
new file mode 100644
index 0000000000..50e0a930d2
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/endpoint/src/main/resources/META-INF/services/org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for the binding extension
+org.apache.tuscany.sca.endpoint.impl.EndpointResolverFactoryImpl;model=org.apache.tuscany.sca.assembly.Endpoint
diff --git a/sca-java-1.x/branches/sca-android/modules/endpoint/src/main/resources/org/apache/tuscany/sca/binding/sca/definitions.xml b/sca-java-1.x/branches/sca-android/modules/endpoint/src/main/resources/org/apache/tuscany/sca/binding/sca/definitions.xml
new file mode 100644
index 0000000000..8bac9e01c9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/endpoint/src/main/resources/org/apache/tuscany/sca/binding/sca/definitions.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<sca:definitions xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ targetNamespace="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0">
+
+ <sca:bindingType type="sca:binding.sca" mayProvide="" alwaysProvides=""/>
+ </sca:definitions> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/AddService.java b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/AddService.java
new file mode 100644
index 0000000000..188451ebac
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/AddService.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 calculator;
+
+/**
+ * The Add service interface
+ */
+public interface AddService {
+
+ double add(double n1, double n2);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/AddServiceImpl.java b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/AddServiceImpl.java
new file mode 100644
index 0000000000..7ca8fb04b5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/AddServiceImpl.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * An implementation of the Add service
+ */
+public class AddServiceImpl implements AddService {
+
+ public double add(double n1, double n2) {
+ Logger logger = Logger.getLogger("calculator");
+ logger.log(Level.FINEST, "Adding " + n1 + " and " + n2);
+ return n1 + n2;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/CalculatorService.java b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/CalculatorService.java
new file mode 100644
index 0000000000..031fa8b912
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/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/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/CalculatorServiceImpl.java b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/CalculatorServiceImpl.java
new file mode 100644
index 0000000000..3d861f2018
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/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/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/DivideService.java b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/DivideService.java
new file mode 100644
index 0000000000..30d248208b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/DivideService.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 calculator;
+
+/**
+ * The divide service interface
+ */
+public interface DivideService {
+
+ double divide(double n1, double n2);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/DivideServiceImpl.java b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/DivideServiceImpl.java
new file mode 100644
index 0000000000..1323edf55a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/DivideServiceImpl.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * An implementation of the Divide service.
+ */
+public class DivideServiceImpl implements DivideService {
+
+ public double divide(double n1, double n2) {
+ Logger logger = Logger.getLogger("calculator");
+ logger.log(Level.FINEST, "Dividing " + n1 + " with " + n2);
+ return n1 / n2;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/MultiplyService.java b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/MultiplyService.java
new file mode 100644
index 0000000000..5290605938
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/MultiplyService.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 calculator;
+
+/**
+ * The interface for the multiply service
+ */
+public interface MultiplyService {
+
+ double multiply(double n1, double n2);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/MultiplyServiceImpl.java b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/MultiplyServiceImpl.java
new file mode 100644
index 0000000000..91b803bc9e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/MultiplyServiceImpl.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * An implementation of the Multiply service.
+ */
+public class MultiplyServiceImpl implements MultiplyService {
+
+ public double multiply(double n1, double n2) {
+ Logger logger = Logger.getLogger("calculator");
+ logger.log(Level.FINEST, "Multiplying " + n1 + " with " + n2);
+ return n1 * n2;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/SubtractService.java b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/SubtractService.java
new file mode 100644
index 0000000000..bf0d1882b6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/SubtractService.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 calculator;
+
+/**
+ * The interface for the multiply service
+ */
+public interface SubtractService {
+
+ double subtract(double n1, double n2);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/SubtractServiceImpl.java b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/SubtractServiceImpl.java
new file mode 100644
index 0000000000..58cc4a3547
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/calculator/SubtractServiceImpl.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * An implementation of the subtract service.
+ */
+public class SubtractServiceImpl implements SubtractService {
+
+ public double subtract(double n1, double n2) {
+ Logger logger = Logger.getLogger("calculator");
+ logger.log(Level.FINEST, "Subtracting " + n1 + " from " + n2);
+ return n1 - n2;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.java b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.java
new file mode 100644
index 0000000000..5a2d9babf4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/java/org/apace/tuscany/sca/binding/sca/EndpointTestCase.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.apace.tuscany.sca.binding.sca;
+
+
+import java.io.File;
+import java.net.URI;
+import java.net.URL;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Endpoint;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ExtensibleModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ModuleActivator;
+import org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.core.assembly.CompositeActivator;
+import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory;
+import org.apache.tuscany.sca.endpoint.impl.EndpointResolverFactoryImpl;
+import org.apache.tuscany.sca.endpointresolver.EndpointResolver;
+import org.apache.tuscany.sca.endpointresolver.EndpointResolverFactory;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * EndpointTestCase
+ *
+ * @version $Rev$ $Date$
+ */
+public class EndpointTestCase {
+
+ private static URLArtifactProcessor<Contribution> contributionProcessor;
+ private static ModelResolverExtensionPoint modelResolvers;
+ private static ModelFactoryExtensionPoint modelFactories;
+ private static AssemblyFactory assemblyFactory;
+ private static XMLOutputFactory outputFactory;
+ private static StAXArtifactProcessor<Object> xmlProcessor;
+ private static CompositeBuilder compositeBuilder;
+ private static ModelResolver modelResolver;
+ private static CompositeActivator compositeActivator;
+ private static ExtensionPointRegistry extensionPoints;
+
+ @BeforeClass
+ public static void init() {
+
+ // Create extension point registry
+ extensionPoints = new DefaultExtensionPointRegistry();
+
+ // Create a monitor
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
+ Monitor monitor = monitorFactory.createMonitor();
+
+ modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+
+ // Initialize the Tuscany module activators
+ ModuleActivatorExtensionPoint moduleActivators = extensionPoints.getExtensionPoint(ModuleActivatorExtensionPoint.class);
+ for (ModuleActivator activator: moduleActivators.getModuleActivators()) {
+ activator.start(extensionPoints);
+ }
+
+ // Get XML input/output factories
+
+ XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class);
+ outputFactory = modelFactories.getFactory(XMLOutputFactory.class);
+
+ // Get contribution workspace and assembly model factories
+ assemblyFactory = new RuntimeAssemblyFactory();
+ modelFactories.addFactory(assemblyFactory);
+
+ // Create XML artifact processors
+ StAXArtifactProcessorExtensionPoint xmlProcessorExtensions = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ xmlProcessor = new ExtensibleStAXArtifactProcessor(xmlProcessorExtensions, inputFactory, outputFactory, monitor);
+
+ // Create contribution content processor
+ URLArtifactProcessorExtensionPoint docProcessorExtensions = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ contributionProcessor = docProcessorExtensions.getProcessor(Contribution.class);
+
+ // Get the model resolvers
+ modelResolvers = extensionPoints.getExtensionPoint(ModelResolverExtensionPoint.class);
+ modelResolver = new ExtensibleModelResolver(null, modelResolvers, modelFactories);
+
+ // Create a composite builder
+ SCABindingFactory scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class);
+ IntentAttachPointTypeFactory attachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class);
+ InterfaceContractMapper contractMapper = utilities.getUtility(InterfaceContractMapper.class);
+ compositeBuilder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, attachPointTypeFactory, contractMapper, monitor);
+
+ // Runtime Init ===================
+/*
+ ContextFactoryExtensionPoint contextFactories = new DefaultContextFactoryExtensionPoint(extensionPoints);
+ extensionPoints.addExtensionPoint(contextFactories);
+
+ // Create a wire post processor extension point
+ RuntimeWireProcessorExtensionPoint wireProcessors =
+ extensionPoints.getExtensionPoint(RuntimeWireProcessorExtensionPoint.class);
+ RuntimeWireProcessor wireProcessor = new ExtensibleWireProcessor(wireProcessors);
+
+ JavaInterfaceFactory javaInterfaceFactory =
+ extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class).getFactory(JavaInterfaceFactory.class);
+ RequestContextFactory requestContextFactory =
+ extensionPoints.getExtensionPoint(ContextFactoryExtensionPoint.class).getFactory(RequestContextFactory.class);
+
+ ConversationManager conversationManager = new ConversationManagerImpl();
+ extensionPoints.addExtensionPoint(conversationManager);
+
+
+ ScopeRegistry scopeRegistry = new ScopeRegistryImpl();
+ ScopeContainerFactory[] factories =
+ new ScopeContainerFactory[] {new CompositeScopeContainerFactory(), new StatelessScopeContainerFactory(),
+ new RequestScopeContainerFactory(),
+ new ConversationalScopeContainerFactory(null),
+ // new HttpSessionScopeContainer(monitor)
+ };
+ for (ScopeContainerFactory f : factories) {
+ scopeRegistry.register(f);
+ }
+
+ compositeActivator =new CompositeActivatorImpl(assemblyFactory,
+ messageFactory,
+ javaInterfaceFactory,
+ scaBindingFactory,
+ mapper,
+ scopeRegistry,
+ extensionPoints.getExtensionPoint(WorkScheduler.class),
+ wireProcessor,
+ requestContextFactory,
+ new DefaultProxyFactoryExtensionPoint(messageFactory, mapper),
+ extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class),
+ extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class),
+ conversationManager);
+
+*/
+
+
+ }
+
+ @Test
+ public void testProvider(){
+ try {
+ URI calculatorURI = URI.create("calcualtor");
+ URL calculatorURL = new File("./target/test-classes").toURI().toURL();
+ Contribution contribution = contributionProcessor.read(null, calculatorURI, calculatorURL);
+
+ contributionProcessor.resolve(contribution, modelResolver);
+
+ Composite composite = contribution.getDeployables().get(0);
+
+ compositeBuilder.build(composite);
+
+ ComponentReference ref = (composite.getComponents().get(0).getReferences().get(0));
+
+ Assert.assertEquals(1, ref.getEndpoints().size());
+
+ Endpoint endpoint = ref.getEndpoints().get(0);
+
+ EndpointResolverFactory<Endpoint> factory = new EndpointResolverFactoryImpl(extensionPoints);
+
+ EndpointResolver endpointResolver = factory.createEndpointResolver(endpoint, null);
+
+ Assert.assertNotNull(endpointResolver);
+
+
+ } catch(Exception ex) {
+ ex.printStackTrace();
+ System.out.println(ex.toString());
+ Assert.fail();
+ }
+ }
+
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/resources/Calculator.composite b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/resources/Calculator.composite
new file mode 100644
index 0000000000..3b743f6e26
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/endpoint/src/test/resources/Calculator.composite
@@ -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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:calc="http://calc"
+ targetNamespace="http://calc"
+ name="Calculator">
+
+ <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="AddServiceComponentOff">
+ <implementation.java class="calculator.AddServiceImpl"/>
+ <service name="AddServiceImpl">
+ <interface.java interface="calculator.AddService"/>
+ </service>
+ </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> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/extensibility/LICENSE b/sca-java-1.x/branches/sca-android/modules/extensibility/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/extensibility/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/extensibility/META-INF/README b/sca-java-1.x/branches/sca-android/modules/extensibility/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/extensibility/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/extensibility/NOTICE b/sca-java-1.x/branches/sca-android/modules/extensibility/NOTICE
new file mode 100644
index 0000000000..b3e4797aaa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/extensibility/NOTICE
@@ -0,0 +1,5 @@
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/extensibility/pom.xml b/sca-java-1.x/branches/sca-android/modules/extensibility/pom.xml
new file mode 100644
index 0000000000..01cd2d0ca9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/extensibility/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>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-extensibility</artifactId>
+ <name>Apache Tuscany SCA Extensibility</name>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.extensibility</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java
new file mode 100644
index 0000000000..48f240559c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+
+/**
+ * Default implementation of a registry to hold all the Tuscany core extension
+ * points. As the point of contact for all extension artifacts this registry
+ * allows loaded extensions to find all other parts of the system and register
+ * themselves appropriately.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultExtensionPointRegistry implements ExtensionPointRegistry {
+ private Map<Class<?>, Object> extensionPoints = new HashMap<Class<?>, Object>();
+
+ /**
+ * Constructs a new registry.
+ */
+ public DefaultExtensionPointRegistry() {
+ }
+
+ /**
+ * Add an extension point to the registry. This default implementation
+ * stores extensions against the interfaces that they implement.
+ *
+ * @param extensionPoint The instance of the extension point
+ *
+ * @throws IllegalArgumentException if extensionPoint is null
+ */
+ public void addExtensionPoint(Object extensionPoint) {
+ if (extensionPoint == null) {
+ throw new IllegalArgumentException("Cannot register null as an ExtensionPoint");
+ }
+
+ Set<Class<?>> interfaces = getAllInterfaces(extensionPoint.getClass());
+ for (Class<?> i : interfaces) {
+ extensionPoints.put(i, extensionPoint);
+ }
+ }
+
+ private Constructor<?> getConstructor(Constructor<?>[] constructors, Class<?>[] paramTypes) {
+ for (Constructor<?> c : constructors) {
+ Class<?>[] types = c.getParameterTypes();
+ if (c.getParameterTypes().length == paramTypes.length) {
+ boolean found = true;
+ for (int i = 0; i < types.length; i++) {
+ if (types[i] != paramTypes[i]) {
+ found = false;
+ break;
+ }
+ }
+ if (found) {
+ return c;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Get the extension point by the interface that it implements
+ *
+ * @param extensionPointType The lookup key (extension point interface)
+ * @return The instance of the extension point
+ *
+ * @throws IllegalArgumentException if extensionPointType is null
+ */
+ public <T> T getExtensionPoint(Class<T> extensionPointType) {
+ if (extensionPointType == null) {
+ throw new IllegalArgumentException("Cannot lookup ExtensionPoint of type null");
+ }
+
+ Object extensionPoint = extensionPoints.get(extensionPointType);
+ if (extensionPoint == null) {
+
+ // Dynamically load an extension point class declared under META-INF/services
+ try {
+ Class<?> extensionPointClass =
+ ServiceDiscovery.getInstance().loadFirstServiceClass(extensionPointType);
+ if (extensionPointClass != null) {
+ // Construct the extension point
+ Constructor<?>[] constructors = extensionPointClass.getConstructors();
+ Constructor<?> constructor = getConstructor(constructors, new Class<?>[] {ExtensionPointRegistry.class});
+ if (constructor != null) {
+ extensionPoint = constructor.newInstance(this);
+ } else {
+ constructor = getConstructor(constructors, new Class<?>[] {});
+ if (constructor != null) {
+ extensionPoint = constructor.newInstance();
+ } else {
+ throw new IllegalArgumentException(
+ "No valid constructor is found for " + extensionPointClass);
+ }
+ }
+
+ // Cache the loaded extension point
+ addExtensionPoint(extensionPoint);
+ }
+ } catch (InvocationTargetException e) {
+ throw new IllegalArgumentException(e);
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e);
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException(e);
+ } catch (InstantiationException e) {
+ throw new IllegalArgumentException(e);
+ } catch (IllegalAccessException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+ return extensionPointType.cast(extensionPoint);
+ }
+
+ /**
+ * Remove an extension point based on the interface that it implements
+ *
+ * @param extensionPoint The extension point to remove
+ *
+ * @throws IllegalArgumentException if extensionPoint is null
+ */
+ public void removeExtensionPoint(Object extensionPoint) {
+ if (extensionPoint == null) {
+ throw new IllegalArgumentException("Cannot remove null as an ExtensionPoint");
+ }
+
+ Set<Class<?>> interfaces = getAllInterfaces(extensionPoint.getClass());
+ for (Class<?> i : interfaces) {
+ extensionPoints.remove(i);
+ }
+ }
+
+ /**
+ * Returns the set of interfaces implemented by the given class and its
+ * ancestors or a blank set if none
+ */
+ private static Set<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) {
+ if (Modifier.isPublic(interfaze.getModifiers())) {
+ implemented.add(interfaze);
+ }
+ }
+ Class<?> superClass = clazz.getSuperclass();
+ // Object has no superclass so check for null
+ if (superClass != null && !superClass.equals(Object.class)) {
+ getAllInterfaces(superClass, implemented);
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultModuleActivatorExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultModuleActivatorExtensionPoint.java
new file mode 100644
index 0000000000..8ca030c0dd
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultModuleActivatorExtensionPoint.java
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+
+/**
+ * Default implementation of an extension point to hold Tuscany module activators.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultModuleActivatorExtensionPoint implements ModuleActivatorExtensionPoint {
+ private List<ModuleActivator> activators = new ArrayList<ModuleActivator>();
+ private boolean loadedActivators;
+
+ /**
+ * Constructs a new extension point.
+ */
+ public DefaultModuleActivatorExtensionPoint() {
+ }
+
+ public void addModuleActivator(ModuleActivator activator) {
+ activators.add(activator);
+ }
+
+ public List<ModuleActivator> getModuleActivators() {
+ loadModuleActivators();
+ return activators;
+ }
+
+ public void removeModuleActivator(Object activator) {
+ activators.remove(activator);
+ }
+
+ /**
+ * Dynamically load module activators declared under META-INF/services
+ */
+ private void loadModuleActivators() {
+ if (loadedActivators)
+ return;
+
+ // Get the activator service declarations
+ Set<ServiceDeclaration> activatorDeclarations;
+ try {
+ activatorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(ModuleActivator.class);
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+
+ // Load and instantiate module activators
+ for (ServiceDeclaration activatorDeclaration: activatorDeclarations) {
+ ModuleActivator activator;
+ try {
+ Class<ModuleActivator> activatorClass = (Class<ModuleActivator>)activatorDeclaration.loadClass();
+ activator = activatorClass.newInstance();
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException(e);
+ } catch (InstantiationException e) {
+ throw new IllegalArgumentException(e);
+ } catch (IllegalAccessException e) {
+ throw new IllegalArgumentException(e);
+ }
+ addModuleActivator(activator);
+ }
+
+ loadedActivators = true;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultUtilityExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultUtilityExtensionPoint.java
new file mode 100644
index 0000000000..6f7c83c8d9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultUtilityExtensionPoint.java
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core;
+
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+
+/**
+ * Default implementation of an extension point to hold Tuscany utility utilities.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultUtilityExtensionPoint implements UtilityExtensionPoint {
+ private Map<Class<?>, Object> utilities = new HashMap<Class<?>, Object>();
+
+ private ExtensionPointRegistry extensionPoints;
+
+ /**
+ * Constructs a new extension point.
+ */
+ public DefaultUtilityExtensionPoint(ExtensionPointRegistry extensionPoints) {
+ this.extensionPoints = extensionPoints;
+ }
+
+ /**
+ * Add a utility to the extension point. This default implementation
+ * stores utilities against the interfaces that they implement.
+ *
+ * @param utility The instance of the utility
+ *
+ * @throws IllegalArgumentException if utility is null
+ */
+ public void addUtility(Object utility) {
+ if (utility == null) {
+ throw new IllegalArgumentException("Cannot register null as a Service");
+ }
+
+ Set<Class<?>> interfaces = getAllInterfaces(utility.getClass());
+ for (Class<?> i : interfaces) {
+ utilities.put(i, utility);
+ }
+ }
+
+ private Constructor<?> getConstructor(Constructor<?>[] constructors, Class<?>[] paramTypes) {
+ for (Constructor<?> c : constructors) {
+ Class<?>[] types = c.getParameterTypes();
+ if (c.getParameterTypes().length == paramTypes.length) {
+ boolean found = true;
+ for (int i = 0; i < types.length; i++) {
+ if (types[i] != paramTypes[i]) {
+ found = false;
+ break;
+ }
+ }
+ if (found) {
+ return c;
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Get the utility by the interface that it implements
+ *
+ * @param utilityType The lookup key (utility interface)
+ * @return The instance of the utility
+ *
+ * @throws IllegalArgumentException if utilityType is null
+ */
+ public <T> T getUtility(Class<T> utilityType) {
+ if (utilityType == null) {
+ throw new IllegalArgumentException("Cannot lookup Service of type null");
+ }
+
+ Object utility = utilities.get(utilityType);
+ if (utility == null) {
+
+ // Dynamically load a utility class declared under META-INF/utilities
+ try {
+ Class<?> utilityClass =
+ ServiceDiscovery.getInstance().loadFirstServiceClass(utilityType);
+ if (utilityClass != null) {
+ // Construct the utility
+ Constructor<?>[] constructors = utilityClass.getConstructors();
+ Constructor<?> constructor = getConstructor(constructors, new Class<?>[] {ExtensionPointRegistry.class});
+ if (constructor != null) {
+ utility = constructor.newInstance(extensionPoints);
+ } else {
+ constructor = getConstructor(constructors, new Class<?>[] {});
+ if (constructor != null) {
+ utility = constructor.newInstance();
+ } else {
+ throw new IllegalArgumentException(
+ "No valid constructor is found for " + utilityClass);
+ }
+ }
+
+ // Cache the loaded utility
+ addUtility(utility);
+ }
+ } catch (InvocationTargetException e) {
+ throw new IllegalArgumentException(e);
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e);
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException(e);
+ } catch (InstantiationException e) {
+ throw new IllegalArgumentException(e);
+ } catch (IllegalAccessException e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+ return utilityType.cast(utility);
+ }
+
+ /**
+ * Remove a utility based on the interface that it implements
+ *
+ * @param utility The utility to remove
+ *
+ * @throws IllegalArgumentException if utility is null
+ */
+ public void removeUtility(Object utility) {
+ if (utility == null) {
+ throw new IllegalArgumentException("Cannot remove null as a Service");
+ }
+
+ Set<Class<?>> interfaces = getAllInterfaces(utility.getClass());
+ for (Class<?> i : interfaces) {
+ utilities.remove(i);
+ }
+ }
+
+ /**
+ * Returns the set of interfaces implemented by the given class and its
+ * ancestors or a blank set if none
+ */
+ private 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) {
+ if (Modifier.isPublic(interfaze.getModifiers())) {
+ implemented.add(interfaze);
+ }
+ }
+ Class<?> superClass = clazz.getSuperclass();
+ // Object has no superclass so check for null
+ if (superClass != null && !superClass.equals(Object.class)) {
+ getAllInterfaces(superClass, implemented);
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ExtensionPointRegistry.java b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ExtensionPointRegistry.java
new file mode 100644
index 0000000000..f2f67b2d52
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ExtensionPointRegistry.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core;
+
+
+/**
+ * The registry for the Tuscany core extension points. As the point of contact
+ * for all extension artifacts this registry allows loaded extensions to find
+ * all other parts of the system and register themselves appropriately.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ExtensionPointRegistry {
+
+ /**
+ * Add an extension point to the registry
+ * @param extensionPoint The instance of the extension point
+ *
+ * @throws IllegalArgumentException if extensionPoint is null
+ */
+ void addExtensionPoint(Object extensionPoint);
+
+ /**
+ * Get the extension point by the interface
+ * @param extensionPointType The lookup key (extension point interface)
+ * @return The instance of the extension point
+ *
+ * @throws IllegalArgumentException if extensionPointType is null
+ */
+ <T> T getExtensionPoint(Class<T> extensionPointType);
+
+ /**
+ * Remove an extension point
+ * @param extensionPoint The extension point to remove
+ *
+ * @throws IllegalArgumentException if extensionPoint is null
+ */
+ void removeExtensionPoint(Object extensionPoint);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ModuleActivator.java b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ModuleActivator.java
new file mode 100644
index 0000000000..dbfd0dcd90
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ModuleActivator.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core;
+
+
+/**
+ * ModuleActivator represents a module that plugs into the Tuscany system. Each
+ * module should provide an implementation of this interface and register the
+ * ModuleActivator implementation class by defining a file named
+ *
+ * "META-INF/services/org.apache.tuscany.core.ModuleActivator"
+ *
+ * The content of the file is the class name of the ModuleActivator implementation.
+ * The implementation class must have a no-arg constructor. The same instance
+ * will be used to invoke all the methods during different phases of the module
+ * activation. Note that the start and stop methods defined by this interface
+ * take a reference to the Tuscany SCA runtime ExtensionPointRegistry. This
+ * gives the ModuleActivator the opportunity to add extension points to the
+ * registry as it is requested to start up and remove them when it is requested
+ * to shut down.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ModuleActivator {
+
+ /**
+ * This method is invoked when the module is started by the Tuscany system.
+ * It can be used by this module to register extensions against extension
+ * points.
+ *
+ * @param registry The extension point registry
+ */
+ void start(ExtensionPointRegistry registry);
+
+ /**
+ * This method is invoked when the module is stopped by the Tuscany system.
+ * It can be used by this module to unregister extensions against the
+ * extension points.
+ *
+ * @param registry The extension point registry
+ */
+ void stop(ExtensionPointRegistry registry);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ModuleActivatorExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ModuleActivatorExtensionPoint.java
new file mode 100644
index 0000000000..ec0f12b8ba
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/ModuleActivatorExtensionPoint.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core;
+
+import java.util.List;
+
+
+/**
+ * The extension point for the Tuscany module activator extensions.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ModuleActivatorExtensionPoint {
+
+ /**
+ * Add a module activator extension to the extension point
+ * @param activator The instance of the module activator
+ *
+ * @throws IllegalArgumentException if activator is null
+ */
+ void addModuleActivator(ModuleActivator activator);
+
+ /**
+ * Returns the module activator extensions.
+ * @return The module activator extensions
+ */
+ List<ModuleActivator> getModuleActivators();
+
+ /**
+ * Remove a module activator
+ * @param activator The module activator to remove
+ *
+ * @throws IllegalArgumentException if activator is null
+ */
+ void removeModuleActivator(Object activator);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/UtilityExtensionPoint.java b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/UtilityExtensionPoint.java
new file mode 100644
index 0000000000..6b14b95666
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/UtilityExtensionPoint.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.core;
+
+
+/**
+ * The extension point for the Tuscany core utility extensions.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface UtilityExtensionPoint {
+
+ /**
+ * Add a utility to the extension point
+ * @param utility The instance of the utility
+ *
+ * @throws IllegalArgumentException if utility is null
+ */
+ void addUtility(Object utility);
+
+ /**
+ * Get the utility by the interface
+ * @param utilityType The lookup key (utility interface)
+ * @return The instance of the utility
+ *
+ * @throws IllegalArgumentException if utilityType is null
+ */
+ <T> T getUtility(Class<T> utilityType);
+
+ /**
+ * Remove a utility
+ * @param utility The utility to remove
+ *
+ * @throws IllegalArgumentException if utility is null
+ */
+ void removeUtility(Object utility);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscoverer.java b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscoverer.java
new file mode 100644
index 0000000000..2e11234095
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscoverer.java
@@ -0,0 +1,248 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.extensibility;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.lang.ref.WeakReference;
+import java.net.URL;
+import java.net.URLConnection;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A ServiceDiscoverer that find META-INF/services/... using the Context ClassLoader.
+ *
+ * @version $Rev: $ $Date: $
+ */
+public class ContextClassLoaderServiceDiscoverer implements ServiceDiscoverer {
+ private static final Logger logger = Logger.getLogger(ContextClassLoaderServiceDiscoverer.class.getName());
+
+ public class ServiceDeclarationImpl implements ServiceDeclaration {
+ private URL url;
+ private String className;
+ private Class<?> javaClass;
+ private Map<String, String> attributes;
+
+ public ServiceDeclarationImpl(URL url, String className, Map<String, String> attributes) {
+ super();
+ this.url = url;
+ this.className = className;
+ this.attributes = attributes;
+ }
+
+ public Map<String, String> getAttributes() {
+ return attributes;
+ }
+
+ public String getClassName() {
+ return className;
+ }
+
+ public URL getLocation() {
+ return url;
+ }
+
+ public Class<?> loadClass() throws ClassNotFoundException {
+ if (className == null) {
+ return null;
+ }
+ if (javaClass == null) {
+ javaClass = loadClass(className);
+ }
+ return javaClass;
+ }
+
+ public Class<?> loadClass(String className) throws ClassNotFoundException {
+ return classLoaderReference.get().loadClass(className);
+ }
+
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("ClassLoader: ").append(classLoaderReference.get());
+ sb.append(" Attributes: ").append(attributes);
+ return sb.toString();
+ }
+
+ public URL getResource(final String name) {
+ return AccessController.doPrivileged(new PrivilegedAction<URL>() {
+ public URL run() {
+ return classLoaderReference.get().getResource(name);
+ }
+ });
+ }
+
+ }
+
+ private WeakReference<ClassLoader> classLoaderReference;
+
+ public ContextClassLoaderServiceDiscoverer() {
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ this.classLoaderReference = new WeakReference<ClassLoader>(classLoader);
+ }
+
+ private List<URL> getResources(final String name, final boolean firstOnly) throws IOException {
+ try {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<List<URL>>() {
+ public List<URL> run() throws IOException {
+ if (firstOnly) {
+ URL url = classLoaderReference.get().getResource(name);
+ if (url != null) {
+ return Arrays.asList(url);
+ } else {
+ return Collections.emptyList();
+ }
+ } else {
+ List<URL> urls = Collections.list(classLoaderReference.get().getResources(name));
+ return urls;
+ }
+ }
+ });
+ } catch (PrivilegedActionException e) {
+ throw (IOException)e.getException();
+ }
+ }
+
+ /**
+ * Parse a service declaration in the form class;attr=value,attr=value and
+ * return a map of attributes
+ *
+ * @param declaration
+ * @return a map of attributes
+ */
+ private static Map<String, String> parseServiceDeclaration(String declaration) {
+ Map<String, String> attributes = new HashMap<String, String>();
+ int index = declaration.indexOf(';');
+ if (index != -1) {
+ attributes.put("class", declaration.substring(0, index).trim());
+ declaration = declaration.substring(index);
+ } else {
+ int j = declaration.indexOf('=');
+ if (j == -1) {
+ attributes.put("class", declaration.trim());
+ return attributes;
+ } else {
+ declaration = ";" + declaration;
+ }
+ }
+ StringTokenizer tokens = new StringTokenizer(declaration);
+ for (; tokens.hasMoreTokens();) {
+ String key = tokens.nextToken("=").substring(1).trim();
+ if (key == null)
+ break;
+ String value = tokens.nextToken(",").substring(1).trim();
+ if (value == null)
+ break;
+ attributes.put(key, value);
+ }
+ return attributes;
+ }
+
+ public Set<ServiceDeclaration> discover(String serviceName, boolean firstOnly) {
+ Set<ServiceDeclaration> descriptors = new HashSet<ServiceDeclaration>();
+
+ String name = "META-INF/services/" + serviceName;
+ boolean debug = logger.isLoggable(Level.FINE);
+ try {
+ for (final URL url : getResources(name, firstOnly)) {
+ if (debug) {
+ logger.fine("Reading service provider file: " + url.toExternalForm());
+ }
+
+ // Allow privileged access to open URL stream. Add FilePermission to added to security
+ // policy file.
+ InputStream is;
+ try {
+ is = AccessController.doPrivileged(new PrivilegedExceptionAction<InputStream>() {
+ public InputStream run() throws IOException {
+ URLConnection connection = url.openConnection();
+ // TUSCANY-2539
+ // Don't cache connections by default to stop Tuscany locking contribution jar files
+ // done here as this is one of the first places we open a stream and the only way to
+ // set the default is to set it on an instance of URLConnection
+ connection.setDefaultUseCaches(false);
+ connection.setUseCaches(false);
+ return url.openStream();
+ }
+ });
+ } catch (PrivilegedActionException e) {
+ throw (IOException)e.getException();
+ }
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new InputStreamReader(is));
+ int count = 0;
+ while (true) {
+ String line = reader.readLine();
+ if (line == null)
+ break;
+ line = line.trim();
+ if (!line.startsWith("#") && !"".equals(line)) {
+ String reg = line.trim();
+ if (debug) {
+ logger.fine("Registering service provider: " + reg);
+ }
+
+ Map<String, String> attributes = parseServiceDeclaration(reg);
+ String className = attributes.get("class");
+ if (className == null) {
+ // Add a unique class name to prevent equals() from returning true
+ className = "_class_" + count;
+ count++;
+ }
+ ServiceDeclarationImpl descriptor = new ServiceDeclarationImpl(url, className, attributes);
+ descriptors.add(descriptor);
+ if (firstOnly) {
+ return descriptors;
+ }
+ }
+ }
+ } finally {
+ if (reader != null) {
+ try {
+ reader.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+ }
+ }
+ } catch (IOException e) {
+ logger.log(Level.SEVERE, e.getMessage(), e);
+ }
+ return descriptors;
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDeclaration.java b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDeclaration.java
new file mode 100644
index 0000000000..403b6aa7a7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDeclaration.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.extensibility;
+
+import java.net.URL;
+import java.util.Map;
+
+/**
+ * Service declaration using J2SE Jar service provider spec Classes specified
+ * inside this declaration are loaded using the ClassLoader used to read the
+ * configuration file corresponding to this declaration.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ServiceDeclaration {
+ /**
+ * Load a java class in the same context as the service definition
+ * @param className The class name
+ * @return The loaded class
+ * @throws ClassNotFoundException
+ */
+ Class<?> loadClass(String className) throws ClassNotFoundException;
+ /**
+ * Get the java class for the service impl
+ * @return The java class
+ */
+ Class<?> loadClass() throws ClassNotFoundException;
+ /**
+ * Get all attributes (name=value pairs) defined for the given entry
+ * @return All attributes keyed by name
+ */
+ Map<String, String> getAttributes();
+
+ URL getLocation();
+
+ String getClassName();
+
+ URL getResource(String name);
+
+ /**
+ * The service descriptor might be hashed
+ * @param obj Another object
+ * @return
+ */
+ boolean equals(Object obj);
+ /**
+ * The service descriptor might be hashed
+ * @return
+ */
+ int hashCode();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscoverer.java b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscoverer.java
new file mode 100644
index 0000000000..1722cd5f49
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscoverer.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.extensibility;
+
+import java.util.Set;
+
+/**
+ * A SPI that allows different implementations of discovering service declarations
+ */
+public interface ServiceDiscoverer {
+ /**
+ * Discover the service descriptors by name
+ * @param serviceName The name of the service
+ * @param firstOnly A flag to indicate if only the first instance is to be discovered
+ *
+ * @return A set of service descriptors
+ */
+ Set<ServiceDeclaration> discover(String serviceName, boolean firstOnly);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java
new file mode 100644
index 0000000000..ce41a44068
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/java/org/apache/tuscany/sca/extensibility/ServiceDiscovery.java
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.extensibility;
+
+import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Service discovery for Tuscany based on J2SE Jar service provider spec.
+ * Services are described using configuration files in META-INF/services.
+ * Service description specifies a class name followed by optional properties.
+ *
+ *
+ * @version $Rev$ $Date$
+ */
+public class ServiceDiscovery {
+ private static final Logger logger = Logger.getLogger(ServiceDiscovery.class.getName());
+
+ private final static ServiceDiscovery INSTANCE = new ServiceDiscovery();
+
+ private ServiceDiscoverer discoverer;
+ private Set<ClassLoader> registeredClassLoaders = new HashSet<ClassLoader>();
+
+ /**
+ * Get an instance of Service discovery, one instance is created per
+ * ClassLoader that this class is loaded from
+ *
+ * @return
+ */
+ public static ServiceDiscovery getInstance() {
+ return INSTANCE;
+ }
+
+ public ServiceDiscoverer getServiceDiscoverer() {
+ if (discoverer == null) {
+ discoverer = new ContextClassLoaderServiceDiscoverer();
+ }
+ return discoverer;
+ }
+
+ public void setServiceDiscoverer(ServiceDiscoverer sd) {
+ if (discoverer != null) {
+ throw new IllegalStateException("The ServiceDiscoverer cannot be reset");
+ }
+ discoverer = sd;
+ }
+
+ /**
+ * @deprecated
+ * Register a ClassLoader with this discovery mechanism. Tuscany extension
+ * ClassLoaders are registered here.
+ *
+ * @param classLoader
+ */
+ @Deprecated
+ public synchronized void registerClassLoader(ClassLoader classLoader) {
+ registeredClassLoaders.add(classLoader);
+ }
+
+ /**
+ * @deprecated
+ * Unregister a ClassLoader with this discovery mechanism.
+ *
+ * @param classLoader
+ */
+ @Deprecated
+ public synchronized void unregisterClassLoader(ClassLoader classLoader) {
+ registeredClassLoaders.remove(classLoader);
+ }
+
+ /**
+ * Get all service declarations for this name
+ *
+ * @param name
+ * @return set of service declarations
+ * @throws IOException
+ */
+ public Set<ServiceDeclaration> getServiceDeclarations(String name) throws IOException {
+ Set<ServiceDeclaration> services = getServiceDiscoverer().discover(name, false);
+ return services;
+ }
+
+ /**
+ * Get all service declarations for this interface
+ *
+ * @param serviceInterface
+ * @return set of service declarations
+ * @throws IOException
+ */
+ public Set<ServiceDeclaration> getServiceDeclarations(Class<?> serviceInterface) throws IOException {
+
+ return getServiceDeclarations(serviceInterface.getName());
+ }
+
+ /**
+ * Load one service implementation class for this interface
+ *
+ * @param serviceInterface
+ * @return service implementation class
+ * @throws IOException
+ * @throws ClassNotFoundException
+ */
+ public Class<?> loadFirstServiceClass(final Class<?> serviceInterface) throws IOException, ClassNotFoundException {
+ // Try System property first
+ String className = AccessController.doPrivileged(new PrivilegedAction<String>() {
+ public String run() {
+ return System.getProperty(serviceInterface.getName());
+ }
+ });
+ if (className != null) {
+ try {
+ // Try the classloader for the service interface first
+ return Class.forName(className, false, serviceInterface.getClassLoader());
+ } catch (ClassNotFoundException e) {
+ try {
+ // Try the thread context classloader
+ return Class.forName(className, false, Thread.currentThread().getContextClassLoader());
+ } catch (ClassNotFoundException ex) {
+ logger.log(Level.WARNING, ex.getMessage(), ex);
+ }
+ }
+ }
+ Set<ServiceDeclaration> services = getServiceDiscoverer().discover(serviceInterface.getName(), true);
+ if (services.isEmpty()) {
+ return null;
+ }
+ return services.iterator().next().loadClass();
+ }
+
+ /**
+ * Create a new instance of a factory service class.
+ *
+ * @param serviceInterface
+ * @return service implementation class
+ * @throws SecurityException
+ * @throws NoSuchMethodException
+ * @throws InvocationTargetException
+ * @throws IllegalAccessException
+ */
+ public Object newFactoryClassInstance(final Class<?> serviceInterface) throws SecurityException, NoSuchMethodException, InvocationTargetException, IllegalAccessException {
+ Method newInstanceMethod = serviceInterface.getMethod("newInstance");
+ Object factory = newInstanceMethod.invoke(null);
+ return factory;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint
new file mode 100644
index 0000000000..42bad63132
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.core.DefaultModuleActivatorExtensionPoint
diff --git a/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.UtilityExtensionPoint b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.UtilityExtensionPoint
new file mode 100644
index 0000000000..d769bad283
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/extensibility/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.UtilityExtensionPoint
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.core.DefaultUtilityExtensionPoint
diff --git a/sca-java-1.x/branches/sca-android/modules/extensibility/src/test/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscovererTestCase.java b/sca-java-1.x/branches/sca-android/modules/extensibility/src/test/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscovererTestCase.java
new file mode 100644
index 0000000000..fd508402fc
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/extensibility/src/test/java/org/apache/tuscany/sca/extensibility/ContextClassLoaderServiceDiscovererTestCase.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.extensibility;
+
+import java.util.Set;
+
+import junit.framework.Assert;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * Test Case for ClasspathServiceDiscover
+ */
+public class ContextClassLoaderServiceDiscovererTestCase {
+ private static ContextClassLoaderServiceDiscoverer discover;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ discover = new ContextClassLoaderServiceDiscoverer();
+ }
+
+ @Test
+ public void testDiscovery() {
+ Set<ServiceDeclaration> discriptors =
+ discover.discover("org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint", false);
+ Assert.assertEquals(1, discriptors.size());
+ discriptors =
+ discover.discover("notthere", false);
+ Assert.assertEquals(0, discriptors.size());
+ }
+
+ @Test
+ public void testDiscoveryFirst() {
+ Set<ServiceDeclaration> discriptors =
+ discover.discover("org.apache.tuscany.sca.core.ModuleActivatorExtensionPoint", true);
+ Assert.assertEquals(1, discriptors.size());
+ discriptors =
+ discover.discover("notthere", true);
+ Assert.assertEquals(0, discriptors.size());
+ }
+
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/LICENSE b/sca-java-1.x/branches/sca-android/modules/host-embedded/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/META-INF/README b/sca-java-1.x/branches/sca-android/modules/host-embedded/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/NOTICE b/sca-java-1.x/branches/sca-android/modules/host-embedded/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/pom.xml b/sca-java-1.x/branches/sca-android/modules/host-embedded/pom.xml
new file mode 100644
index 0000000000..92fd8cc016
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/pom.xml
@@ -0,0 +1,132 @@
+<?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.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-host-embedded</artifactId>
+ <name>Apache Tuscany SCA Embedded Host</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-node-impl</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-extensibility</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-definitions</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-definitions-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-binding-sca</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-binding-sca-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution-impl</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-policy-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core-databinding</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly-xsd</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-endpoint</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>runtime</scope>
+ </dependency>
+
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.host.embedded</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.host.embedded*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomain.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomain.java
new file mode 100644
index 0000000000..a7f148cdda
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomain.java
@@ -0,0 +1,226 @@
+/*
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.host.embedded;
+
+import java.lang.reflect.Constructor;
+
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+import org.apache.tuscany.sca.host.embedded.impl.DefaultSCADomain;
+import org.apache.tuscany.sca.host.embedded.management.ComponentManager;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * A handle to an SCA domain.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class SCADomain {
+
+ static final String LOCAL_DOMAIN_URI = "http://localhost";
+
+ /**
+ * Static variable to hold the most recent instance of SCADomain
+ */
+ // TODO: Temporary support for SCADomain.connect() API
+ protected static SCADomain theDomain;
+
+
+ /**
+ * Returns a new instance of a local SCA domain.
+ *
+ * @return
+ */
+ public static SCADomain newInstance() {
+ return createNewInstance(LOCAL_DOMAIN_URI, null);
+ }
+
+ /**
+ * Returns a new instance of a local SCA domain. The specified deployable
+ * composite will be included in the SCA domain.
+ *
+ * @param composite the deployable composite to include in the SCA domain.
+ * @return
+ */
+ public static SCADomain newInstance(String composite) {
+ return createNewInstance(LOCAL_DOMAIN_URI, "/", composite);
+ }
+
+ /**
+ * Returns a new instance of a local SCA domain. The specified deployable
+ * composites will be included in the SCA domain.
+ *
+ * @param domainURI the URI of the SCA domain
+ * @param contributionLocation the location of an SCA contribution
+ * @param composites the deployable composites to include in the SCA domain.
+ * @return
+ */
+ public static SCADomain newInstance(String domainURI, String contributionLocation, String... composites) {
+ return createNewInstance(domainURI, contributionLocation, composites);
+ }
+
+ /**
+ * Removes the specified local SCA Domain instance
+ *
+ * @param domainInstance the instance to be removed
+ */
+ // FIXME: Adding this as temporary support for the "connect" API
+ public static void removeInstance(SCADomain domainInstance) {
+ theDomain = null;
+ }
+
+ /**
+ * Returns an SCADomain representing a remote SCA domain.
+ *
+ * @param domainURI the URI of the SCA domain
+ * @return
+ */
+ // FIXME : this is a temporary implementation to get the capability working
+ public static SCADomain connect(String domainURI) {
+ return theDomain;
+ }
+
+ /**
+ * Close the SCA domain.
+ */
+ public void close() {
+ // TODO: temporary to support initial SCADomain.connect capability
+ SCADomain.removeInstance(this);
+ }
+
+ /**
+ * Returns the URI of the SCA Domain.
+ *
+ * @return the URI of the SCA Domain
+ */
+ public abstract String getURI();
+
+ /**
+ * Cast a type-safe reference to a CallableReference. Converts a type-safe
+ * reference to an equivalent CallableReference; if the target refers to a
+ * service then a ServiceReference will be returned, if the target refers to
+ * a callback then a CallableReference will be returned.
+ *
+ * @param target a reference proxy provided by the SCA runtime
+ * @param <B> the Java type of the business interface for the reference
+ * @param <R> the type of reference to be returned
+ * @return a CallableReference equivalent for the proxy
+ * @throws IllegalArgumentException if the supplied instance is not a
+ * reference supplied by the SCA runtime
+ */
+ public abstract <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException;
+
+ /**
+ * Returns a proxy for a service provided by a component in the SCA domain.
+ *
+ * @param businessInterface the interface that will be used to invoke the
+ * service
+ * @param serviceName the name of the service
+ * @param <B> the Java type of the business interface for the service
+ * @return an object that implements the business interface
+ */
+ public abstract <B> B getService(Class<B> businessInterface, String serviceName);
+
+ /**
+ * Returns a ServiceReference for a service provided by a component in the
+ * SCA domain.
+ *
+ * @param businessInterface the interface that will be used to invoke the
+ * service
+ * @param serviceName the name of the service
+ * @param <B> the Java type of the business interface for the service
+ * @return a ServiceReference for the designated service
+ */
+ public abstract <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String serviceName);
+
+ /**
+ * Returns an SCADomain instance. If the system property
+ * "org.apache.tuscany.sca.host.embedded.SCADomain" is set, its value is used as
+ * the name of the implementation class. Otherwise, if the resource
+ * "META-INF/services/org.apache.tuscany.sca.host.embedded.SCADomain" can be
+ * loaded from the supplied ClassLoader. Otherwise, it will use
+ * "org.apache.tuscany.sca.host.embedded.impl.DefaultSCADomain" as the default.
+ * The named class is loaded from the supplied ClassLoader.
+ *
+ * @param classLoader
+ * @param domainURI
+ * @param contributionLocation
+ * @param composites
+ * @return
+ */
+ static SCADomain createNewInstance(String domainURI, String contributionLocation, String... composites) {
+
+ SCADomain domain = null;
+
+ try {
+ // Determine the runtime and application ClassLoader
+ final ClassLoader runtimeClassLoader = SCADomain.class.getClassLoader();
+ final ClassLoader applicationClassLoader = Thread.currentThread().getContextClassLoader();
+
+ Class<?> implClass = ServiceDiscovery.getInstance().loadFirstServiceClass(SCADomain.class);
+
+ if (implClass == null) {
+
+ // Create a default SCA domain implementation
+ domain =
+ new DefaultSCADomain(runtimeClassLoader, applicationClassLoader, domainURI, contributionLocation,
+ composites);
+ } else {
+
+ // Create an instance of the discovered SCA domain implementation
+ Constructor<?> constructor = null;
+ try {
+ constructor =
+ implClass.getConstructor(ClassLoader.class,
+ ClassLoader.class,
+ String.class,
+ String.class,
+ String[].class);
+ } catch (NoSuchMethodException e) {
+ }
+ if (constructor != null) {
+ domain =
+ (SCADomain)constructor.newInstance(runtimeClassLoader,
+ applicationClassLoader,
+ domainURI,
+ contributionLocation,
+ composites);
+ } else {
+
+ constructor = implClass.getConstructor(ClassLoader.class, String.class);
+ domain = (SCADomain)constructor.newInstance(runtimeClassLoader, domainURI);
+ }
+ }
+
+ // FIXME: temporary support for connect() API
+ theDomain = domain;
+
+ return domain;
+
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ public ComponentManager getComponentManager() {
+ return null;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomainBean.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomainBean.java
new file mode 100644
index 0000000000..c9bfe499c6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCADomainBean.java
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.host.embedded;
+
+import org.apache.tuscany.sca.host.embedded.management.ComponentManager;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ServiceReference;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class SCADomainBean extends SCADomain {
+
+ private SCADomain instance;
+
+ private String uri = LOCAL_DOMAIN_URI;
+ private String location = "/";
+ private String[] composites;
+
+ /**
+ * Constructs a new SCA domain
+ */
+ public SCADomainBean() {
+ }
+
+ @Override
+ public String getURI() {
+ return uri;
+ }
+
+ public void setURI(String uri) {
+ this.uri = uri;
+ }
+
+ public void setContributionLocation(String contributionLocation) {
+ this.location = contributionLocation;
+ }
+
+ public String getContributionLocation() {
+ return location;
+ }
+
+ public void setDeployableComposite(String composite) {
+ setDeployableComposites(composite);
+ }
+
+ public void setDeployableComposites(String... composites) {
+ this.composites = composites;
+ }
+
+ public String[] getDeployableComposites() {
+ return composites;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+ if (instance == null) {
+ instance = SCADomain.createNewInstance(uri, location, composites);
+ }
+ Object result = instance.cast(target);
+ return (R) result;
+ }
+
+ @Override
+ public void close() {
+ if (instance == null) {
+ instance = SCADomain.createNewInstance(uri, location, composites);
+ }
+ instance.close();
+ instance = null;
+ }
+
+ @Override
+ public <B> B getService(Class<B> businessInterface, String serviceName) {
+ if (instance == null) {
+ instance = SCADomain.createNewInstance(uri, location, composites);
+ }
+ return instance.getService(businessInterface, serviceName);
+ }
+
+ @Override
+ public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String referenceName) {
+ if (instance == null) {
+ instance = SCADomain.createNewInstance(uri, location, composites);
+ }
+ return instance.getServiceReference(businessInterface, referenceName);
+ }
+
+ @Override
+ protected void finalize() throws Throwable {
+
+ // Make sure that the SCA domain is closed
+ if (instance != null) {
+ instance.close();
+ instance = null;
+ }
+ }
+
+ @Override
+ public ComponentManager getComponentManager() {
+ if (instance == null) {
+ instance = SCADomain.createNewInstance(uri, location, composites);
+ }
+ return instance.getComponentManager();
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCATestCaseRunner.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCATestCaseRunner.java
new file mode 100644
index 0000000000..7c893a5c9e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/SCATestCaseRunner.java
@@ -0,0 +1,291 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.host.embedded;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+/**
+ * A helper class that can be used to run an SCA JUnit test case. The test case will run in an isolated class loader.
+ *
+ * @version $Rev$ $Date$
+ */
+public class SCATestCaseRunner {
+
+ private ClassLoader classLoader;
+ private Class<?> testSuiteClass;
+ private Object testSuite;
+ private Class<?> testResultClass;
+ private Class<?> testCaseClass;
+ private Object testCase;
+
+ private Class<?> beforeAnnotation;
+ private Class<?> beforeClassAnnotation;
+ private Class<?> afterAnnotation;
+ private Class<?> afterClassAnnotation;
+ private Class<?> junit4AdapterClass;
+ private Class<?> junit3TestCaseClass;
+
+ /**
+ * Constructs a new TestCase runner.
+ *
+ * @param testClass
+ */
+ public SCATestCaseRunner(Class testClass) {
+ try {
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ classLoader = testClass.getClassLoader();
+ if (classLoader instanceof URLClassLoader) {
+ URL[] urls = ((URLClassLoader)classLoader).getURLs();
+ classLoader = new URLClassLoader(urls, classLoader.getParent());
+ } else if (classLoader == tccl || classLoader.getParent() == tccl) {
+ classLoader = new URLClassLoader(new URL[0], classLoader);
+ } else {
+ classLoader = tccl;
+ }
+
+ try {
+ // Thread.currentThread().setContextClassLoader(classLoader);
+ // Allow privileged access to set class loader. Requires RuntimePermission
+ // setContextClassLoader in security policy.
+ final ClassLoader finalClassLoader = classLoader;
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ Thread.currentThread().setContextClassLoader(finalClassLoader);
+ return null;
+ }
+ });
+
+ testCaseClass = Class.forName(testClass.getName(), true, classLoader);
+ testCase = testCaseClass.newInstance();
+ ClassLoader testClassLoader = testCaseClass.getClassLoader();
+
+ junit3TestCaseClass = Class.forName("junit.framework.TestCase", true, testClassLoader);
+
+ testSuiteClass = Class.forName("junit.framework.TestSuite", true, testClassLoader);
+ Constructor testSuiteConstructor = testSuiteClass.getConstructor(Class.class);
+ testSuite = testSuiteConstructor.newInstance(testCaseClass);
+
+ testResultClass = Class.forName("junit.framework.TestResult", true, testClassLoader);
+
+ try {
+ beforeAnnotation = Class.forName("org.junit.Before", true, testClassLoader);
+ afterAnnotation = Class.forName("org.junit.After", true, testClassLoader);
+ beforeClassAnnotation = Class.forName("org.junit.BeforeClass", true, testClassLoader);
+ afterClassAnnotation = Class.forName("org.junit.AfterClass", true, testClassLoader);
+ junit4AdapterClass = Class.forName("junit.framework.JUnit4TestAdapter", true, testClassLoader);
+ } catch (Exception e) {
+ // Unexpected
+ throw new AssertionError(e);
+ }
+ } catch (Throwable e) {
+ e.printStackTrace();
+ } finally {
+ // Thread.currentThread().setContextClassLoader(tccl);
+ // Allow privileged access to set class loader. Requires RuntimePermission
+ // setContextClassLoader in security policy.
+ final ClassLoader finaltccl = tccl;
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ Thread.currentThread().setContextClassLoader(finaltccl);
+ return null;
+ }
+ });
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Run the test case
+ */
+ public void run() {
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ try {
+ // Thread.currentThread().setContextClassLoader(classLoader);
+ // Allow privileged access to set class loader. Requires RuntimePermission
+ // setContextClassLoader in security policy.
+ final ClassLoader finalClassLoader = classLoader;
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ Thread.currentThread().setContextClassLoader(finalClassLoader);
+ return null;
+ }
+ });
+
+ if (junit3TestCaseClass.isAssignableFrom(testCaseClass)) {
+ Object testResult = testResultClass.newInstance();
+ Method runMethod = testSuiteClass.getMethod("run", testResultClass);
+ runMethod.invoke(testSuite, testResult);
+ } else {
+ Object junit4Adapter = junit4AdapterClass.getConstructor(Class.class).newInstance(testCaseClass);
+ Object testResult = testResultClass.newInstance();
+ Method runMethod = junit4AdapterClass.getMethod("run", testResultClass);
+ runMethod.invoke(junit4Adapter, testResult);
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ // Thread.currentThread().setContextClassLoader(tccl);
+ // Allow privileged access to set class loader. Requires RuntimePermission
+ // setContextClassLoader in security policy.
+ final ClassLoader finaltccl = tccl;
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ Thread.currentThread().setContextClassLoader(finaltccl);
+ return null;
+ }
+ });
+ }
+ }
+
+ /**
+ * Invoke the setUp method
+ */
+ public void setUp() {
+ execute("setUp");
+ }
+
+ /**
+ * Invoke the before methods
+ */
+ public void before() {
+ execute(beforeAnnotation);
+ }
+
+ /**
+ * Invoke the beforeClass methods
+ */
+ public void beforeClass() {
+ execute(beforeClassAnnotation);
+ }
+
+ /**
+ * Invoke the tearDown method
+ */
+ public void tearDown() {
+ execute("tearDown");
+ }
+
+ /**
+ * Invoke the after methods
+ */
+ public void after() {
+ execute(afterAnnotation);
+ }
+
+ /**
+ * Invoke the afterClass methods
+ */
+ public void afterClass() {
+ execute(afterClassAnnotation);
+ }
+
+ /**
+ * Invoke the specified test method.
+ */
+ public void run(String methodName) {
+ execute(methodName);
+ }
+
+ /**
+ * Invoke the methods annotated with the specified annotation.
+ */
+ private void execute(Class<?> annotationClass) {
+ if (annotationClass == null) {
+ throw new RuntimeException(new NoSuchMethodException());
+ }
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ try {
+ // Thread.currentThread().setContextClassLoader(classLoader);
+ // Allow privileged access to set class loader. Requires RuntimePermission
+ // setContextClassLoader in security policy.
+ final ClassLoader finalClassLoader = classLoader;
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ Thread.currentThread().setContextClassLoader(finalClassLoader);
+ return null;
+ }
+ });
+
+ for (Method method : testCaseClass.getDeclaredMethods()) {
+ for (Annotation annotation : method.getAnnotations()) {
+ if (annotation.annotationType() == annotationClass) {
+ method.invoke(testCase);
+ }
+ }
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ // Thread.currentThread().setContextClassLoader(tccl);
+ // Allow privileged access to set class loader. Requires RuntimePermission
+ // setContextClassLoader in security policy.
+ final ClassLoader finaltccl = tccl;
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ Thread.currentThread().setContextClassLoader(finaltccl);
+ return null;
+ }
+ });
+ }
+ }
+
+ /**
+ * Invoke the specified method
+ */
+ private void execute(String methodName) {
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ try {
+ // Thread.currentThread().setContextClassLoader(classLoader);
+ // Allow privileged access to set class loader. Requires RuntimePermission
+ // setContextClassLoader in security policy.
+ final ClassLoader finalClassLoader = classLoader;
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ Thread.currentThread().setContextClassLoader(finalClassLoader);
+ return null;
+ }
+ });
+ Method setUpMethod = testCaseClass.getDeclaredMethod(methodName);
+ setUpMethod.setAccessible(true);
+ setUpMethod.invoke(testCase);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ } finally {
+ // Thread.currentThread().setContextClassLoader(tccl);
+ // Allow privileged access to set class loader. Requires RuntimePermission
+ // setContextClassLoader in security policy.
+ final ClassLoader finaltccl = tccl;
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ Thread.currentThread().setContextClassLoader(finaltccl);
+ return null;
+ }
+ });
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ComponentManagerImpl.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ComponentManagerImpl.java
new file mode 100644
index 0000000000..187f32f405
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ComponentManagerImpl.java
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.host.embedded.impl;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.core.assembly.ActivationException;
+import org.apache.tuscany.sca.core.assembly.RuntimeComponentImpl;
+import org.apache.tuscany.sca.host.embedded.management.ComponentListener;
+import org.apache.tuscany.sca.host.embedded.management.ComponentManager;
+
+/**
+ * Implementation of the ComponentManager.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentManagerImpl implements ComponentManager {
+
+ protected List<ComponentListener> listeners = new CopyOnWriteArrayList<ComponentListener>();
+ protected EmbeddedSCADomain domain;
+
+ public ComponentManagerImpl(EmbeddedSCADomain domain) {
+ this.domain = domain;
+ }
+
+ public void addComponentListener(ComponentListener listener) {
+ this.listeners.add(listener);
+ }
+
+ public void removeComponentListener(ComponentListener listener) {
+ this.listeners.remove(listener);
+ }
+
+ public Set<String> getComponentNames() {
+ Set<String> names = new HashSet<String>();
+ for (Composite composite: domain.getDomainComposite().getIncludes()) {
+ for (Component component: composite.getComponents()) {
+ names.add(component.getName());
+ }
+ }
+ return names;
+ }
+
+ public Component getComponent(String componentName) {
+ for (Composite composite: domain.getDomainComposite().getIncludes()) {
+ for (Component component: composite.getComponents()) {
+ if (component.getName().equals(componentName)) {
+ return component;
+ }
+ }
+ }
+ return null;
+ }
+
+ public void startComponent(String componentName) throws ActivationException {
+ Component component = getComponent(componentName);
+ if (component == null) {
+ throw new IllegalArgumentException("no component: " + componentName);
+ }
+ domain.getCompositeActivator().start(component);
+ notifyComponentStarted(componentName);
+ }
+
+ public void stopComponent(String componentName) throws ActivationException {
+ Component component = getComponent(componentName);
+ if (component == null) {
+ throw new IllegalArgumentException("no component: " + componentName);
+ }
+ domain.getCompositeActivator().stop(component);
+ notifyComponentStopped(componentName);
+ }
+
+ public void notifyComponentStarted(String componentName) {
+ for (ComponentListener listener : listeners) {
+ try {
+ listener.componentStarted(componentName);
+ } catch (Exception e) {
+ e.printStackTrace(); // TODO: log
+ }
+ }
+ }
+
+ public void notifyComponentStopped(String componentName) {
+ for (ComponentListener listener : listeners) {
+ try {
+ listener.componentStopped(componentName);
+ } catch (Exception e) {
+ e.printStackTrace(); // TODO: log
+ }
+ }
+ }
+
+ public boolean isComponentStarted(String componentName) {
+ RuntimeComponentImpl runtimeComponent = (RuntimeComponentImpl)getComponent(componentName);
+ return runtimeComponent.isStarted();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java
new file mode 100644
index 0000000000..1bca290c27
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomain.java
@@ -0,0 +1,339 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.host.embedded.impl;
+
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import javax.xml.XMLConstants;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.xml.Constants;
+import org.apache.tuscany.sca.core.assembly.ActivationException;
+import org.apache.tuscany.sca.core.assembly.CompositeActivator;
+import org.apache.tuscany.sca.core.assembly.RuntimeComponentImpl;
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+import org.apache.tuscany.sca.host.embedded.management.ComponentListener;
+import org.apache.tuscany.sca.host.embedded.management.ComponentManager;
+import org.apache.tuscany.sca.node.SCAClient;
+import org.apache.tuscany.sca.node.SCAContribution;
+import org.apache.tuscany.sca.node.SCANode;
+import org.apache.tuscany.sca.node.SCANodeFactory;
+import org.apache.tuscany.sca.node.impl.NodeImpl;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ServiceReference;
+
+/**
+ * A default SCA domain facade implementation.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultSCADomain extends SCADomain {
+
+ private String uri;
+ private String[] composites;
+ // private Composite domainComposite;
+ // private List<Contribution> contributions;
+ private Map<String, Component> components;
+ private ComponentManager componentManager;
+ // private ClassLoader runtimeClassLoader;
+ private ClassLoader applicationClassLoader;
+ private String domainURI;
+ private List<String> contributionURLs;
+
+ private CompositeActivator compositeActivator;
+ private SCANode node;
+ private SCAClient client;
+
+ /**
+ * Constructs a new domain facade.
+ *
+ * @param domainURI
+ * @param contributionLocation
+ * @param composites
+ */
+ public DefaultSCADomain(ClassLoader runtimeClassLoader,
+ ClassLoader applicationClassLoader,
+ String domainURI,
+ String contributionLocation,
+ String... composites) {
+ this.uri = domainURI;
+ this.composites = composites;
+ // this.runtimeClassLoader = runtimeClassLoader;
+ this.applicationClassLoader = applicationClassLoader;
+ this.domainURI = domainURI;
+ this.contributionURLs = new ArrayList<String>();
+ if (contributionLocation != null && !"/".equals(contributionLocation)) {
+ this.contributionURLs.add(contributionLocation);
+ }
+ this.composites = composites;
+
+ init();
+
+ this.componentManager = new DefaultSCADomainComponentManager(this);
+
+ }
+
+ /**
+ * A hack to create an aggregated composite
+ * @param classLoader
+ * @param composites
+ * @return
+ */
+ private String createDeploymentComposite(ClassLoader classLoader, String composites[]) {
+ try {
+ StringBuffer xml =
+ new StringBuffer("<sca:composite xmlns:sca=\"http://www.osoa.org/xmlns/sca/1.0\"")
+ .append(" targetNamespace=\"http://tempuri.org\" name=\"aggregated\">\n");
+ XMLInputFactory factory = XMLInputFactory.newInstance();
+ for (int i = 0; i < composites.length; i++) {
+ URL url = classLoader.getResource(composites[i]);
+ if (url == null) {
+ continue;
+ }
+ String location = NodeImpl.getContributionURL(url, composites[i]).toString();
+ if (!contributionURLs.contains(location)) {
+ contributionURLs.add(location);
+ }
+ URLConnection connection = url.openConnection();
+ connection.setUseCaches(false);
+ XMLStreamReader reader = factory.createXMLStreamReader(connection.getInputStream());
+ reader.nextTag();
+
+ assert Constants.COMPOSITE_QNAME.equals(reader.getName());
+ String ns = reader.getAttributeValue(null, "targetNamespace");
+ if (ns == null) {
+ ns = XMLConstants.NULL_NS_URI;
+ }
+ String name = reader.getAttributeValue(null, "name");
+ reader.close();
+ if (XMLConstants.NULL_NS_URI.equals(ns)) {
+ xml.append("<sca:include name=\"").append(name).append("\"/>\n");
+ } else {
+ xml.append("<sca:include xmlns:ns").append(i).append("=\"").append(ns).append("\"");
+ xml.append(" name=\"").append("ns").append(i).append(":").append(name).append("\"/>\n");
+ }
+ }
+ xml.append("</sca:composite>");
+ // System.out.println(xml.toString());
+ return xml.toString();
+ } catch (Exception e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ public void init() {
+ SCANodeFactory factory = SCANodeFactory.newInstance();
+
+ List<SCAContribution> contributions = new ArrayList<SCAContribution>();
+
+ if (composites != null && composites.length > 1) {
+ // Create an aggregated composite that includes all the composites as Node API only takes one composite
+ String content = createDeploymentComposite(applicationClassLoader, composites);
+ // Create SCA contributions
+ for (String location : contributionURLs) {
+ contributions.add(new SCAContribution(location, location));
+ }
+ node =
+ factory.createSCANode("http://tempuri.org/aggregated", content, contributions
+ .toArray(new SCAContribution[contributions.size()]));
+ } else {
+ for (String location : contributionURLs) {
+ contributions.add(new SCAContribution(location, location));
+ }
+ String composite = (composites != null && composites.length >= 1) ? composites[0] : null;
+ if (!contributions.isEmpty()) {
+ node =
+ factory.createSCANode(composite, contributions.toArray(new SCAContribution[contributions.size()]));
+ } else {
+ node = factory.createSCANodeFromClassLoader(composite, applicationClassLoader);
+ }
+ }
+ client = (SCAClient)node;
+ compositeActivator = ((NodeImpl)node).getCompositeActivator();
+ components = new HashMap<String, Component>();
+
+ node.start();
+
+ getComponents(compositeActivator.getDomainComposite());
+ }
+
+ private void getComponents(Composite composite) {
+ for (Component c : composite.getComponents()) {
+ components.put(c.getName(), c);
+ }
+ for (Composite cp : composite.getIncludes()) {
+ getComponents(cp);
+ }
+ }
+
+ @Override
+ public void close() {
+ super.close();
+ node.stop();
+
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+ return (R)client.cast(target);
+ }
+
+ @Override
+ public <B> B getService(Class<B> businessInterface, String serviceName) {
+ return client.getService(businessInterface, serviceName);
+ }
+
+ @Override
+ public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String name) {
+ return client.getServiceReference(businessInterface, name);
+ }
+
+ @Override
+ public String getURI() {
+ return uri;
+ }
+
+ @Override
+ public ComponentManager getComponentManager() {
+ return componentManager;
+ }
+
+ public Set<String> getComponentNames() {
+ return components.keySet();
+ /*
+ Set<String> componentNames = new HashSet<String>();
+ for (Contribution contribution : contributions) {
+ for (Artifact artifact : contribution.getArtifacts()) {
+ if (artifact.getModel() instanceof Composite) {
+ for (Component component : ((Composite)artifact.getModel()).getComponents()) {
+ componentNames.add(component.getName());
+ }
+ }
+ }
+ }
+ return componentNames;
+ */
+ }
+
+ public Component getComponent(String componentName) {
+ return components.get(componentName);
+ /*
+ for (Contribution contribution : contributions) {
+ for (Artifact artifact : contribution.getArtifacts()) {
+ if (artifact.getModel() instanceof Composite) {
+ for (Component component : ((Composite)artifact.getModel()).getComponents()) {
+ if (component.getName().equals(componentName)) {
+ return component;
+ }
+ }
+ }
+ }
+ }
+ return null;
+ */
+ }
+
+ public void startComponent(String componentName) throws ActivationException {
+ Component component = getComponent(componentName);
+ if (component == null) {
+ throw new IllegalArgumentException("no component: " + componentName);
+ }
+ compositeActivator.start(component);
+ }
+
+ public void stopComponent(String componentName) throws ActivationException {
+ Component component = getComponent(componentName);
+ if (component == null) {
+ throw new IllegalArgumentException("no component: " + componentName);
+ }
+ compositeActivator.stop(component);
+ }
+}
+
+class DefaultSCADomainComponentManager implements ComponentManager {
+
+ protected DefaultSCADomain scaDomain;
+ protected List<ComponentListener> listeners = new CopyOnWriteArrayList<ComponentListener>();
+
+ public DefaultSCADomainComponentManager(DefaultSCADomain scaDomain) {
+ this.scaDomain = scaDomain;
+ }
+
+ public void addComponentListener(ComponentListener listener) {
+ this.listeners.add(listener);
+ }
+
+ public void removeComponentListener(ComponentListener listener) {
+ this.listeners.remove(listener);
+ }
+
+ public Set<String> getComponentNames() {
+ return scaDomain.getComponentNames();
+ }
+
+ public Component getComponent(String componentName) {
+ return scaDomain.getComponent(componentName);
+ }
+
+ public void startComponent(String componentName) throws ActivationException {
+ scaDomain.startComponent(componentName);
+ }
+
+ public void stopComponent(String componentName) throws ActivationException {
+ scaDomain.stopComponent(componentName);
+ }
+
+ public void notifyComponentStarted(String componentName) {
+ for (ComponentListener listener : listeners) {
+ try {
+ listener.componentStarted(componentName);
+ } catch (Exception e) {
+ e.printStackTrace(); // TODO: log
+ }
+ }
+ }
+
+ public void notifyComponentStopped(String componentName) {
+ for (ComponentListener listener : listeners) {
+ try {
+ listener.componentStopped(componentName);
+ } catch (Exception e) {
+ e.printStackTrace(); // TODO: log
+ }
+ }
+ }
+
+ public boolean isComponentStarted(String componentName) {
+ RuntimeComponentImpl runtimeComponent = (RuntimeComponentImpl)getComponent(componentName);
+ return runtimeComponent.isStarted();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java
new file mode 100644
index 0000000000..519e76d0ae
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomain.java
@@ -0,0 +1,235 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.host.embedded.impl;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.assembly.xml.Constants;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.service.ContributionService;
+import org.apache.tuscany.sca.core.assembly.ActivationException;
+import org.apache.tuscany.sca.core.assembly.CompositeActivator;
+import org.apache.tuscany.sca.core.context.ServiceReferenceImpl;
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+import org.apache.tuscany.sca.host.embedded.management.ComponentManager;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.node.impl.RuntimeBootStrapper;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentContext;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * An SCA domain facade implementation.
+ *
+ * @version $Rev$ $Date$
+ */
+public class EmbeddedSCADomain extends SCADomain {
+
+ private String uri;
+ private Composite domainComposite;
+ private RuntimeBootStrapper runtime;
+ private ComponentManagerImpl componentManager = new ComponentManagerImpl(this);
+
+ /**
+ * Constructs a new domain facade.
+ *
+ * @param runtimeClassLoader
+ * @param domainURI
+ */
+ public EmbeddedSCADomain(ClassLoader runtimeClassLoader,
+ String domainURI) {
+ this.uri = domainURI;
+
+ // Create a runtime
+ runtime = new RuntimeBootStrapper(runtimeClassLoader);
+ }
+
+ public void start() throws ActivationException {
+
+ // Start the runtime
+ runtime.start();
+
+ // Create an in-memory domain level composite
+ AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
+ domainComposite = assemblyFactory.createComposite();
+ domainComposite.setName(new QName(Constants.SCA10_NS, "domain"));
+ domainComposite.setURI(uri);
+
+ getCompositeActivator().setDomainComposite(domainComposite);
+
+ }
+
+ public void stop() throws ActivationException {
+
+ // Stop the runtime
+ runtime.stop();
+
+ // Cleanup
+ domainComposite = null;
+ }
+
+ public void buildComposite(Composite composite) throws CompositeBuilderException {
+ runtime.buildComposite(composite);
+ }
+
+ public ContributionService getContributionService() {
+ return runtime.getContributionService();
+ }
+
+ public CompositeBuilder getCompositeBuilder() {
+ return runtime.getCompositeBuilder();
+ }
+
+ public CompositeActivator getCompositeActivator() {
+ return runtime.getCompositeActivator();
+ }
+
+ public Composite getDomainComposite() {
+ return domainComposite;
+ }
+
+ @Override
+ public ComponentManager getComponentManager() {
+ return componentManager;
+ }
+
+ @Override
+ public void close() {
+ super.close();
+ }
+
+ @Override
+ public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+ return (R)runtime.getProxyFactory().cast(target);
+ }
+
+ @Override
+ public <B> B getService(Class<B> businessInterface, String serviceName) {
+ ServiceReference<B> serviceReference = getServiceReference(businessInterface, serviceName);
+ if (serviceReference == null) {
+ throw new ServiceRuntimeException("Service not found: " + serviceName);
+ }
+ return serviceReference.getService();
+ }
+
+ private <B> ServiceReference<B> createServiceReference(Class<B> businessInterface, String targetURI) {
+ try {
+ AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
+ Composite composite = assemblyFactory.createComposite();
+ composite.setName(new QName(Constants.SCA10_TUSCANY_NS, "default"));
+ RuntimeComponent component = (RuntimeComponent)assemblyFactory.createComponent();
+ component.setName("default");
+ component.setURI("default");
+ runtime.getCompositeActivator().configureComponentContext(component);
+ composite.getComponents().add(component);
+ RuntimeComponentReference reference = (RuntimeComponentReference)assemblyFactory.createComponentReference();
+ reference.setName("default");
+ ModelFactoryExtensionPoint factories =
+ runtime.getExtensionPointRegistry().getExtensionPoint(ModelFactoryExtensionPoint.class);
+ JavaInterfaceFactory javaInterfaceFactory = factories.getFactory(JavaInterfaceFactory.class);
+ InterfaceContract interfaceContract = javaInterfaceFactory.createJavaInterfaceContract();
+ interfaceContract.setInterface(javaInterfaceFactory.createJavaInterface(businessInterface));
+ reference.setInterfaceContract(interfaceContract);
+ component.getReferences().add(reference);
+ reference.setComponent(component);
+ SCABindingFactory scaBindingFactory = factories.getFactory(SCABindingFactory.class);
+ SCABinding binding = scaBindingFactory.createSCABinding();
+ binding.setURI(targetURI);
+ reference.getBindings().add(binding);
+ return new ServiceReferenceImpl<B>(businessInterface, component, reference, binding, runtime
+ .getProxyFactory(), runtime.getCompositeActivator());
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+ @Override
+ public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String name) {
+
+ // Extract the component name
+ String componentName;
+ String serviceName;
+ int i = name.indexOf('/');
+ if (i != -1) {
+ componentName = name.substring(0, i);
+ serviceName = name.substring(i + 1);
+
+ } else {
+ componentName = name;
+ serviceName = null;
+ }
+
+ // Lookup the component in the domain
+ Component component = componentManager.getComponent(componentName);
+ if (component == null) {
+ // The component is not local in the partition, try to create a remote service ref
+ return createServiceReference(businessInterface, name);
+ }
+ RuntimeComponentContext componentContext = null;
+
+ // If the component is a composite, then we need to find the
+ // non-composite component that provides the requested service
+ if (component.getImplementation() instanceof Composite) {
+ for (ComponentService componentService : component.getServices()) {
+ if (serviceName == null || serviceName.equals(componentService.getName())) {
+ CompositeService compositeService = (CompositeService)componentService.getService();
+ if (compositeService != null) {
+ if (serviceName != null) {
+ serviceName = "$promoted$" + component.getName() + "$slash$" + serviceName;
+ }
+ componentContext =
+ ((RuntimeComponent)compositeService.getPromotedComponent()).getComponentContext();
+ return componentContext.createSelfReference(businessInterface, compositeService
+ .getPromotedService());
+ }
+ break;
+ }
+ }
+ // No matching service is found
+ throw new ServiceRuntimeException("Composite service not found: " + name);
+ } else {
+ componentContext = ((RuntimeComponent)component).getComponentContext();
+ if (serviceName != null) {
+ return componentContext.createSelfReference(businessInterface, serviceName);
+ } else {
+ return componentContext.createSelfReference(businessInterface);
+ }
+ }
+
+ }
+
+ @Override
+ public String getURI() {
+ return uri;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/HotUpdatableSCADomain.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/HotUpdatableSCADomain.java
new file mode 100644
index 0000000000..d59f1544e5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/HotUpdatableSCADomain.java
@@ -0,0 +1,389 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.host.embedded.impl;
+
+import java.io.File;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.service.ContributionService;
+import org.apache.tuscany.sca.contribution.service.util.FileHelper;
+import org.apache.tuscany.sca.core.assembly.ActivationException;
+import org.apache.tuscany.sca.host.embedded.SCADomain;
+import org.apache.tuscany.sca.host.embedded.management.ComponentManager;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * An SCADomain that starts a Tuscany runtime supporting multiple
+ * SCA contribution jars. All contribution jars found in a repository
+ * directory will be contributed to the SCA domain. Any changes to the
+ * contributions in that repository will be automatically detected and
+ * the SCADomain updated accordingly.
+ *
+ * TODO: find how to properly add/remove contributions and start/activate the SCADomain
+ * TODO: support contributions that are folders as well as jar's
+ * TODO: needs to restart the entire SCADomain when a contribution changes
+ * as the domain classpath includes all the contribution jar's, would
+ * be nice to find a way to avoid this
+ * TODO: hot update requires copying contribution jars to a temp location
+ * to avoid the classpath lock preventing updating the contribution
+ * jars, would be nice to find a way to avoid that
+ *
+ * @version $Rev$ $Date$
+ */
+public class HotUpdatableSCADomain extends SCADomain {
+ private static final Logger logger = Logger.getLogger(HotUpdatableSCADomain.class.getName());
+ protected String domainURI;
+ protected File contributionRepository;
+
+ protected EmbeddedSCADomain scaDomain;
+
+ protected boolean hotUpdateActive;
+ protected Thread hotUpdateThread;
+ protected int hotUpdateInterval; // milliseconds, 0 = hotupdate disabled
+
+ protected HashMap<URL, Long> existingContributions; // value is last modified time
+ protected ClassLoader originalCCL;
+
+ protected static final String REPOSITORY_FOLDER = "sca-contributions";
+
+ public HotUpdatableSCADomain(String domainURI, File contributionRepository, int hotupdateInterval) {
+ this.domainURI = domainURI;
+ this.contributionRepository = contributionRepository;
+ this.hotUpdateInterval = hotupdateInterval;
+ this.originalCCL = Thread.currentThread().getContextClassLoader();
+ start();
+ }
+
+ protected void start() {
+ try {
+ initEmbeddedSCADomain();
+ activateHotUpdate();
+ for (URL url : existingContributions.keySet()) {
+ File f = new File(url.toURI());
+ logger.info("added contribution: " + f.getName());
+ }
+ } catch (ActivationException e) {
+ throw new ServiceRuntimeException(e);
+ } catch (URISyntaxException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ @Override
+ public void close() {
+ try {
+ hotUpdateActive = false;
+ scaDomain.stop();
+ } catch (ActivationException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ Thread.currentThread().setContextClassLoader(originalCCL);
+ super.close();
+ }
+
+
+ protected SCADomain initEmbeddedSCADomain() throws ActivationException {
+
+ URL[] contributionJars = getContributionJarURLs(contributionRepository);
+
+ this.existingContributions = getLastModified(contributionJars);
+
+ if (hotUpdateInterval > 0) {
+ contributionJars = copyContributionsToTemp(contributionJars);
+ }
+
+ // Using the CCL as the parent exposes Tuscany to the contributions, want to do this?
+ URLClassLoader cl = new URLClassLoader(contributionJars, originalCCL);
+ Thread.currentThread().setContextClassLoader(cl);
+
+ scaDomain = new EmbeddedSCADomain(cl, domainURI);
+
+ scaDomain.start();
+
+ initContributions(scaDomain, cl, contributionJars);
+
+ return scaDomain;
+ }
+
+ protected URL[] getContributionJarURLs(File repositoryDir) {
+
+ String[] jars = repositoryDir.list(new FilenameFilter() {
+ public boolean accept(File dir, String name) {
+ return name.endsWith(".jar");
+ }});
+
+ List<URL> contributionJars = new ArrayList<URL>();
+ if (jars != null) {
+ for (String jar : jars) {
+ try {
+ contributionJars.add(new File(repositoryDir, jar).toURL());
+ } catch (MalformedURLException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ return contributionJars.toArray(new URL[contributionJars.size()]);
+ }
+
+ /**
+ * TODO: No idea what the 'correct' way to add/contribute and activate/start things to an scaDomain is
+ * but this seems to work. Doesn't seem to start <service>s or <reference>s which are outside of
+ * a <component> so something is missing/wrong. Also this doesn't seem to be picking up composites
+ * located in META-INF/deployables or specified in the sca-deployables.xml. Maybe the EmbeddedSCADomain
+ * and ContributionService APIs should make all this easier?
+ */
+ protected void initContributions(EmbeddedSCADomain scaDomain, ClassLoader cl, URL[] contributionJars) {
+ Contribution contribution = null;
+ ContributionService contributionService = scaDomain.getContributionService();
+ for (URL jar : contributionJars) {
+ InputStream is = null;
+ try {
+ is = jar.openStream();
+ contribution = contributionService.contribute(jar.toString(), jar, is);
+ } catch (Exception e) {
+ System.err.println("exception adding contribution: " + jar);
+ e.printStackTrace();
+ }
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+
+ if (contribution != null ) {
+ try {
+
+ for (Composite composite : contribution.getDeployables()) {
+ scaDomain.getDomainComposite().getIncludes().add(composite);
+ scaDomain.getCompositeBuilder().build(composite);
+ scaDomain.getCompositeActivator().activate(composite);
+ }
+
+ for (Composite composite : contribution.getDeployables()) {
+ scaDomain.getCompositeActivator().start(composite);
+ }
+
+ } catch (ActivationException e) {
+ throw new RuntimeException(e);
+ } catch (CompositeBuilderException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ }
+
+ /**
+ * Copies Files to a temp location returning the URLs of the new temp files.
+ * For hot update to work need to be able to delete/update the contribution jar's
+ * but as they're in the classpath the URLClassLoader has an open lock on the jar's
+ * so you can't update them. This solution copies each contribution to a temp
+ * location for use on the classpath, nicer would be a ClassLoder impl that doesn't
+ * lock the jar's.
+ */
+ protected URL[] copyContributionsToTemp(URL[] contributionJars) {
+ try {
+
+ URL[] newURLs = new URL[contributionJars.length];
+ File tempDir = new File(System.getProperty("java.io.tmpdir"));
+ for (int i=0; i<contributionJars.length; i++) {
+ File fin = new File(contributionJars[i].toURI());
+ File fout = File.createTempFile("tuscany", fin.getName(), tempDir);
+ fout.deleteOnExit();
+ FileHelper.copyFile(fin, fout);
+ fout.setLastModified(System.currentTimeMillis());
+ newURLs[i] = fout.toURL();
+ }
+ return newURLs;
+
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Returns the last modified times of the files pointed to by the URLs
+ */
+ protected HashMap<URL, Long> getLastModified(URL[] contrabutions) {
+ try {
+
+ HashMap<URL, Long> contributionLastUpdates = new HashMap<URL, Long>();
+ for (URL url: contrabutions) {
+ File f = new File(url.toURI());
+ contributionLastUpdates.put(url, new Long(f.lastModified()));
+ }
+ return contributionLastUpdates;
+
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected void activateHotUpdate() {
+ if (hotUpdateInterval == 0) {
+ return; // hotUpdateInterval of 0 disables hotupdate
+ }
+
+ Runnable runable = new Runnable() {
+ public void run() {
+ logger.info("Tuscany contribution hotupdate running");
+ while (hotUpdateActive) {
+ try {
+ Thread.sleep(hotUpdateInterval);
+ } catch (InterruptedException e) {
+ }
+ if (hotUpdateActive) {
+ checkForUpdates();
+ }
+ }
+ logger.info("Tuscany contribution hotupdate stopped");
+ }
+ };
+ hotUpdateThread = new Thread(runable, "TuscanyHotUpdate");
+ hotUpdateActive = true;
+ hotUpdateThread.start();
+ }
+
+
+ /**
+ * Checks if any of the contributions have been updated and if so restarts the SCADomain
+ * TODO: Ideally just the altered contribution would be restarted but thats not possible
+ * as the ClassLoader used by the SCADomain includes the old contribution so need
+ * to restart the entire domain to use a new ClassLoader. Should there be separate
+ * ClassLoader per contribution? But then have all the issues with sharing classes
+ * across contributions.
+ */
+ protected void checkForUpdates() {
+ URL[] currentContributions = getContributionJarURLs(contributionRepository);
+
+ if (areContributionsAltered(currentContributions)) {
+ try {
+ scaDomain.stop();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ try {
+ initEmbeddedSCADomain();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ protected boolean areContributionsAltered(URL[] currentContrabutions) {
+ try {
+
+ List addedContributions = getAddedContributions(currentContrabutions);
+ List removedContributions = getRemovedContributions(currentContrabutions);
+ List updatedContributions = getUpdatedContributions(currentContrabutions);
+
+ return (addedContributions.size() > 0 || removedContributions.size() > 0 || updatedContributions.size() > 0);
+
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ protected List<URL> getUpdatedContributions(URL[] currentContrabutions) throws URISyntaxException {
+ List<URL> urls = new ArrayList<URL>();
+ for (URL url : currentContrabutions) {
+ if (existingContributions.containsKey(url)) {
+ File curentFile = new File(url.toURI());
+ if (curentFile.lastModified() != existingContributions.get(url)) {
+ urls.add(url);
+ logger.info("updated contribution: " + curentFile.getName());
+ }
+ }
+ }
+ return urls;
+ }
+
+ protected List getRemovedContributions(URL[] currentContrabutions) throws URISyntaxException {
+ List<URL> currentUrls = Arrays.asList(currentContrabutions);
+ List<URL> urls = new ArrayList<URL>();
+ for (URL url : existingContributions.keySet()) {
+ if (!currentUrls.contains(url)) {
+ urls.add(url);
+ }
+ }
+ for (URL url : urls) {
+ logger.info("removed contributions: " + new File(url.toURI()).getName());
+ }
+ return urls;
+ }
+
+ protected List getAddedContributions(URL[] currentContrabutions) throws URISyntaxException {
+ List<URL> urls = new ArrayList<URL>();
+ for (URL url : currentContrabutions) {
+ if (!existingContributions.containsKey(url)) {
+ urls.add(url);
+ logger.info("added contribution: " + new File(url.toURI()).getName());
+ }
+ }
+ return urls;
+ }
+
+ @Override
+ public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+ throw new UnsupportedOperationException("not implemented");
+ }
+
+ @Override
+ public <B> B getService(Class<B> businessInterface, String serviceName) {
+ return scaDomain.getService(businessInterface, serviceName);
+ }
+
+ @Override
+ public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String referenceName) {
+ return scaDomain.getServiceReference(businessInterface, referenceName);
+ }
+
+ @Override
+ public String getURI() {
+ return domainURI;
+ }
+
+ @Override
+ public ComponentManager getComponentManager(){
+ return scaDomain.getComponentManager();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java
new file mode 100644
index 0000000000..55b6afb6f2
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntime.java
@@ -0,0 +1,385 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.host.embedded.impl;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.TransformerFactory;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.EndpointFactory;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionService;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ModuleActivator;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.core.assembly.ActivationException;
+import org.apache.tuscany.sca.core.assembly.CompositeActivator;
+import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory;
+import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint;
+import org.apache.tuscany.sca.core.scope.ScopeRegistry;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.definitions.impl.SCADefinitionsImpl;
+import org.apache.tuscany.sca.definitions.util.SCADefinitionsUtil;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl;
+import org.apache.tuscany.sca.policy.DefaultIntentAttachPointTypeFactory;
+import org.apache.tuscany.sca.policy.DefaultPolicyFactory;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.provider.SCADefinitionsProvider;
+import org.apache.tuscany.sca.provider.SCADefinitionsProviderExtensionPoint;
+import org.apache.tuscany.sca.work.WorkScheduler;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReallySmallRuntime {
+ private static final Logger logger = Logger.getLogger(ReallySmallRuntime.class.getName());
+ private List<ModuleActivator> modules;
+ private ExtensionPointRegistry registry;
+
+ private ClassLoader classLoader;
+ private AssemblyFactory assemblyFactory;
+ private ContributionService contributionService;
+ private CompositeActivator compositeActivator;
+ private CompositeBuilder compositeBuilder;
+ // private DomainBuilder domainBuilder;
+ private WorkScheduler workScheduler;
+ private ScopeRegistry scopeRegistry;
+ private ProxyFactory proxyFactory;
+ private List<SCADefinitions> policyDefinitions;
+ private ModelResolver policyDefinitionsResolver;
+ private Monitor monitor;
+
+ public ReallySmallRuntime(ClassLoader classLoader) {
+ this.classLoader = classLoader;
+ }
+
+ public void start() throws ActivationException {
+ long start = System.currentTimeMillis();
+
+ // Create our extension point registry
+ registry = new DefaultExtensionPointRegistry();
+ UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
+
+ // Get work scheduler
+ workScheduler = utilities.getUtility(WorkScheduler.class);
+
+ // Create an interface contract mapper
+ InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class);
+
+ // Get factory extension point
+ ModelFactoryExtensionPoint factories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class);
+
+ // Get Message factory
+ MessageFactory messageFactory = factories.getFactory(MessageFactory.class);
+
+ // Get proxy factory
+ ProxyFactoryExtensionPoint proxyFactories = registry.getExtensionPoint(ProxyFactoryExtensionPoint.class);
+ proxyFactory = new ExtensibleProxyFactory(proxyFactories);
+
+ // Create model factories
+ assemblyFactory = new RuntimeAssemblyFactory();
+ factories.addFactory(assemblyFactory);
+ PolicyFactory policyFactory = new DefaultPolicyFactory();
+ factories.addFactory(policyFactory);
+
+ // Load the runtime modules
+ modules = loadModules(registry);
+
+ // Start the runtime modules
+ startModules(registry, modules);
+
+ SCABindingFactory scaBindingFactory = factories.getFactory(SCABindingFactory.class);
+ IntentAttachPointTypeFactory intentAttachPointTypeFactory = new DefaultIntentAttachPointTypeFactory();
+ factories.addFactory(intentAttachPointTypeFactory);
+ ContributionFactory contributionFactory = factories.getFactory(ContributionFactory.class);
+
+ // Create a monitor
+ MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
+
+ if (monitorFactory != null){
+ monitor = monitorFactory.createMonitor();
+ } else {
+ monitorFactory = new DefaultMonitorFactoryImpl();
+ monitor = monitorFactory.createMonitor();
+ utilities.addUtility(monitorFactory);
+ //logger.fine("No MonitorFactory is found on the classpath.");
+ }
+
+ // Create a contribution service
+ policyDefinitions = new ArrayList<SCADefinitions>();
+ policyDefinitionsResolver = new DefaultModelResolver();
+ contributionService = ReallySmallRuntimeBuilder.createContributionService(classLoader,
+ registry,
+ contributionFactory,
+ assemblyFactory,
+ policyFactory,
+ mapper,
+ policyDefinitions,
+ policyDefinitionsResolver,
+ monitor);
+
+ // Create the ScopeRegistry
+ scopeRegistry = ReallySmallRuntimeBuilder.createScopeRegistry(registry);
+
+ // Create a composite activator
+ compositeActivator = ReallySmallRuntimeBuilder.createCompositeActivator(registry,
+ assemblyFactory,
+ messageFactory,
+ scaBindingFactory,
+ mapper,
+ proxyFactory,
+ scopeRegistry,
+ workScheduler);
+
+ // Load the definitions.xml
+ loadSCADefinitions();
+
+ if (logger.isLoggable(Level.FINE)) {
+ long end = System.currentTimeMillis();
+ logger.fine("The tuscany runtime is started in " + (end - start) + " ms.");
+ }
+ }
+
+ public void stop() throws ActivationException {
+ long start = System.currentTimeMillis();
+
+ // Stop the runtime modules
+ stopModules(registry, modules);
+
+ // Stop and destroy the work manager
+ workScheduler.destroy();
+
+ // Cleanup
+ modules = null;
+ registry = null;
+ assemblyFactory = null;
+ contributionService = null;
+ compositeActivator = null;
+ workScheduler = null;
+ scopeRegistry = null;
+
+ if (logger.isLoggable(Level.FINE)) {
+ long end = System.currentTimeMillis();
+ logger.fine("The tuscany runtime is stopped in " + (end - start) + " ms.");
+ }
+ }
+
+ public void buildComposite(Composite composite) throws CompositeBuilderException {
+ //Get factory extension point
+ ModelFactoryExtensionPoint factories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ SCABindingFactory scaBindingFactory = factories.getFactory(SCABindingFactory.class);
+ IntentAttachPointTypeFactory intentAttachPointTypeFactory = factories.getFactory(IntentAttachPointTypeFactory.class);
+ EndpointFactory endpointFactory = factories.getFactory(EndpointFactory.class);
+ UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
+ InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class);
+ DocumentBuilderFactory documentBuilderFactory = factories.getFactory(DocumentBuilderFactory.class);
+ TransformerFactory transformerFactory = factories.getFactory(TransformerFactory.class);
+
+ //Create a composite builder
+ SCADefinitions aggregatedDefinitions = new SCADefinitionsImpl();
+ for ( SCADefinitions definition : ((List<SCADefinitions>)policyDefinitions) ) {
+ SCADefinitionsUtil.aggregateSCADefinitions(definition, aggregatedDefinitions);
+ }
+ compositeBuilder = ReallySmallRuntimeBuilder.createCompositeBuilder(monitor,
+ assemblyFactory,
+ scaBindingFactory,
+ endpointFactory,
+ intentAttachPointTypeFactory,
+ documentBuilderFactory,
+ transformerFactory,
+ mapper,
+ aggregatedDefinitions);
+ compositeBuilder.build(composite);
+
+ }
+
+ public ContributionService getContributionService() {
+ return contributionService;
+ }
+
+ public CompositeActivator getCompositeActivator() {
+ return compositeActivator;
+ }
+
+ public CompositeBuilder getCompositeBuilder() {
+ return compositeBuilder;
+ }
+
+ public AssemblyFactory getAssemblyFactory() {
+ return assemblyFactory;
+ }
+
+ private void loadSCADefinitions() throws ActivationException {
+ try {
+ URLArtifactProcessorExtensionPoint documentProcessors = registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ URLArtifactProcessor<SCADefinitions> definitionsProcessor = documentProcessors.getProcessor(SCADefinitions.class);
+ SCADefinitionsProviderExtensionPoint scaDefnProviders = registry.getExtensionPoint(SCADefinitionsProviderExtensionPoint.class);
+
+ SCADefinitions systemSCADefinitions = new SCADefinitionsImpl();
+ SCADefinitions aSCADefn = null;
+ for ( SCADefinitionsProvider aProvider : scaDefnProviders.getSCADefinitionsProviders() ) {
+ aSCADefn = aProvider.getSCADefinition();
+ SCADefinitionsUtil.aggregateSCADefinitions(aSCADefn, systemSCADefinitions);
+ }
+
+ policyDefinitions.add(systemSCADefinitions);
+
+ //we cannot expect that providers will add the intents and policysets into the resolver
+ //so we do this here explicitly
+ for ( Intent intent : systemSCADefinitions.getPolicyIntents() ) {
+ policyDefinitionsResolver.addModel(intent);
+ }
+
+ for ( PolicySet policySet : systemSCADefinitions.getPolicySets() ) {
+ policyDefinitionsResolver.addModel(policySet);
+ }
+
+ for ( IntentAttachPointType attachPoinType : systemSCADefinitions.getBindingTypes() ) {
+ policyDefinitionsResolver.addModel(attachPoinType);
+ }
+
+ for ( IntentAttachPointType attachPoinType : systemSCADefinitions.getImplementationTypes() ) {
+ policyDefinitionsResolver.addModel(attachPoinType);
+ }
+
+ //now that all system sca definitions have been read, lets resolve them right away
+ definitionsProcessor.resolve(systemSCADefinitions,
+ policyDefinitionsResolver);
+ } catch ( Exception e ) {
+ throw new ActivationException(e);
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private List<ModuleActivator> loadModules(ExtensionPointRegistry registry) throws ActivationException {
+
+ // Load and instantiate the modules found on the classpath (or any registered ClassLoaders)
+ modules = new ArrayList<ModuleActivator>();
+ try {
+ Set<ServiceDeclaration> moduleActivators =
+ ServiceDiscovery.getInstance().getServiceDeclarations(ModuleActivator.class);
+ Set<String> moduleClasses = new HashSet<String>();
+ for (ServiceDeclaration moduleDeclarator : moduleActivators) {
+ if (moduleClasses.contains(moduleDeclarator.getClassName())) {
+ continue;
+ }
+ moduleClasses.add(moduleDeclarator.getClassName());
+ Class<?> moduleClass = moduleDeclarator.loadClass();
+ ModuleActivator module = (ModuleActivator)moduleClass.newInstance();
+ modules.add(module);
+ }
+ } catch (IOException e) {
+ throw new ActivationException(e);
+ } catch (ClassNotFoundException e) {
+ throw new ActivationException(e);
+ } catch (InstantiationException e) {
+ throw new ActivationException(e);
+ } catch (IllegalAccessException e) {
+ throw new ActivationException(e);
+ }
+
+ return modules;
+ }
+
+ private void startModules(ExtensionPointRegistry registry, List<ModuleActivator> modules)
+ throws ActivationException {
+ boolean debug = logger.isLoggable(Level.FINE);
+ // Start all the extension modules
+ for (ModuleActivator module : modules) {
+ long start = 0L;
+ if (debug) {
+ logger.fine(module.getClass().getName() + " is starting.");
+ start = System.currentTimeMillis();
+ }
+ try {
+ module.start(registry);
+ if (debug) {
+ long end = System.currentTimeMillis();
+ logger.fine(module.getClass().getName() + " is started in " + (end - start) + " ms.");
+ }
+ } catch (Throwable e) {
+ logger.log(Level.WARNING, "Exception starting module " + module.getClass().getName() + " :" + e.getMessage());
+ logger.log(Level.FINE, "Exception starting module " + module.getClass().getName(), e);
+ }
+ }
+ }
+
+ private void stopModules(final ExtensionPointRegistry registry, List<ModuleActivator> modules) {
+ boolean debug = logger.isLoggable(Level.FINE);
+ for (ModuleActivator module : modules) {
+ long start = 0L;
+ if (debug) {
+ logger.fine(module.getClass().getName() + " is stopping.");
+ start = System.currentTimeMillis();
+ }
+ module.stop(registry);
+ if (debug) {
+ long end = System.currentTimeMillis();
+ logger.fine(module.getClass().getName() + " is stopped in " + (end - start) + " ms.");
+ }
+ }
+ }
+
+ /**
+ * @return the proxyFactory
+ */
+ public ProxyFactory getProxyFactory() {
+ return proxyFactory;
+ }
+
+ /**
+ * @return the registry
+ */
+ public ExtensionPointRegistry getExtensionPointRegistry() {
+ return registry;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.java
new file mode 100644
index 0000000000..738e5e6248
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/impl/ReallySmallRuntimeBuilder.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.sca.host.embedded.impl;
+
+import java.io.IOException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.transform.TransformerFactory;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.EndpointFactory;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl;
+import org.apache.tuscany.sca.assembly.xml.CompositeDocumentProcessor;
+import org.apache.tuscany.sca.context.ContextFactoryExtensionPoint;
+import org.apache.tuscany.sca.context.RequestContextFactory;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.DefaultValidatingXMLInputFactory;
+import org.apache.tuscany.sca.contribution.processor.DefaultValidationSchemaExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensiblePackageProcessor;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.PackageProcessor;
+import org.apache.tuscany.sca.contribution.processor.PackageProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
+import org.apache.tuscany.sca.contribution.service.ContributionListenerExtensionPoint;
+import org.apache.tuscany.sca.contribution.service.ContributionRepository;
+import org.apache.tuscany.sca.contribution.service.ContributionService;
+import org.apache.tuscany.sca.contribution.service.ExtensibleContributionListener;
+import org.apache.tuscany.sca.contribution.service.TypeDescriber;
+import org.apache.tuscany.sca.contribution.service.impl.ContributionRepositoryImpl;
+import org.apache.tuscany.sca.contribution.service.impl.ContributionServiceImpl;
+import org.apache.tuscany.sca.contribution.service.impl.PackageTypeDescriberImpl;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.core.assembly.ActivationException;
+import org.apache.tuscany.sca.core.assembly.CompositeActivator;
+import org.apache.tuscany.sca.core.assembly.CompositeActivatorImpl;
+import org.apache.tuscany.sca.core.conversation.ConversationManager;
+import org.apache.tuscany.sca.core.invocation.ExtensibleWireProcessor;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.core.scope.CompositeScopeContainerFactory;
+import org.apache.tuscany.sca.core.scope.ConversationalScopeContainerFactory;
+import org.apache.tuscany.sca.core.scope.RequestScopeContainerFactory;
+import org.apache.tuscany.sca.core.scope.ScopeContainerFactory;
+import org.apache.tuscany.sca.core.scope.ScopeRegistry;
+import org.apache.tuscany.sca.core.scope.ScopeRegistryImpl;
+import org.apache.tuscany.sca.core.scope.StatelessScopeContainerFactory;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.endpointresolver.EndpointResolverFactoryExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
+import org.apache.tuscany.sca.runtime.RuntimeWireProcessor;
+import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint;
+import org.apache.tuscany.sca.work.WorkScheduler;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReallySmallRuntimeBuilder {
+
+ // private static final Logger logger = Logger.getLogger(ReallySmallRuntimeBuilder.class.getName());
+
+ public static CompositeActivator createCompositeActivator(ExtensionPointRegistry registry,
+ AssemblyFactory assemblyFactory,
+ MessageFactory messageFactory,
+ SCABindingFactory scaBindingFactory,
+ InterfaceContractMapper mapper,
+ ProxyFactory proxyFactory,
+ ScopeRegistry scopeRegistry,
+ WorkScheduler workScheduler) {
+
+ // Create a wire post processor extension point
+ RuntimeWireProcessorExtensionPoint wireProcessors =
+ registry.getExtensionPoint(RuntimeWireProcessorExtensionPoint.class);
+ RuntimeWireProcessor wireProcessor = new ExtensibleWireProcessor(wireProcessors);
+
+ // Retrieve the processors extension point
+ StAXArtifactProcessorExtensionPoint processors =
+ registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+
+ // Create a provider factory extension point
+ ProviderFactoryExtensionPoint providerFactories =
+ registry.getExtensionPoint(ProviderFactoryExtensionPoint.class);
+
+ // Create a endpoint resolver factory extension point
+ EndpointResolverFactoryExtensionPoint endpointResolverFactories =
+ registry.getExtensionPoint(EndpointResolverFactoryExtensionPoint.class);
+
+ JavaInterfaceFactory javaInterfaceFactory =
+ registry.getExtensionPoint(ModelFactoryExtensionPoint.class).getFactory(JavaInterfaceFactory.class);
+ RequestContextFactory requestContextFactory =
+ registry.getExtensionPoint(ContextFactoryExtensionPoint.class).getFactory(RequestContextFactory.class);
+
+ UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
+ ConversationManager conversationManager = utilities.getUtility(ConversationManager.class);
+
+ // Create the composite activator
+ CompositeActivator compositeActivator =
+ new CompositeActivatorImpl(assemblyFactory, messageFactory, javaInterfaceFactory, scaBindingFactory,
+ mapper, scopeRegistry, workScheduler, wireProcessor, requestContextFactory,
+ proxyFactory, providerFactories, endpointResolverFactories, processors, conversationManager);
+
+ return compositeActivator;
+ }
+
+ public static CompositeBuilder createCompositeBuilder(Monitor monitor,
+ AssemblyFactory assemblyFactory,
+ SCABindingFactory scaBindingFactory,
+ EndpointFactory endpointFactory,
+ IntentAttachPointTypeFactory intentAttachPointTypeFactory,
+ DocumentBuilderFactory documentBuilderFactory,
+ TransformerFactory transformerFactory,
+ InterfaceContractMapper interfaceContractMapper,
+ SCADefinitions policyDefinitions) {
+
+
+ return new CompositeBuilderImpl(assemblyFactory,
+ endpointFactory,
+ scaBindingFactory,
+ intentAttachPointTypeFactory,
+ documentBuilderFactory,
+ transformerFactory,
+ interfaceContractMapper,
+ policyDefinitions,
+ monitor);
+ }
+
+
+ /**
+ * Create the contribution service used by this domain.
+ *
+ * @throws ActivationException
+ */
+ public static ContributionService createContributionService(ClassLoader classLoader,
+ ExtensionPointRegistry registry,
+ ContributionFactory contributionFactory,
+ AssemblyFactory assemblyFactory,
+ PolicyFactory policyFactory,
+ InterfaceContractMapper mapper,
+ List<SCADefinitions> policyDefinitions,
+ ModelResolver policyDefinitionResolver,
+ Monitor monitor)
+ throws ActivationException {
+
+ // Get the model factory extension point
+ ModelFactoryExtensionPoint modelFactories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class);
+
+ // Create a new XML input factory
+ // Allow privileged access to factory. Requires RuntimePermission in security policy file.
+ XMLInputFactory inputFactory = AccessController.doPrivileged(new PrivilegedAction<XMLInputFactory>() {
+ public XMLInputFactory run() {
+ return XMLInputFactory.newInstance();
+ }
+ });
+ modelFactories.addFactory(inputFactory);
+
+ // Create a validation XML schema extension point
+ ValidationSchemaExtensionPoint schemas = new DefaultValidationSchemaExtensionPoint();
+
+ // Create a validating XML input factory
+ XMLInputFactory validatingInputFactory = new DefaultValidatingXMLInputFactory(inputFactory, schemas, monitor);
+ modelFactories.addFactory(validatingInputFactory);
+
+ // Create StAX artifact processor extension point
+ StAXArtifactProcessorExtensionPoint staxProcessors =
+ registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+
+ // Create and register StAX processors for SCA assembly XML
+ // Allow privileged access to factory. Requires RuntimePermission in security policy file.
+ XMLOutputFactory outputFactory = AccessController.doPrivileged(new PrivilegedAction<XMLOutputFactory>() {
+ public XMLOutputFactory run() {
+ return XMLOutputFactory.newInstance();
+ }
+ });
+ ExtensibleStAXArtifactProcessor staxProcessor =
+ new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, monitor);
+
+ // Create URL artifact processor extension point
+ URLArtifactProcessorExtensionPoint documentProcessors =
+ registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+
+ // Create and register document processors for SCA assembly XML
+ documentProcessors.getProcessor(Composite.class);
+ DocumentBuilderFactory documentBuilderFactory = AccessController.doPrivileged(new PrivilegedAction<DocumentBuilderFactory>() {
+ public DocumentBuilderFactory run() {
+ return DocumentBuilderFactory.newInstance();
+ }
+ });
+ documentProcessors.addArtifactProcessor(new CompositeDocumentProcessor(staxProcessor, validatingInputFactory, documentBuilderFactory, policyDefinitions, monitor));
+
+ // Create Model Resolver extension point
+ ModelResolverExtensionPoint modelResolvers = registry.getExtensionPoint(ModelResolverExtensionPoint.class);
+
+ // Create contribution package processor extension point
+ TypeDescriber describer = new PackageTypeDescriberImpl();
+ PackageProcessor packageProcessor =
+ new ExtensiblePackageProcessor(registry.getExtensionPoint(PackageProcessorExtensionPoint.class), describer, monitor);
+
+ // Create contribution listener
+ ExtensibleContributionListener contributionListener =
+ new ExtensibleContributionListener(registry.getExtensionPoint(ContributionListenerExtensionPoint.class));
+
+ // Create a contribution repository
+ ContributionRepository repository;
+ try {
+ repository = new ContributionRepositoryImpl("target", inputFactory, monitor);
+ } catch (IOException e) {
+ throw new ActivationException(e);
+ }
+
+ ExtensibleURLArtifactProcessor documentProcessor = new ExtensibleURLArtifactProcessor(documentProcessors, monitor);
+
+ // Create the contribution service
+ ContributionService contributionService =
+ new ContributionServiceImpl(repository, packageProcessor, documentProcessor, staxProcessor,
+ contributionListener, policyDefinitionResolver, modelResolvers, modelFactories,
+ assemblyFactory, contributionFactory, inputFactory, policyDefinitions, monitor);
+ return contributionService;
+ }
+
+ public static ScopeRegistry createScopeRegistry(ExtensionPointRegistry registry) {
+ ScopeRegistry scopeRegistry = new ScopeRegistryImpl();
+ ScopeContainerFactory[] factories =
+ new ScopeContainerFactory[] {new CompositeScopeContainerFactory(), new StatelessScopeContainerFactory(),
+ new RequestScopeContainerFactory(),
+ new ConversationalScopeContainerFactory(null),
+ // new HttpSessionScopeContainer(monitor)
+ };
+ for (ScopeContainerFactory f : factories) {
+ scopeRegistry.register(f);
+ }
+
+ //FIXME Pass the scope container differently as it's not an extension point
+ registry.addExtensionPoint(scopeRegistry);
+
+ return scopeRegistry;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/management/ComponentListener.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/management/ComponentListener.java
new file mode 100644
index 0000000000..5f38c0c063
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/management/ComponentListener.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.host.embedded.management;
+
+import java.util.EventListener;
+
+/**
+ * Component Listener interface.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ComponentListener extends EventListener {
+
+ void componentStarted(String componentName);
+ void componentStopped(String componentName);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/management/ComponentManager.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/management/ComponentManager.java
new file mode 100644
index 0000000000..4acb270810
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/main/java/org/apache/tuscany/sca/host/embedded/management/ComponentManager.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.host.embedded.management;
+
+import java.util.Set;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.core.assembly.ActivationException;
+
+/**
+ * Component Manager interface.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ComponentManager {
+
+ Set<String> getComponentNames();
+
+ Component getComponent(String componentName);
+
+ boolean isComponentStarted(String componentName);
+
+ void startComponent(String componentName) throws ActivationException;
+
+ void stopComponent(String componentName) throws ActivationException;
+
+ void addComponentListener(ComponentListener listener);
+
+ void removeComponentListener(ComponentListener listener);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainBeanTestCase.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainBeanTestCase.java
new file mode 100644
index 0000000000..9252b114a1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainBeanTestCase.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.host.embedded;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.host.embedded.test.extension.TestService;
+import org.osoa.sca.ServiceReference;
+
+
+
+/**
+ * Test creation of an SCADomainBean and invocation of a service.
+ *
+ * @version $Rev$ $Date$
+ */
+public class SCADomainBeanTestCase extends TestCase {
+
+ private SCADomainBean domain;
+
+ @Override
+ protected void setUp() throws Exception {
+ domain = new SCADomainBean();
+ domain.setDeployableComposites("test.composite");
+ }
+
+ public void testInvoke() throws Exception {
+ ServiceReference<TestService> serviceReference = domain.getServiceReference(TestService.class, "TestServiceComponent");
+ assertNotNull(serviceReference);
+ TestService service = serviceReference.getService();
+ String result = service.ping("Bob");
+ assertEquals("Hello Bob", result);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ domain.close();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainTestCase.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainTestCase.java
new file mode 100644
index 0000000000..c52c16d8e1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/SCADomainTestCase.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.host.embedded;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.host.embedded.test.extension.TestService;
+import org.osoa.sca.ServiceReference;
+
+
+
+/**
+ * Test SCADomain.newInstance and invocation of a service.
+ *
+ * @version $Rev$ $Date$
+ */
+public class SCADomainTestCase extends TestCase {
+
+ private SCADomain domain;
+
+ @Override
+ protected void setUp() throws Exception {
+ domain = SCADomain.newInstance("test.composite");
+ }
+
+ public void testInvoke() throws Exception {
+ ServiceReference<TestService> serviceReference = domain.getServiceReference(TestService.class, "TestServiceComponent");
+ assertNotNull(serviceReference);
+ TestService service = serviceReference.getService();
+ String result = service.ping("Bob");
+ assertEquals("Hello Bob", result);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ domain.close();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomainTestCase.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomainTestCase.java
new file mode 100644
index 0000000000..fd5398c8e6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/DefaultSCADomainTestCase.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.host.embedded.impl;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.host.embedded.management.ComponentManager;
+import org.apache.tuscany.sca.host.embedded.test.extension.TestService;
+
+
+/**
+ * Test creation of DefaultSCADomain.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultSCADomainTestCase extends TestCase {
+ private DefaultSCADomain domain;
+
+ @Override
+ protected void setUp() throws Exception {
+ domain = new DefaultSCADomain(getClass().getClassLoader(), getClass().getClassLoader(),
+ "http://localhost", "./target/test-classes", "test.composite");
+ }
+
+ public void testStart() throws Exception {
+ TestService service = domain.getService(TestService.class, "TestServiceComponent");
+ assertNotNull(service);
+ }
+
+ public void testComponentManager() throws Exception {
+ ComponentManager componentManager = domain.getComponentManager();
+ assertEquals(1, componentManager.getComponentNames().size());
+ assertEquals("TestServiceComponent", componentManager.getComponentNames().iterator().next());
+ assertNotNull(componentManager.getComponent("TestServiceComponent"));
+
+ assertTrue(componentManager.isComponentStarted("TestServiceComponent"));
+ componentManager.stopComponent("TestServiceComponent");
+ assertFalse(componentManager.isComponentStarted("TestServiceComponent"));
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ domain.close();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java
new file mode 100644
index 0000000000..2a59635a19
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/EmbeddedSCADomainTestCase.java
@@ -0,0 +1,189 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.host.embedded.impl;
+
+import java.net.URL;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.service.ContributionService;
+import org.apache.tuscany.sca.host.embedded.management.ComponentListener;
+import org.apache.tuscany.sca.host.embedded.management.ComponentManager;
+import org.apache.tuscany.sca.host.embedded.test.extension.TestService;
+
+/**
+ * Test creation of an EmbeddedSCADomain and invocation of a service.
+ *
+ * @version $Rev$ $Date$
+ */
+public class EmbeddedSCADomainTestCase extends TestCase {
+ private EmbeddedSCADomain domain;
+
+ @Override
+ protected void setUp() throws Exception {
+
+ // Create a test embedded SCA domain
+ domain = new EmbeddedSCADomain(getClass().getClassLoader(), "http://localhost");
+ }
+
+ public void testDomain() throws Exception {
+ // Start the domain
+ domain.start();
+
+ // Determine my class loader and my test SCA contribution location
+ ClassLoader myClassLoader = getClass().getClassLoader();
+ String url = myClassLoader.getResource("test.txt").toString();
+ url = url.substring(0, url.length()-8);
+
+ // Contribute the SCA contribution
+ TestModelResolver myResolver = new TestModelResolver(myClassLoader);
+ ContributionService contributionService = domain.getContributionService();
+ Contribution contribution = contributionService.contribute("http://test/contribution", new URL(url), myResolver, false);
+ assertNotNull(contribution);
+
+ // Decide which SCA composite I want to deploy
+ Composite myComposite = myResolver.getComposite(new QName("http://test", "test"));
+
+ // Add the deployable composite to the domain
+ domain.getDomainComposite().getIncludes().add(myComposite);
+
+
+ domain.buildComposite(myComposite);
+
+ // Start the composite
+ domain.getCompositeActivator().activate(myComposite);
+ domain.getCompositeActivator().start(myComposite);
+
+ // At this point the domain contains my contribution, my composite and
+ // it's started, my application code can start using it
+
+ // Get the TestServiceComponent service
+ TestService service = domain.getService(TestService.class, "TestServiceComponent");
+
+ // Invoke the service
+ String result = service.ping("Bob");
+ assertEquals("Hello Bob", result);
+
+ // Stop my composite
+ domain.getCompositeActivator().stop(myComposite);
+ domain.getCompositeActivator().deactivate(myComposite);
+
+ // Remove my composite
+ domain.getDomainComposite().getIncludes().remove(myComposite);
+
+ // Remove my contribution
+ contributionService.remove("http://test/contribution");
+
+ // Stop the domain
+ domain.stop();
+ }
+
+ public void testComponentManager() throws Exception {
+ // Start the domain
+ domain.start();
+
+ // Determine my class loader and my test SCA contribution location
+ ClassLoader myClassLoader = getClass().getClassLoader();
+ String url = myClassLoader.getResource("test.txt").toString();
+ url = url.substring(0, url.length()-8);
+
+ // Contribute the SCA contribution
+ TestModelResolver myResolver = new TestModelResolver(myClassLoader);
+ ContributionService contributionService = domain.getContributionService();
+ Contribution contribution = contributionService.contribute("http://test/contribution", new URL(url), myResolver, false);
+ assertNotNull(contribution);
+
+ // Decide which SCA composite I want to deploy
+ Composite myComposite = myResolver.getComposite(new QName("http://test", "test"));
+
+ // Add the deployable composite to the domain
+ domain.getDomainComposite().getIncludes().add(myComposite);
+
+ domain.buildComposite(myComposite);
+
+ // Start the composite
+ domain.getCompositeActivator().activate(myComposite);
+ domain.getCompositeActivator().start(myComposite);
+
+ // At this point the domain contains my contribution, my composite and
+ // it's started, my application code can start using it
+
+ ComponentManager componentManager = domain.getComponentManager();
+ assertEquals(1, componentManager.getComponentNames().size());
+ assertEquals("TestServiceComponent", componentManager.getComponentNames().iterator().next());
+
+ Component component = componentManager.getComponent("TestServiceComponent");
+ assertNotNull(component);
+ assertEquals("TestServiceComponent", component.getName());
+
+ MyComponentListener cl = new MyComponentListener();
+ componentManager.addComponentListener(cl);
+
+ assertTrue(componentManager.isComponentStarted("TestServiceComponent"));
+
+ assertFalse(cl.stopCalled);
+ componentManager.stopComponent("TestServiceComponent");
+ assertTrue(cl.stopCalled);
+ assertFalse(componentManager.isComponentStarted("TestServiceComponent"));
+
+ assertFalse(cl.startCalled);
+ componentManager.startComponent("TestServiceComponent");
+ assertTrue(cl.startCalled);
+ assertTrue(componentManager.isComponentStarted("TestServiceComponent"));
+
+ // Stop my composite
+ domain.getCompositeActivator().stop(myComposite);
+ domain.getCompositeActivator().deactivate(myComposite);
+
+ // Remove my composite
+ domain.getDomainComposite().getIncludes().remove(myComposite);
+
+ // Remove my contribution
+ contributionService.remove("http://test/contribution");
+
+ // Stop the domain
+ domain.stop();
+ }
+
+ class MyComponentListener implements ComponentListener {
+ boolean startCalled;
+ boolean stopCalled;
+
+ public void componentStarted(String componentName) {
+ startCalled = true;
+ }
+
+ public void componentStopped(String componentName) {
+ stopCalled = true;
+ }
+
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ domain.close();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java
new file mode 100644
index 0000000000..1cfe5ed5d8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/impl/TestModelResolver.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.host.embedded.impl;
+
+import java.lang.ref.WeakReference;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.resolver.ClassReference;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+
+/**
+ * A test model resolver, based on a map.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestModelResolver implements ModelResolver {
+ private static final long serialVersionUID = -7826976465762296634L;
+
+ private Map<Object, Object> map = new HashMap<Object, Object>();
+ private WeakReference<ClassLoader> classLoader;
+
+ private Map<QName, Composite> composites = new HashMap<QName, Composite>();
+
+ public TestModelResolver(ClassLoader classLoader) {
+ this.classLoader = new WeakReference<ClassLoader>(classLoader);
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ Object resolved = map.get(unresolved);
+ if (resolved != null) {
+
+ // Return the resolved object
+ return modelClass.cast(resolved);
+
+ } else if (unresolved instanceof ClassReference) {
+
+ // Load a class on demand
+ ClassReference classReference = (ClassReference)unresolved;
+ Class<?> clazz;
+ try {
+ clazz = Class.forName(classReference.getClassName(), true, classLoader.get());
+ } catch (ClassNotFoundException e) {
+
+ // Return the unresolved object
+ return unresolved;
+ }
+
+ // Store a new ClassReference wrapping the loaded class
+ resolved = new ClassReference(clazz);
+ map.put(resolved, resolved);
+
+ // Return the resolved ClassReference
+ return modelClass.cast(resolved);
+
+ } else {
+
+ // Return the unresolved object
+ return unresolved;
+ }
+ }
+
+ public void addModel(Object resolved) {
+ map.put(resolved, resolved);
+ if (resolved instanceof Composite) {
+ Composite composite = (Composite)resolved;
+ composites.put(composite.getName(), composite);
+ }
+ }
+
+ public Object removeModel(Object resolved) {
+ if (resolved instanceof Composite) {
+ Composite composite = (Composite)resolved;
+ composites.remove(composite.getName());
+ }
+ return map.remove(resolved);
+ }
+
+ public Composite getComposite(QName qname) {
+ return composites.get(qname);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/DefaultTestImplementationFactory.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/DefaultTestImplementationFactory.java
new file mode 100644
index 0000000000..86e0cb6a8a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/DefaultTestImplementationFactory.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.host.embedded.test.extension;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.host.embedded.test.extension.impl.TestImplementationImpl;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+
+
+/**
+ * Default factory for the test implementation model.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultTestImplementationFactory implements TestImplementationFactory {
+
+ private AssemblyFactory assemblyFactory;
+ private JavaInterfaceFactory javaFactory;
+
+ public DefaultTestImplementationFactory(AssemblyFactory assemblyFactory,
+ JavaInterfaceFactory javaFactory) {
+ this.assemblyFactory = assemblyFactory;
+ this.javaFactory = javaFactory;
+ }
+
+ public TestImplementation createTestImplementation() {
+ return new TestImplementationImpl(assemblyFactory, javaFactory);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestImplementation.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestImplementation.java
new file mode 100644
index 0000000000..d9f1228307
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestImplementation.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.host.embedded.test.extension;
+
+import org.apache.tuscany.sca.assembly.Implementation;
+
+/**
+ * The model representing a test implementation in an SCA assembly model.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface TestImplementation extends Implementation {
+
+ /**
+ * Returns the greeting string that can be configured on test implementations.
+ *
+ * @return the greeting string that can be configured on test implementations
+ */
+ String getGreeting();
+
+ /**
+ * Sets the greeting string that can be configured on test implementations.
+ *
+ * @param greeting the greeting string that can be configured on test implementations
+ */
+ void setGreeting(String greeting);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestImplementationFactory.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestImplementationFactory.java
new file mode 100644
index 0000000000..9200d850bb
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestImplementationFactory.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.host.embedded.test.extension;
+
+
+/**
+ * A factory for the test implementation model.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface TestImplementationFactory {
+
+ /**
+ * Creates a new test implementation.
+ *
+ * @return
+ */
+ TestImplementation createTestImplementation();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestService.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestService.java
new file mode 100644
index 0000000000..4adec91151
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/TestService.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.host.embedded.test.extension;
+
+/**
+ * Service interface for test component implementations.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface TestService {
+
+ String ping(String name);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/impl/TestImplementationImpl.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/impl/TestImplementationImpl.java
new file mode 100644
index 0000000000..083b01167f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/impl/TestImplementationImpl.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.host.embedded.test.extension.impl;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.host.embedded.test.extension.TestService;
+import org.apache.tuscany.sca.host.embedded.test.extension.TestImplementation;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+
+
+/**
+ * The model representing a test implementation in an SCA assembly model.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestImplementationImpl implements TestImplementation {
+
+ private Service testService;
+ private String greeting;
+
+ /**
+ * Constructs a new test implementation.
+ */
+ public TestImplementationImpl(AssemblyFactory assemblyFactory,
+ JavaInterfaceFactory javaFactory) {
+
+ // Test implementations always provide a single service exposing
+ // the TestService interface, and have no references and properties
+ testService = assemblyFactory.createService();
+ testService.setName("Test");
+ JavaInterface javaInterface;
+ try {
+ javaInterface = javaFactory.createJavaInterface(TestService.class);
+ } catch (InvalidInterfaceException e) {
+ throw new IllegalArgumentException(e);
+ }
+ JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract();
+ interfaceContract.setInterface(javaInterface);
+ testService.setInterfaceContract(interfaceContract);
+ }
+
+ public String getGreeting() {
+ return greeting;
+ }
+
+ public void setGreeting(String greeting) {
+ this.greeting = greeting;
+ }
+
+ public ConstrainingType getConstrainingType() {
+ // The test implementation does not support constrainingTypes
+ return null;
+ }
+
+ public List<Property> getProperties() {
+ // The test implementation does not support properties
+ return Collections.emptyList();
+ }
+
+ public List<Service> getServices() {
+ // The test implementation provides a single fixed Test service
+ return Collections.singletonList(testService);
+ }
+
+ public List<Reference> getReferences() {
+ // The test implementation does not support properties
+ return Collections.emptyList();
+ }
+
+ public String getURI() {
+ // The test implementation does not have a URI
+ return null;
+ }
+
+ public void setConstrainingType(ConstrainingType constrainingType) {
+ // The test implementation does not support constrainingTypes
+ }
+
+ public void setURI(String uri) {
+ // The test implementation does not have a URI
+ }
+
+ public boolean isUnresolved() {
+ // The test implementation is always resolved
+ return false;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ // The test implementation is always resolved
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/impl/TestImplementationProcessor.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/impl/TestImplementationProcessor.java
new file mode 100644
index 0000000000..73feffad50
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/impl/TestImplementationProcessor.java
@@ -0,0 +1,96 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.host.embedded.test.extension.impl;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.host.embedded.test.extension.TestImplementation;
+import org.apache.tuscany.sca.host.embedded.test.extension.TestImplementationFactory;
+
+
+
+/**
+ * Implements a StAX artifact processor for test implementations.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestImplementationProcessor implements StAXArtifactProcessor<TestImplementation> {
+ private static final QName IMPLEMENTATION_TEST = new QName("http://test/extension", "implementation.test");
+
+ private TestImplementationFactory testFactory;
+
+ public TestImplementationProcessor(TestImplementationFactory testFactory) {
+ this.testFactory = testFactory;
+ }
+
+ public QName getArtifactType() {
+ // Returns the QName of the XML element processed by this processor
+ return IMPLEMENTATION_TEST;
+ }
+
+ public Class<TestImplementation> getModelType() {
+ // Returns the type of model processed by this processor
+ return TestImplementation.class;
+ }
+
+ public TestImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+
+ // Read an <implementation.test> element
+
+ // Read the message attribute.
+ String message = reader.getAttributeValue(null, "greeting");
+
+ // Create and initialize the test implementation model
+ TestImplementation implementation = testFactory.createTestImplementation();
+ implementation.setGreeting(message);
+
+ // Skip to end element
+ while (reader.hasNext()) {
+ if (reader.next() == END_ELEMENT && IMPLEMENTATION_TEST.equals(reader.getName())) {
+ break;
+ }
+ }
+
+ return implementation;
+ }
+
+ public void resolve(TestImplementation impl, ModelResolver resolver) throws ContributionResolveException {
+ }
+
+ public void write(TestImplementation implementation, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+
+ writer.writeStartElement(IMPLEMENTATION_TEST.getNamespaceURI(), IMPLEMENTATION_TEST.getLocalPart());
+
+ if (implementation.getGreeting() != null) {
+ writer.writeAttribute("greeting", implementation.getGreeting());
+ }
+
+ writer.writeEndElement();
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/module/TestModuleActivator.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/module/TestModuleActivator.java
new file mode 100644
index 0000000000..f6f077e99b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/module/TestModuleActivator.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.host.embedded.test.extension.module;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ModuleActivator;
+import org.apache.tuscany.sca.host.embedded.test.extension.DefaultTestImplementationFactory;
+import org.apache.tuscany.sca.host.embedded.test.extension.TestImplementationFactory;
+import org.apache.tuscany.sca.host.embedded.test.extension.impl.TestImplementationProcessor;
+import org.apache.tuscany.sca.host.embedded.test.extension.provider.TestImplementationProviderFactory;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
+
+
+
+/**
+ * Implements a module activator for the test implementation extension module.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestModuleActivator implements ModuleActivator {
+
+ public void start(ExtensionPointRegistry registry) {
+
+ // Create the test implementation factory
+ ModelFactoryExtensionPoint modelFactories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ JavaInterfaceFactory javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class);
+ TestImplementationFactory testFactory = new DefaultTestImplementationFactory(assemblyFactory, javaFactory);
+ modelFactories.addFactory(testFactory);
+
+ // Add the test implementation extension to the StAXArtifactProcessor
+ // extension point
+ StAXArtifactProcessorExtensionPoint processors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ TestImplementationProcessor implementationArtifactProcessor = new TestImplementationProcessor(testFactory);
+ processors.addArtifactProcessor(implementationArtifactProcessor);
+
+ // Add the test provider factory to the ProviderFactory extension point
+ ProviderFactoryExtensionPoint providerFactories = registry.getExtensionPoint(ProviderFactoryExtensionPoint.class);
+ providerFactories.addProviderFactory(new TestImplementationProviderFactory());
+ }
+
+ public void stop(ExtensionPointRegistry registry) {
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestImplementationProvider.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestImplementationProvider.java
new file mode 100644
index 0000000000..1d27e08fee
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestImplementationProvider.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.host.embedded.test.extension.provider;
+
+import org.apache.tuscany.sca.host.embedded.test.extension.TestImplementation;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+
+/**
+ * Implementation provider for test implementations.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestImplementationProvider implements ImplementationProvider {
+
+ private RuntimeComponent component;
+ private TestImplementation implementation;
+
+ /**
+ * Constructs a new test implementation provider.
+ */
+ public TestImplementationProvider(RuntimeComponent component, TestImplementation implementation) {
+ this.component = component;
+ this.implementation = implementation;
+ }
+
+ public Invoker createInvoker(RuntimeComponentService service, Operation operation) {
+ TestInvoker invoker = new TestInvoker(operation, implementation.getGreeting());
+ return invoker;
+ }
+
+ public boolean supportsOneWayInvocation() {
+ return false;
+ }
+
+ public void start() {
+ System.out.println("Starting " + component.getName());
+ }
+
+ public void stop() {
+ System.out.println("Stopping " + component.getName());
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestImplementationProviderFactory.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestImplementationProviderFactory.java
new file mode 100644
index 0000000000..15d3618fdd
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestImplementationProviderFactory.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.host.embedded.test.extension.provider;
+
+import org.apache.tuscany.sca.host.embedded.test.extension.TestImplementation;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.provider.ImplementationProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+
+/**
+ * The model representing a test implementation in an SCA assembly model.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestImplementationProviderFactory implements ImplementationProviderFactory<TestImplementation> {
+
+ /**
+ * Constructs a new test implementation provider factory.
+ */
+ public TestImplementationProviderFactory() {
+ }
+
+ public ImplementationProvider createImplementationProvider(RuntimeComponent component, TestImplementation implementation) {
+ return new TestImplementationProvider(component, implementation);
+ }
+
+ public Class<TestImplementation> getModelType() {
+ return TestImplementation.class;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestInvoker.java b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestInvoker.java
new file mode 100644
index 0000000000..d49179dec0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/java/org/apache/tuscany/sca/host/embedded/test/extension/provider/TestInvoker.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.host.embedded.test.extension.provider;
+
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+
+
+/**
+ * Implements an invoker for test component implementations.
+ *
+ * The target invoker is responsible for handling operation invocations.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestInvoker implements Invoker {
+ private Operation operation;
+ private String greeting;
+
+ public TestInvoker(Operation operation, String greeting) {
+ this.operation = operation;
+ this.greeting = greeting;
+ }
+
+ public Message invoke(Message msg) {
+ Object[] args = msg.getBody();
+ if (operation.getName().equals("ping")) {
+ msg.setBody(greeting + " " + args[0]);
+ } else {
+ msg.setFaultBody(new Exception("Operation " + operation.getName() + " is not supported"));
+ }
+ return msg;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator
new file mode 100644
index 0000000000..7e2e11e4cc
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# Implementation class for the ExtensionActivator
+org.apache.tuscany.sca.host.embedded.test.extension.module.TestModuleActivator
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/resources/test.composite b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/resources/test.composite
new file mode 100644
index 0000000000..bd7c5fab79
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/resources/test.composite
@@ -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"
+ targetNamespace="http://test"
+ xmlns:se="http://test"
+ xmlns:e="http://test/extension"
+ name="test">
+
+ <component name="TestServiceComponent">
+ <e:implementation.test greeting="Hello" />
+ </component>
+
+</composite>
diff --git a/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/resources/test.txt b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/resources/test.txt
new file mode 100644
index 0000000000..287f9b1f65
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/host-embedded/src/test/resources/test.txt
@@ -0,0 +1,16 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License. \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/LICENSE b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/META-INF/README b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/NOTICE b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/pom.xml b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/pom.xml
new file mode 100644
index 0000000000..96510ea576
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/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>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-implementation-java-runtime</artifactId>
+ <name>Apache Tuscany SCA Java Implementation Model</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core-spi</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-implementation-java</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-implementation-java-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-databinding</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.implementation.java.runtime</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.implementation.java*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/InstanceFactory.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/InstanceFactory.java
new file mode 100644
index 0000000000..ac8af3ed64
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/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.sca.implementation.java.context;
+
+import org.apache.tuscany.sca.core.context.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/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/InstanceFactoryProvider.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/InstanceFactoryProvider.java
new file mode 100644
index 0000000000..a93710d266
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/InstanceFactoryProvider.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.context;
+
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+
+/**
+ * @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 element the injection site name
+ * @param objectFactory the object factory
+ */
+ void setObjectFactory(JavaElementImpl element, ObjectFactory<?> objectFactory);
+
+ /**
+ * Create an instance factory that can be used to create component instances.
+ *
+ * @return a new instance factory
+ */
+ InstanceFactory<T> createFactory();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceFactory.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceFactory.java
new file mode 100644
index 0000000000..b5d3254fa0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceFactory.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.context;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+import org.apache.tuscany.sca.core.context.InstanceWrapper;
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+import org.apache.tuscany.sca.implementation.java.injection.Injector;
+import org.apache.tuscany.sca.implementation.java.invocation.EventInvoker;
+
+/**
+ * @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) {
+ //FIXME Injectors should never be null
+ if (injector != null)
+ injector.inject(instance);
+ }
+ }
+
+ return new ReflectiveInstanceWrapper<T>(instance, initInvoker, destroyInvoker);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceWrapper.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceWrapper.java
new file mode 100644
index 0000000000..5285caa481
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceWrapper.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.implementation.java.context;
+
+import org.apache.tuscany.sca.core.context.InstanceWrapper;
+import org.apache.tuscany.sca.core.scope.TargetDestructionException;
+import org.apache.tuscany.sca.core.scope.TargetInitializationException;
+import org.apache.tuscany.sca.implementation.java.invocation.EventInvoker;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReflectiveInstanceWrapper<T> implements InstanceWrapper<T> {
+ private final EventInvoker<T> initInvoker;
+ private final EventInvoker<T> destroyInvoker;
+ private final T instance;
+
+ public ReflectiveInstanceWrapper(T instance, EventInvoker<T> initInvoker, EventInvoker<T> destroyInvoker) {
+ this.instance = instance;
+ this.initInvoker = initInvoker;
+ this.destroyInvoker = destroyInvoker;
+ }
+
+ public T getInstance() {
+ return instance;
+ }
+
+ public void start() throws TargetInitializationException {
+ if (initInvoker != null) {
+ initInvoker.invokeEvent(instance);
+ }
+ }
+
+
+ public void stop() throws TargetDestructionException {
+ if (destroyInvoker != null) {
+ destroyInvoker.invokeEvent(instance);
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ArrayMultiplicityObjectFactory.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ArrayMultiplicityObjectFactory.java
new file mode 100644
index 0000000000..2513c63e38
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/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.sca.implementation.java.injection;
+
+import java.lang.reflect.Array;
+import java.util.List;
+
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.factory.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/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ContextInjector.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ContextInjector.java
new file mode 100644
index 0000000000..d8eef18c74
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/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.sca.implementation.java.injection;
+
+import org.apache.tuscany.sca.core.factory.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/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ConversationIDObjectFactory.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ConversationIDObjectFactory.java
new file mode 100644
index 0000000000..ffce7ce467
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ConversationIDObjectFactory.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.injection;
+
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+import org.apache.tuscany.sca.core.invocation.ThreadMessageContext;
+
+/**
+ * Object Factory that is used to retrieve the ConversationID from the
+ * Message on the ThreadMessageContext.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConversationIDObjectFactory implements ObjectFactory {
+
+ public ConversationIDObjectFactory() {
+ }
+
+ public Object getInstance() {
+ return ThreadMessageContext.getMessageContext().getFrom().getReferenceParameters().getConversationID();
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/FieldInjector.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/FieldInjector.java
new file mode 100644
index 0000000000..dd454be7c5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/FieldInjector.java
@@ -0,0 +1,67 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.injection;
+
+import java.lang.reflect.Field;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+
+/**
+ * Injects a value created by an {@link org.apache.tuscany.sca.core.factory.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 pField, ObjectFactory<?> objectFactory) {
+ field = pField;
+ // Allow privileged access to set accessibility. Requires ReflectPermission
+ // in security policy.
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ field.setAccessible(true); // ignore Java accessibility
+ return null;
+ }
+ });
+
+ this.objectFactory = objectFactory;
+ }
+
+ /**
+ * Inject a new value on the given instance
+ */
+ public void inject(T instance) throws ObjectCreationException {
+ try {
+ field.set(instance, objectFactory.getInstance());
+ } catch (IllegalAccessException e) {
+ throw new ObjectCreationException("Field is not accessible [" + field + "]", e);
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InjectionRuntimeException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InjectionRuntimeException.java
new file mode 100644
index 0000000000..4a8c8f31b8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InjectionRuntimeException.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.injection;
+
+
+/**
+ * Root unchecked exception for the injection package
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class InjectionRuntimeException extends RuntimeException {
+
+ public InjectionRuntimeException() {
+ super();
+ }
+
+ public InjectionRuntimeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public InjectionRuntimeException(String message) {
+ super(message);
+ }
+
+ public InjectionRuntimeException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/Injector.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/Injector.java
new file mode 100644
index 0000000000..4d062859b9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/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.sca.implementation.java.injection;
+
+import org.apache.tuscany.sca.core.factory.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/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InvalidAccessorException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InvalidAccessorException.java
new file mode 100644
index 0000000000..5aeebcca36
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/InvalidAccessorException.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.injection;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InvalidAccessorException extends InjectionRuntimeException {
+ private static final long serialVersionUID = 9196299279363310978L;
+
+ public InvalidAccessorException() {
+ super();
+ }
+
+ public InvalidAccessorException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public InvalidAccessorException(String message) {
+ super(message);
+ }
+
+ public InvalidAccessorException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java
new file mode 100644
index 0000000000..695dea3343
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactory.java
@@ -0,0 +1,325 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.injection;
+
+import java.lang.reflect.Array;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import org.apache.tuscany.sca.assembly.ComponentProperty;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.context.PropertyValueFactory;
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+import org.apache.tuscany.sca.databinding.Mediator;
+import org.apache.tuscany.sca.databinding.SimpleTypeMapper;
+import org.apache.tuscany.sca.databinding.impl.DOMHelper;
+import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl;
+import org.apache.tuscany.sca.databinding.xml.DOMDataBinding;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.JavaIntrospectionHelper;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
+import org.apache.tuscany.sca.interfacedef.util.TypeInfo;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaPropertyValueObjectFactory implements PropertyValueFactory {
+ private Mediator mediator = null;
+ private boolean isSimpleType;
+
+ public JavaPropertyValueObjectFactory(Mediator mediator) {
+ this.mediator = mediator;
+ }
+
+ public ObjectFactory createValueFactory(Property property, Object propertyValue, JavaElementImpl javaElement) {
+ isSimpleType = isSimpleType(property);
+ Document doc = (Document)propertyValue;
+ Class javaType = JavaIntrospectionHelper.getBaseType(javaElement.getType(), javaElement.getGenericType());
+ Element rootElement = doc.getDocumentElement();
+ if (property.isMany()) {
+ if (isSimpleType) {
+ String value = "";
+ if (rootElement.getChildNodes().getLength() > 0) {
+ value = rootElement.getChildNodes().item(0).getTextContent();
+ }
+ List<String> values = getSimplePropertyValues(value, javaType);
+ if ( javaElement.getType().isArray() ) {
+ return new ArrayObjectFactoryImpl(property, values, isSimpleType, javaType);
+ } else {
+ return new ListObjectFactoryImpl(property, values, isSimpleType, javaType);
+ }
+ } else {
+ if ( javaElement.getType().isArray() ) {
+ return new ArrayObjectFactoryImpl(property, getComplexPropertyValues(doc), isSimpleType, javaType);
+ } else {
+ return new ListObjectFactoryImpl(property, getComplexPropertyValues(doc), isSimpleType, javaType);
+ }
+ }
+ } else {
+ if (isSimpleType) {
+ String value = "";
+ if (rootElement.getChildNodes().getLength() > 0) {
+ value = rootElement.getChildNodes().item(0).getTextContent();
+ }
+ return new ObjectFactoryImpl(property, value, isSimpleType, javaType);
+ } else {
+ List<Node> nodes = getComplexPropertyValues(doc);
+ Object value = null;
+ if (!nodes.isEmpty()) {
+ value = nodes.get(0);
+ }
+ return new ObjectFactoryImpl(property, value, isSimpleType, javaType);
+ }
+
+ }
+ }
+
+ public ObjectFactory createValueFactory(Property property, Object propertyValue, Class javaType) {
+ isSimpleType = isSimpleType(property);
+ Document doc = (Document)propertyValue;
+ Element rootElement = doc.getDocumentElement();
+ if (property.isMany()) {
+ if (isSimpleType) {
+ String value = "";
+ if (rootElement.getChildNodes().getLength() > 0) {
+ value = rootElement.getChildNodes().item(0).getTextContent();
+ }
+ List<String> values = getSimplePropertyValues(value, javaType);
+ return new ListObjectFactoryImpl(property, values, isSimpleType, javaType);
+ } else {
+ return new ListObjectFactoryImpl(property, getComplexPropertyValues(doc), isSimpleType, javaType);
+ }
+ } else {
+ if (isSimpleType) {
+ String value = "";
+ if (rootElement.getChildNodes().getLength() > 0) {
+ value = rootElement.getChildNodes().item(0).getTextContent();
+ }
+ return new ObjectFactoryImpl(property, value, isSimpleType, javaType);
+ } else {
+ List<Node> nodes = getComplexPropertyValues(doc);
+ Object value = null;
+ if (!nodes.isEmpty()) {
+ value = nodes.get(0);
+ }
+ return new ObjectFactoryImpl(property, value, isSimpleType, javaType);
+ }
+
+ }
+ }
+
+ private boolean isSimpleType(Property property) {
+ if (property.getXSDType() != null) {
+ return SimpleTypeMapperImpl.isSimpleXSDType(property.getXSDType());
+ } else {
+ if (property instanceof Document) {
+ Document doc = (Document)property;
+ Element element = doc.getDocumentElement();
+ if (element.getChildNodes().getLength() == 1 && element.getChildNodes().item(0).getNodeType() == Element.TEXT_NODE) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private List<String> getSimplePropertyValues(String concatenatedValue, Class javaType) {
+ List<String> propValues = new ArrayList<String>();
+ StringTokenizer st = null;
+ if (javaType.getName().equals("java.lang.String")) {
+ st = new StringTokenizer(concatenatedValue, "\"");
+ } else {
+ st = new StringTokenizer(concatenatedValue);
+ }
+ String aToken = null;
+ while (st.hasMoreTokens()) {
+ aToken = st.nextToken();
+ if (aToken.trim().length() > 0) {
+ propValues.add(aToken);
+ }
+ }
+ return propValues;
+ }
+
+ private List<Node> getComplexPropertyValues(Document document) {
+ Element rootElement = document.getDocumentElement();
+ List<Node> propValues = new ArrayList<Node>();
+ NodeList nodes = rootElement.getChildNodes();
+ for (int count = 0; count < nodes.getLength(); ++count) {
+ if (nodes.item(count).getNodeType() == Document.ELEMENT_NODE) {
+ propValues.add(DOMHelper.promote(nodes.item(count)));
+ }
+ }
+ return propValues;
+ }
+
+ public abstract class ObjectFactoryImplBase implements ObjectFactory {
+ protected SimpleTypeMapper simpleTypeMapper = new SimpleTypeMapperImpl();
+ protected Property property;
+ protected Object propertyValue;
+ protected Class javaType;
+ protected DataType<XMLType> sourceDataType;
+ protected DataType<?> targetDataType;
+ boolean isSimpleType;
+
+ public ObjectFactoryImplBase(Property property, Object propertyValue, boolean isSimpleType, Class javaType) {
+ this.isSimpleType = isSimpleType;
+ this.property = property;
+ this.propertyValue = propertyValue;
+ this.javaType = javaType;
+ sourceDataType = new DataTypeImpl<XMLType>(DOMDataBinding.NAME, Node.class, new XMLType(null, this.property
+ .getXSDType()));
+ TypeInfo typeInfo = null;
+ if (this.property.getXSDType() != null) {
+ if (SimpleTypeMapperImpl.isSimpleXSDType(this.property.getXSDType())) {
+ typeInfo = new TypeInfo(property.getXSDType(), true, null);
+ } else {
+ typeInfo = new TypeInfo(property.getXSDType(), false, null);
+ }
+ } else {
+ typeInfo = new TypeInfo(property.getXSDType(), false, null);
+ }
+
+ XMLType xmlType = new XMLType(typeInfo);
+ String dataBinding = null; // (String)property.getExtensions().get(DataBinding.class.getName());
+ if (dataBinding != null) {
+ targetDataType = new DataTypeImpl<XMLType>(dataBinding, javaType, xmlType);
+ } else {
+ targetDataType = new DataTypeImpl<XMLType>(dataBinding, javaType, xmlType);
+ mediator.getDataBindings().introspectType(targetDataType, null);
+ }
+ }
+ }
+
+ public class ObjectFactoryImpl extends ObjectFactoryImplBase {
+ public ObjectFactoryImpl(Property property, Object propertyValue, boolean isSimpleType, Class javaType) {
+ super(property, propertyValue, isSimpleType, javaType);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object getInstance() throws ObjectCreationException {
+ if (isSimpleType) {
+ try {
+ return simpleTypeMapper.toJavaObject(property.getXSDType(), (String)propertyValue, null);
+ } catch (NumberFormatException ex) {
+ throw new ObjectCreationException("Failed to create instance for property "
+ + property.getName() + " with value " + propertyValue, ex);
+ } catch (IllegalArgumentException ex) {
+ throw new ObjectCreationException("Failed to create instance for property "
+ + property.getName() + " with value " + propertyValue, ex);
+ }
+ } else {
+ return mediator.mediate(propertyValue, sourceDataType, targetDataType, null);
+ // return null;
+ }
+ }
+ }
+
+ public class ListObjectFactoryImpl extends ObjectFactoryImplBase {
+ public ListObjectFactoryImpl(Property property, List<?> propertyValues, boolean isSimpleType, Class javaType) {
+ super(property, propertyValues, isSimpleType, javaType);
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<?> getInstance() throws ObjectCreationException {
+ if (isSimpleType) {
+ List<Object> values = new ArrayList<Object>();
+ for (String aValue : (List<String>)propertyValue) {
+ try {
+ values.add(simpleTypeMapper.toJavaObject(property.getXSDType(), aValue, null));
+ } catch (NumberFormatException ex) {
+ throw new ObjectCreationException("Failed to create instance for property "
+ + property.getName() + " with value " + aValue
+ + " from value list of " + propertyValue, ex);
+ } catch (IllegalArgumentException ex) {
+ throw new ObjectCreationException("Failed to create instance for property "
+ + property.getName() + " with value " + aValue
+ + " from value list of " + propertyValue, ex);
+ }
+ }
+ return values;
+ } else {
+ List instances = new ArrayList();
+ for (Node aValue : (List<Node>)propertyValue) {
+ instances.add(mediator.mediate(aValue, sourceDataType, targetDataType, null));
+ }
+ return instances;
+ }
+ }
+ }
+
+ public class ArrayObjectFactoryImpl extends ObjectFactoryImplBase {
+ public ArrayObjectFactoryImpl(Property property, List<?> propertyValues, boolean isSimpleType, Class javaType) {
+ super(property, propertyValues, isSimpleType, javaType);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Object getInstance() throws ObjectCreationException {
+ if (isSimpleType) {
+ int count = 0;
+ Object values = Array.newInstance(javaType, ((List<Object>)propertyValue).size());
+ for (String aValue : (List<String>)propertyValue) {
+ try {
+ Array.set(values, count++, simpleTypeMapper.toJavaObject(property.getXSDType(), aValue, null));
+ } catch (NumberFormatException ex) {
+ throw new ObjectCreationException("Failed to create instance for property "
+ + property.getName() + " with value " + aValue
+ + " from value list of " + propertyValue, ex);
+ } catch (IllegalArgumentException ex) {
+ throw new ObjectCreationException("Failed to create instance for property "
+ + property.getName() + " with value " + aValue
+ + " from value list of " + propertyValue, ex);
+ }
+ }
+ return values;
+ } else {
+ Object instances = Array.newInstance(javaType, ((List<Object>)propertyValue).size());
+ int count = 0;
+ for (Node aValue : (List<Node>)propertyValue) {
+ Array.set(instances, count++, mediator.mediate(aValue, sourceDataType, targetDataType, null));
+ }
+ return instances;
+ }
+ }
+ }
+
+ /**
+ * This method will create an instance of the value for the specified Property.
+ *
+ * @param property The Property from which to retrieve the property value
+ * @param type The type of the property value being retrieved from the Property
+ * @param <B> Type type of the property value being looked up
+ *
+ * @return the value for the Property
+ */
+ public <B> B createPropertyValue(ComponentProperty property, Class<B> type)
+ {
+ ObjectFactory<B> factory = this.createValueFactory(property, property.getValue(), type);
+ return factory.getInstance();
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ListMultiplicityObjectFactory.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ListMultiplicityObjectFactory.java
new file mode 100644
index 0000000000..9f587f58de
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/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.sca.implementation.java.injection;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.factory.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/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/MethodInjector.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/MethodInjector.java
new file mode 100644
index 0000000000..baf9eb9cc1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/MethodInjector.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.injection;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+
+/**
+ * Injects a value created by an {@link org.apache.tuscany.sca.core.factory.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 aMethod, ObjectFactory<?> objectFactory) {
+ assert aMethod != null;
+ assert objectFactory != null;
+ this.method = aMethod;
+ // Allow privileged access to set accessibility. Requires ReflectPermission in security
+ // policy.
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ method.setAccessible(true);
+ return null;
+ }
+ });
+ this.objectFactory = objectFactory;
+ }
+
+ public void inject(T instance) throws ObjectCreationException {
+ try {
+ method.invoke(instance, objectFactory.getInstance());
+ } catch (IllegalAccessException e) {
+ throw new ObjectCreationException("Method is not accessible [" + method + "]", e);
+ } 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/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/RequestContextObjectFactory.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/RequestContextObjectFactory.java
new file mode 100644
index 0000000000..ca9c08fe63
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/RequestContextObjectFactory.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.injection;
+
+import org.apache.tuscany.sca.context.RequestContextFactory;
+import org.apache.tuscany.sca.core.context.RequestContextImpl;
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.osoa.sca.RequestContext;
+
+/**
+ * Creates instances of
+ * {@link org.apache.tuscany.sca.core.context.RequestContextImpl} for
+ * injection on component implementation instances
+ *
+ * @version $Rev$ $Date$
+ */
+public class RequestContextObjectFactory implements ObjectFactory<RequestContext> {
+ private RequestContextFactory factory;
+ private ProxyFactory proxyFactory;
+
+ public RequestContextObjectFactory(RequestContextFactory factory) {
+ this(factory, null);
+ }
+
+ public RequestContextObjectFactory(RequestContextFactory factory, ProxyFactory proxyFactory) {
+ this.factory = factory;
+ this.proxyFactory = proxyFactory;
+ }
+
+ public RequestContext getInstance() throws ObjectCreationException {
+ if (factory != null) {
+ return factory.createRequestContext();
+ } else {
+ return new RequestContextImpl(proxyFactory);
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceHost.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceHost.java
new file mode 100644
index 0000000000..70c368a0e6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/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.sca.implementation.java.injection;
+
+/**
+ * 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/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceNotFoundException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceNotFoundException.java
new file mode 100644
index 0000000000..17450f43cb
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceNotFoundException.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.injection;
+
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+
+/**
+ * Denotes an exception thrown when a runtime resource is not found
+ *
+ * @version $Rev$ $Date$
+ */
+public class ResourceNotFoundException extends ObjectCreationException {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+ public ResourceNotFoundException() {
+ super();
+ }
+
+ public ResourceNotFoundException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ResourceNotFoundException(String message) {
+ super(message);
+ }
+
+ public ResourceNotFoundException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceObjectFactory.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceObjectFactory.java
new file mode 100644
index 0000000000..5d4d999453
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceObjectFactory.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.injection;
+
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+
+/**
+ * Resolves a runtime resource to be injected on a field or method of a Java component type marked with {@link
+ * javax.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/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceResolutionException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceResolutionException.java
new file mode 100644
index 0000000000..f94b24762a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/injection/ResourceResolutionException.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.injection;
+
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ResourceResolutionException extends Exception {
+ private static final long serialVersionUID = 13421352711315479L;
+
+ public ResourceResolutionException() {
+ super();
+ }
+
+ public ResourceResolutionException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public ResourceResolutionException(String message) {
+ super(message);
+ }
+
+ public ResourceResolutionException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/EventInvocationException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/EventInvocationException.java
new file mode 100644
index 0000000000..25c09231c5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/EventInvocationException.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.invocation;
+
+import org.apache.tuscany.sca.implementation.java.injection.InjectionRuntimeException;
+
+/**
+ * Denotes an error when invoking an event on an object
+ *
+ * @version $Rev$ $Date$
+ */
+public class EventInvocationException extends InjectionRuntimeException {
+ private static final long serialVersionUID = 1480018831708211581L;
+
+ public EventInvocationException() {
+ super();
+ }
+
+ public EventInvocationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public EventInvocationException(String message) {
+ super(message);
+ }
+
+ public EventInvocationException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/EventInvoker.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/EventInvoker.java
new file mode 100644
index 0000000000..e6ebb5abc3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/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.sca.implementation.java.invocation;
+
+/**
+ * Performs an invocation on an instance
+ *
+ * @version $Rev$ $Date$
+ */
+public interface EventInvoker<T> {
+
+ /**
+ * Performs the invocation on a given instance
+ *
+ * @throws EventInvocationException
+ */
+ void invokeEvent(T instance) throws EventInvocationException;
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/InvalidConversationSequenceException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/InvalidConversationSequenceException.java
new file mode 100644
index 0000000000..135fde09ff
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/InvalidConversationSequenceException.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.invocation;
+
+import org.apache.tuscany.sca.core.invocation.TargetInvocationException;
+
+/**
+ * Denotes an unknown operation sequence in a conversation
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidConversationSequenceException extends TargetInvocationException {
+ private static final long serialVersionUID = -5744028391493899147L;
+
+ public InvalidConversationSequenceException() {
+ super();
+ }
+
+ public InvalidConversationSequenceException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public InvalidConversationSequenceException(String message) {
+ super(message);
+ }
+
+ public InvalidConversationSequenceException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaCallbackRuntimeWireProcessor.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaCallbackRuntimeWireProcessor.java
new file mode 100644
index 0000000000..ef4e67d79a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaCallbackRuntimeWireProcessor.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.java.invocation;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.apache.tuscany.sca.assembly.Contract;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.core.invocation.CallbackInterfaceInterceptor;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.apache.tuscany.sca.runtime.RuntimeWireProcessor;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaCallbackRuntimeWireProcessor implements RuntimeWireProcessor {
+ private static final Logger logger = Logger.getLogger(JavaCallbackRuntimeWireProcessor.class.getName());
+ private InterfaceContractMapper interfaceContractMapper;
+ private JavaInterfaceFactory javaInterfaceFactory;
+
+ /**
+ * @param interfaceContractMapper
+ * @param javaInterfaceFactory
+ */
+ public JavaCallbackRuntimeWireProcessor(InterfaceContractMapper interfaceContractMapper,
+ JavaInterfaceFactory javaInterfaceFactory) {
+ super();
+ this.interfaceContractMapper = interfaceContractMapper;
+ this.javaInterfaceFactory = javaInterfaceFactory;
+ }
+
+ public void process(RuntimeWire wire) {
+ addCallbackInterfaceInterceptors(wire);
+ }
+
+ private void addCallbackInterfaceInterceptors(RuntimeWire wire) {
+ Contract contract = wire.getSource().getContract();
+ if (!(contract instanceof RuntimeComponentReference)) {
+ return;
+ }
+ RuntimeComponent component = wire.getSource().getComponent();
+ Implementation implementation = component.getImplementation();
+ if (!(implementation instanceof JavaImplementation)) {
+ return;
+ }
+ JavaImplementation javaImpl = (JavaImplementation)implementation;
+ EndpointReference callbackEndpoint = wire.getSource().getCallbackEndpoint();
+ if (callbackEndpoint != null) {
+ Interface iface = callbackEndpoint.getContract().getInterfaceContract().getInterface();
+ if (!supportsCallbackInterface(iface, javaImpl)) {
+ // callback to this impl is not possible, so ensure a callback object is set
+ for (InvocationChain chain : wire.getInvocationChains()) {
+ chain.addInterceptor(Phase.REFERENCE, new CallbackInterfaceInterceptor());
+ }
+ }
+ }
+ }
+
+ private boolean supportsCallbackInterface(Interface iface, JavaImplementation impl) {
+ if (iface instanceof JavaInterface) {
+ Class<?> ifaceClass = ((JavaInterface)iface).getJavaClass();
+ if (ifaceClass.isAssignableFrom(impl.getJavaClass())) {
+ return true;
+ }
+ }
+ try {
+ Interface implType = javaInterfaceFactory.createJavaInterface(impl.getJavaClass());
+ // Ignore the remotable/conversational testing
+ implType.setRemotable(iface.isRemotable());
+ implType.setConversational(iface.isConversational());
+ return interfaceContractMapper.isCompatible(iface, implType);
+ } catch (InvalidInterfaceException e) {
+ logger.log(Level.WARNING, e.getMessage(), e);
+ return false;
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextFactory.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextFactory.java
new file mode 100644
index 0000000000..2903cc6fc8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextFactory.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.invocation;
+
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+import org.osoa.sca.ComponentContext;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaComponentContextFactory implements ObjectFactory<ComponentContext> {
+ private final JavaComponentContextProvider component;
+
+
+ public JavaComponentContextFactory(JavaComponentContextProvider component) {
+ this.component = component;
+ }
+
+
+ public ComponentContext getInstance() throws ObjectCreationException {
+ return component.getComponent().getComponentContext();
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java
new file mode 100644
index 0000000000..e585b3d46f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentContextProvider.java
@@ -0,0 +1,404 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.invocation;
+
+import java.lang.annotation.ElementType;
+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.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.sca.assembly.ComponentProperty;
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Multiplicity;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.context.ComponentContextFactory;
+import org.apache.tuscany.sca.context.RequestContextFactory;
+import org.apache.tuscany.sca.core.context.ComponentContextImpl;
+import org.apache.tuscany.sca.core.context.InstanceWrapper;
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+import org.apache.tuscany.sca.core.invocation.CallableReferenceObjectFactory;
+import org.apache.tuscany.sca.core.invocation.CallbackReferenceObjectFactory;
+import org.apache.tuscany.sca.core.invocation.CallbackWireObjectFactory;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.core.invocation.WireObjectFactory;
+import org.apache.tuscany.sca.core.scope.ScopeContainer;
+import org.apache.tuscany.sca.core.scope.TargetResolutionException;
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.implementation.java.impl.JavaConstructorImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaResourceImpl;
+import org.apache.tuscany.sca.implementation.java.injection.ConversationIDObjectFactory;
+import org.apache.tuscany.sca.implementation.java.injection.InvalidAccessorException;
+import org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.JavaIntrospectionHelper;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.annotations.ConversationID;
+
+/**
+ * The runtime instantiation of Java component implementations
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaComponentContextProvider {
+ private JavaPropertyValueObjectFactory propertyValueFactory;
+ private DataBindingExtensionPoint dataBindingRegistry;
+ private RuntimeComponent component;
+ private JavaInstanceFactoryProvider<?> instanceFactoryProvider;
+ private ProxyFactory proxyFactory;
+
+ public JavaComponentContextProvider(RuntimeComponent component,
+ JavaInstanceFactoryProvider configuration,
+ DataBindingExtensionPoint dataBindingExtensionPoint,
+ JavaPropertyValueObjectFactory propertyValueObjectFactory,
+ ComponentContextFactory componentContextFactory,
+ RequestContextFactory requestContextFactory) {
+ super();
+ this.instanceFactoryProvider = configuration;
+ this.proxyFactory = configuration.getProxyFactory();
+ // if (componentContextFactory != null) {
+ // this.componentContext = componentContextFactory.createComponentContext(component, requestContextFactory);
+ // } else {
+ // this.componentContext = new ComponentContextImpl(this, requestContextFactory, this.proxyService);
+ // }
+ this.component = component;
+ this.dataBindingRegistry = dataBindingExtensionPoint;
+ this.propertyValueFactory = propertyValueObjectFactory;
+ }
+
+ InstanceWrapper<?> createInstanceWrapper() throws ObjectCreationException {
+ return instanceFactoryProvider.createFactory().newInstance();
+ }
+
+ void configureProperties(List<ComponentProperty> definedProperties) {
+ for (ComponentProperty p : definedProperties) {
+ configureProperty(p);
+ }
+ }
+
+ private void configureProperty(ComponentProperty configuredProperty) {
+ JavaElementImpl element =
+ instanceFactoryProvider.getImplementation().getPropertyMembers().get(configuredProperty.getName());
+
+ if (element != null && configuredProperty.getValue() != null) {
+ if (!(element.getAnchor() instanceof Constructor)) {
+ if(element.getElementType() == ElementType.FIELD) {
+ // Field field = (Field)element.getAnchor();
+ instanceFactoryProvider.getInjectionSites().add(element);
+ /*
+ if(Modifier.isPublic(field.getModifiers())) {
+ instanceFactoryProvider.getInjectionSites().add(element);
+ } else if(field.getAnnotation(org.osoa.sca.annotations.Property.class) != null) {
+ instanceFactoryProvider.getInjectionSites().add(element);
+ }
+ */
+ } else {
+ instanceFactoryProvider.getInjectionSites().add(element);
+ }
+ }
+
+ //Class propertyJavaType = JavaIntrospectionHelper.getBaseType(element.getType(), element.getGenericType());
+ ObjectFactory<?> propertyObjectFactory =
+ createPropertyValueFactory(configuredProperty, configuredProperty.getValue(), element);
+ instanceFactoryProvider.setObjectFactory(element, propertyObjectFactory);
+
+ JavaConstructorImpl constructor = instanceFactoryProvider.getImplementation().getConstructor();
+ for(JavaElementImpl p: constructor.getParameters()){
+ if(element.getName().equals(p.getName())) {
+ instanceFactoryProvider.setObjectFactory(p, propertyObjectFactory);
+ }
+ }
+ }
+ }
+
+ void start() {
+ if (!instanceFactoryProvider.getImplementation().getCallbackMembers().isEmpty()) {
+ Map<String, List<RuntimeWire>> callbackWires = new HashMap<String, List<RuntimeWire>>();
+ for (ComponentService service : component.getServices()) {
+
+ RuntimeComponentReference callbackReference = (RuntimeComponentReference)service.getCallbackReference();
+ if (callbackReference != null) {
+ List<RuntimeWire> wires = callbackReference.getRuntimeWires();
+ if (!wires.isEmpty()) {
+ callbackWires.put(wires.get(0).getSource().getInterfaceContract().getInterface().toString(),
+ wires);
+ }
+ }
+ }
+
+ for (Map.Entry<String, Collection<JavaElementImpl>> entry : instanceFactoryProvider.getImplementation()
+ .getCallbackMembers().entrySet()) {
+ List<RuntimeWire> 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;
+ }
+ for(JavaElementImpl element : entry.getValue()) {
+ Class<?> businessInterface = element.getType();
+ ObjectFactory<?> factory = null;
+ if (CallableReference.class.isAssignableFrom(element.getType())) {
+ businessInterface =
+ JavaIntrospectionHelper.getBusinessInterface(element.getType(), element.getGenericType());
+ factory =
+ new CallbackReferenceObjectFactory(businessInterface, proxyFactory, wires);
+ } else {
+ factory = new CallbackWireObjectFactory(businessInterface, proxyFactory, wires);
+ }
+ if (!(element.getAnchor() instanceof Constructor)) {
+ instanceFactoryProvider.getInjectionSites().add(element);
+ }
+ instanceFactoryProvider.setObjectFactory(element, factory);
+ }
+ }
+ }
+ for (Reference ref : instanceFactoryProvider.getImplementation().getReferences()) {
+ JavaElementImpl element =
+ instanceFactoryProvider.getImplementation().getReferenceMembers().get(ref.getName());
+ if (element != null) {
+ if (!(element.getAnchor() instanceof Constructor)) {
+ if(element.getElementType() == ElementType.FIELD) {
+ Field field = (Field)element.getAnchor();
+ if(Modifier.isPublic(field.getModifiers())) {
+ instanceFactoryProvider.getInjectionSites().add(element);
+ } else if(field.getAnnotation(org.osoa.sca.annotations.Reference.class) != null) {
+ instanceFactoryProvider.getInjectionSites().add(element);
+ }
+ } else {
+ instanceFactoryProvider.getInjectionSites().add(element);
+ }
+ }
+ ComponentReference componentReference = null;
+ List<RuntimeWire> wireList = null;
+ for (ComponentReference reference : component.getReferences()) {
+ if (reference.getName().equals(ref.getName())) {
+ wireList = ((RuntimeComponentReference)reference).getRuntimeWires();
+ componentReference = reference;
+ break;
+ }
+ }
+ if (ref.getMultiplicity() == Multiplicity.ONE_N || ref.getMultiplicity() == Multiplicity.ZERO_N) {
+ List<ObjectFactory<?>> factories = new ArrayList<ObjectFactory<?>>();
+ Class<?> baseType =
+ JavaIntrospectionHelper.getBaseType(element.getType(), element.getGenericType());
+ for (int i = 0; i < wireList.size(); i++) {
+ ObjectFactory<?> factory = null;
+ if (CallableReference.class.isAssignableFrom(baseType)) {
+ Type callableRefType = JavaIntrospectionHelper.getParameterType(element.getGenericType());
+ // Type businessType = JavaIntrospectionHelper.getParameterType(callableRefType);
+ Class<?> businessInterface =
+ JavaIntrospectionHelper.getBusinessInterface(baseType, callableRefType);
+ factory =
+ new CallableReferenceObjectFactory(businessInterface, component,
+ (RuntimeComponentReference)wireList.get(i)
+ .getSource().getContract(), wireList.get(i)
+ .getSource().getBinding());
+ } else {
+ factory = createObjectFactory(baseType, wireList.get(i));
+ }
+ factories.add(factory);
+ }
+ instanceFactoryProvider.setObjectFactories(element, factories);
+ JavaConstructorImpl constructor = instanceFactoryProvider.getImplementation().getConstructor();
+ for(JavaElementImpl p: constructor.getParameters()){
+ if(element.getName().equals(p.getName())) {
+ instanceFactoryProvider.setObjectFactories(p, factories);
+ }
+ }
+ } else {
+ if (wireList == null && ref.getMultiplicity() == Multiplicity.ONE_ONE) {
+ throw new IllegalStateException("Required reference is missing: " + ref.getName());
+ }
+ if (wireList != null && !wireList.isEmpty()) {
+ ObjectFactory<?> factory = null;
+ if (CallableReference.class.isAssignableFrom(element.getType())) {
+ Class<?> businessInterface =
+ JavaIntrospectionHelper.getBusinessInterface(element.getType(), element
+ .getGenericType());
+ factory =
+ new CallableReferenceObjectFactory(businessInterface, component,
+ (RuntimeComponentReference)componentReference, null);
+ } else {
+ factory = createObjectFactory(element.getType(), wireList.get(0));
+ }
+ instanceFactoryProvider.setObjectFactory(element, factory);
+ JavaConstructorImpl constructor = instanceFactoryProvider.getImplementation().getConstructor();
+ for(JavaElementImpl p: constructor.getParameters()){
+ if(element.getName().equals(p.getName())) {
+ instanceFactoryProvider.setObjectFactory(p, factory);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ // We need to set the PropertyValueFactory on the ComponentContextImpl
+ // so the ComponentContext can "de-marshal" the property type to a value
+ // when the getProperty() method is called
+ ComponentContextImpl ccImpl = (ComponentContextImpl)component.getComponentContext();
+ ccImpl.setPropertyValueFactory(propertyValueFactory);
+
+ //setUpPolicyHandlers();
+ }
+
+ void addResourceFactory(String name, ObjectFactory<?> factory) {
+ JavaResourceImpl resource = instanceFactoryProvider.getImplementation().getResources().get(name);
+
+ if (resource != null && !(resource.getElement().getAnchor() instanceof Constructor)) {
+ instanceFactoryProvider.getInjectionSites().add(resource.getElement());
+ }
+
+ instanceFactoryProvider.setObjectFactory(resource.getElement(), factory);
+ }
+
+ void addConversationIDFactories(List<Member> names) {
+ ObjectFactory<String> factory = new ConversationIDObjectFactory();
+ for (Member name : names) {
+ if (name instanceof Field) {
+ JavaElementImpl element = new JavaElementImpl((Field)name);
+ element.setClassifer(ConversationID.class);
+ instanceFactoryProvider.setObjectFactory(element, factory);
+ } else if (name instanceof Method) {
+ JavaElementImpl element = new JavaElementImpl((Method)name, 0);
+ element.setName(JavaIntrospectionHelper.toPropertyName(name.getName()));
+ element.setClassifer(ConversationID.class);
+ instanceFactoryProvider.setObjectFactory(element, factory);
+ } else {
+ throw new InvalidAccessorException("Member must be a field or method: " + name.getName());
+ }
+ }
+ }
+
+ Object createInstance() throws ObjectCreationException {
+ return createInstanceWrapper().getInstance();
+ }
+
+ JavaInstanceFactoryProvider<?> getInstanceFactoryProvider() {
+ return instanceFactoryProvider;
+ }
+
+ void stop() {
+ //cleanUpPolicyHandlers();
+ }
+
+ Invoker createInvoker(Operation operation) throws NoSuchMethodException {
+ Class<?> implClass = instanceFactoryProvider.getImplementationClass();
+
+ Method method = JavaInterfaceUtil.findMethod(implClass, operation);
+ return new JavaImplementationInvoker(operation, method, component);
+ }
+
+ private static class OptimizedObjectFactory<T> implements ObjectFactory<T> {
+ private ScopeContainer scopeContainer;
+
+ public OptimizedObjectFactory(ScopeContainer scopeContainer) {
+ super();
+ this.scopeContainer = scopeContainer;
+ }
+
+ public T getInstance() throws ObjectCreationException {
+ try {
+ return (T)scopeContainer.getWrapper(null).getInstance();
+ } catch (TargetResolutionException e) {
+ throw new ObjectCreationException(e);
+ }
+ }
+
+ }
+
+ private <B> ObjectFactory<B> createObjectFactory(Class<B> interfaze, RuntimeWire wire) {
+ // FIXME: [rfeng] Disable the optimization for new as it needs more discussions
+ /*
+ boolean conversational = wire.getSource().getInterfaceContract().getInterface().isConversational();
+ Binding binding = wire.getSource().getBinding();
+ // Check if it's wireable binding for optimization
+ if (!conversational && binding instanceof OptimizableBinding) {
+ OptimizableBinding optimizableBinding = (OptimizableBinding)binding;
+ Component component = optimizableBinding.getTargetComponent();
+ if (component != null) {
+ Implementation implementation = component.getImplementation();
+ // Check if the target component is java component
+ if (implementation instanceof JavaImplementation) {
+ JavaImplementation javaImplementation = (JavaImplementation)implementation;
+ if (interfaze.isAssignableFrom(javaImplementation.getJavaClass())) {
+ ScopedRuntimeComponent scopedComponent = (ScopedRuntimeComponent)component;
+ ScopeContainer scopeContainer = scopedComponent.getScopeContainer();
+ Scope scope = scopeContainer.getScope();
+ if (scope == Scope.COMPOSITE || scope == Scope.STATELESS || scope == Scope.SYSTEM) {
+ boolean optimizable = true;
+ for (InvocationChain chain : wire.getInvocationChains()) {
+ if (chain.getHeadInvoker() != chain.getTailInvoker()) {
+ optimizable = false;
+ break;
+ }
+ }
+ if (optimizable) {
+ return new OptimizedObjectFactory<B>(scopeContainer);
+ }
+ }
+ }
+ }
+ }
+ }
+ */
+ return new WireObjectFactory<B>(interfaze, wire, proxyFactory);
+ }
+
+ private ObjectFactory<?> createPropertyValueFactory(ComponentProperty property,
+ Object propertyValue,
+ JavaElementImpl javaElement) {
+ return propertyValueFactory.createValueFactory(property, propertyValue, javaElement);
+ }
+
+ /**
+ * @return the component
+ */
+ RuntimeComponent getComponent() {
+ return component;
+ }
+
+ /*private void setUpPolicyHandlers() {
+ for (PolicyHandler policyHandler : policyHandlers.values()) {
+ policyHandler.setUp(component.getImplementation());
+ }
+ }
+
+ private void cleanUpPolicyHandlers() {
+ for (PolicyHandler policyHandler : policyHandlers.values() ) {
+ policyHandler.cleanUp(this);
+ }
+ }*/
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentNameFactory.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentNameFactory.java
new file mode 100644
index 0000000000..4a5ad98e5b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaComponentNameFactory.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.invocation;
+
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaComponentNameFactory implements ObjectFactory<String> {
+ private final JavaComponentContextProvider componentContextProvider;
+
+
+ public JavaComponentNameFactory(JavaComponentContextProvider component) {
+ this.componentContextProvider = component;
+ }
+
+
+ public String getInstance() throws ObjectCreationException {
+ String uri = componentContextProvider.getComponent().getURI();
+ return uri.substring(uri.lastIndexOf('/')+1);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java
new file mode 100644
index 0000000000..25d538cff4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationInvoker.java
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.invocation;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.sca.core.context.InstanceWrapper;
+import org.apache.tuscany.sca.core.scope.Scope;
+import org.apache.tuscany.sca.core.scope.ScopeContainer;
+import org.apache.tuscany.sca.core.scope.ScopedRuntimeComponent;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.interfacedef.ConversationSequence;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil;
+import org.apache.tuscany.sca.invocation.DataExchangeSemantics;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.EndpointReference;
+import org.apache.tuscany.sca.runtime.ReferenceParameters;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * Responsible for synchronously dispatching an invocation to a Java component
+ * implementation instance
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaImplementationInvoker implements Invoker, DataExchangeSemantics {
+ protected Operation operation;
+ protected Method method;
+ protected boolean allowsPBR;
+
+ @SuppressWarnings("unchecked")
+ protected final ScopeContainer scopeContainer;
+
+ public JavaImplementationInvoker(Operation operation, Method method, RuntimeComponent component) {
+ assert method != null : "Operation method cannot be null";
+ this.method = method;
+ this.operation = operation;
+ this.scopeContainer = ((ScopedRuntimeComponent)component).getScopeContainer();
+ this.allowsPBR = ((JavaImplementation)component.getImplementation()).isAllowsPassByReference(method);
+ }
+
+ public JavaImplementationInvoker(Operation operation, RuntimeComponent component) {
+ // used if the method can't be computed statically in advance
+ this.operation = operation;
+ this.scopeContainer = ((ScopedRuntimeComponent)component).getScopeContainer();
+ }
+
+ @SuppressWarnings("unchecked")
+ public Message invoke(Message msg) {
+ Operation op = msg.getOperation();
+ if (op == null) {
+ op = this.operation;
+ }
+ ConversationSequence sequence = op.getConversationSequence();
+ Object payload = msg.getBody();
+
+ Object contextId = null;
+
+ EndpointReference from = msg.getFrom();
+ ReferenceParameters parameters = null;
+ if (from != null) {
+ parameters = from.getReferenceParameters();
+ }
+ // check what sort of context is required
+ if (scopeContainer != null) {
+ Scope scope = scopeContainer.getScope();
+ if (scope == Scope.REQUEST) {
+ contextId = Thread.currentThread();
+ } else if (scope == Scope.CONVERSATION && parameters != null) {
+ contextId = parameters.getConversationID();
+ }
+ }
+
+ try {
+ // The following call might create a new conversation, as a result, the msg.getConversationID() might
+ // return a new value
+ InstanceWrapper wrapper = scopeContainer.getWrapper(contextId);
+
+ // detects whether the scope container has created a conversation Id. This will
+ // happen in the case that the component has conversational scope but only the
+ // callback interface is conversational. Or in the callback case if the service interface
+ // is conversational and the callback interface isn't. If we are in this situation we need
+ // to get the contextId of this component and remove it after we have invoked the method on
+ // it. It is possible that the component instance will not go away when it is removed below
+ // because a callback conversation will still be holding a reference to it
+ boolean removeTemporaryConversationalComponentAfterCall = false;
+ if (parameters != null && (contextId == null) && (parameters.getConversationID() != null)) {
+ contextId = parameters.getConversationID();
+ removeTemporaryConversationalComponentAfterCall = true;
+ }
+
+ Object instance = wrapper.getInstance();
+
+ // If the method couldn't be computed statically, or the instance being
+ // invoked is a user-specified callback object that doesn't implement
+ // the service interface from which the reflective method was obtained,
+ // compute the method object dynamically for this invocation.
+ Method imethod = method;
+ if (imethod == null || !imethod.getDeclaringClass().isInstance(instance)) {
+ try {
+ imethod = JavaInterfaceUtil.findMethod(instance.getClass(), operation);
+ } catch (NoSuchMethodException e) {
+ throw new IllegalArgumentException("Callback object does not provide method " + e.getMessage());
+ }
+ }
+
+ Object ret;
+ if (payload != null && !payload.getClass().isArray()) {
+ ret = imethod.invoke(instance, payload);
+ } else {
+ ret = imethod.invoke(instance, (Object[])payload);
+ }
+
+ scopeContainer.returnWrapper(wrapper, contextId);
+
+ if ((sequence == ConversationSequence.CONVERSATION_END) || (removeTemporaryConversationalComponentAfterCall)) {
+ // if end conversation, or we have the special case where a conversational
+ // object was created to service the stateless half of a stateful component
+ scopeContainer.remove(contextId);
+ parameters.setConversationID(null);
+ }
+ msg.setBody(ret);
+ } catch (InvocationTargetException e) {
+ Throwable cause = e.getTargetException();
+ boolean isChecked = false;
+ for (DataType<?> d : operation.getFaultTypes()) {
+ if (d.getPhysical().isInstance(cause)) {
+ isChecked = true;
+ msg.setFaultBody(cause);
+ break;
+ }
+ }
+
+
+ if (sequence != ConversationSequence.CONVERSATION_NONE ){
+ try {
+// // If the exception is not a business exception then end the conversation
+// boolean businessException = false;
+//
+// for (DataType dataType : operation.getFaultTypes()){
+// if ((dataType.getPhysical() == e.getCause().getClass()) &&
+// (contextId != null) ){
+// businessException = true;
+// break;
+// }
+// }
+
+ if (!isChecked && contextId != null) {
+ scopeContainer.remove(contextId);
+ parameters.setConversationID(null);
+ }
+ } catch (Exception ex){
+ // TODO - sure what the best course of action is here. We have
+ // a system exception in the middle of a business exception
+ }
+ }
+ if (!isChecked) {
+ if (cause instanceof RuntimeException) {
+ throw (RuntimeException)cause;
+ }
+ if (cause instanceof Error) {
+ throw (Error)cause;
+ } else {
+ throw new ServiceRuntimeException(cause.getMessage(), cause);
+ }
+ }
+
+ } catch (Exception e) {
+ msg.setFaultBody(e);
+ }
+ return msg;
+ }
+
+ public boolean allowsPassByReference() {
+ return allowsPBR;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProvider.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProvider.java
new file mode 100644
index 0000000000..e9eea607c9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProvider.java
@@ -0,0 +1,204 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.java.invocation;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.context.ComponentContextFactory;
+import org.apache.tuscany.sca.context.RequestContextFactory;
+import org.apache.tuscany.sca.core.context.InstanceWrapper;
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.core.scope.Scope;
+import org.apache.tuscany.sca.core.scope.ScopedImplementationProvider;
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.impl.JavaResourceImpl;
+import org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory;
+import org.apache.tuscany.sca.implementation.java.injection.RequestContextObjectFactory;
+import org.apache.tuscany.sca.implementation.java.injection.ResourceHost;
+import org.apache.tuscany.sca.implementation.java.injection.ResourceObjectFactory;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.policy.util.PolicyHandlerTuple;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.RequestContext;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaImplementationProvider implements ScopedImplementationProvider {
+ private JavaImplementation implementation;
+ private JavaComponentContextProvider componentContextProvider;
+ private RequestContextFactory requestContextFactory;
+
+ public JavaImplementationProvider(RuntimeComponent component,
+ JavaImplementation implementation,
+ ProxyFactory proxyService,
+ DataBindingExtensionPoint dataBindingRegistry,
+ JavaPropertyValueObjectFactory propertyValueObjectFactory,
+ ComponentContextFactory componentContextFactory,
+ RequestContextFactory requestContextFactory,
+ List<PolicyHandlerTuple> policyHandlerClassNames) {
+ super();
+ this.implementation = implementation;
+ this.requestContextFactory = requestContextFactory;
+ this.implementation.setPolicyHandlerClassNames(policyHandlerClassNames);
+
+ try {
+ JavaInstanceFactoryProvider configuration = new JavaInstanceFactoryProvider(implementation);
+ configuration.setProxyFactory(proxyService);
+ componentContextProvider =
+ new JavaComponentContextProvider(component,
+ configuration,
+ dataBindingRegistry,
+ propertyValueObjectFactory,
+ componentContextFactory,
+ requestContextFactory);
+
+ Scope scope = getScope();
+
+ if (scope == Scope.SYSTEM || scope == Scope.COMPOSITE) {
+ // Nothing
+ } else {
+ // Check for conversational contract if conversational scope
+ if (scope == Scope.CONVERSATION) {
+ boolean hasConversationalContract = false;
+ for (Service serviceDef : implementation.getServices()) {
+ if (serviceDef.getInterfaceContract().getInterface().isConversational()) {
+ hasConversationalContract = true;
+ break;
+ }
+ }
+ if (!hasConversationalContract) {
+ String name = implementation.getJavaClass().getName();
+ throw new NoConversationalContractException(name);
+ }
+ }
+ }
+
+ if (implementation.getConversationIDMembers().size() > 0) {
+ componentContextProvider.addConversationIDFactories(implementation.getConversationIDMembers());
+ }
+
+ componentContextProvider.configureProperties(component.getProperties());
+ handleResources(implementation, proxyService);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+
+ }
+
+ private void handleResources(JavaImplementation componentType, ProxyFactory proxyService) {
+ for (JavaResourceImpl resource : componentType.getResources().values()) {
+ String name = resource.getName();
+
+ ObjectFactory<?> objectFactory =
+ (ObjectFactory<?>)componentContextProvider.getInstanceFactoryProvider().getFactories().get(resource.getElement());
+ if (objectFactory == null) {
+ Class<?> type = resource.getElement().getType();
+ if (ComponentContext.class.equals(type)) {
+ objectFactory = new JavaComponentContextFactory(componentContextProvider);
+ } else if (RequestContext.class.equals(type)) {
+ objectFactory = new RequestContextObjectFactory(requestContextFactory, proxyService);
+ } else if (String.class.equals(type)) {
+ objectFactory = new JavaComponentNameFactory(componentContextProvider);
+ } else {
+ boolean optional = resource.isOptional();
+ String mappedName = resource.getMappedName();
+ objectFactory = createResourceObjectFactory(type, mappedName, optional, null);
+ }
+ }
+ componentContextProvider.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);
+ }
+
+ public Invoker createInvoker(RuntimeComponentService service, Operation operation) {
+ try {
+ return componentContextProvider.createInvoker(operation);
+ } catch (NoSuchMethodException e) {
+ // It's possible that the instance being invoked is a user-specified
+ // callback object that isn't an instance of the component implementation
+ // class. As an attempt to deal with this, look up a method object from
+ // the service interface. This isn't foolproof, as it's possible that
+ // the service interface isn't a Java interface, or that the callback
+ // object has the right method signature without implementing the
+ // callback interface. There is code in JavaImplementationInvoker
+ // to deal with these possibilities.
+ Interface iface = service.getInterfaceContract().getInterface();
+ if (iface instanceof JavaInterface) {
+ try {
+ Method method = JavaInterfaceUtil.findMethod(((JavaInterface)iface).getJavaClass(), operation);
+ return new JavaImplementationInvoker(operation, method, componentContextProvider.getComponent());
+ } catch (NoSuchMethodException e1) {
+ throw new IllegalArgumentException(e1);
+ }
+ } else {
+ return new JavaImplementationInvoker(operation, componentContextProvider.getComponent());
+ }
+ }
+ }
+
+ public boolean supportsOneWayInvocation() {
+ return false;
+ }
+
+ public Scope getScope() {
+ return new Scope(implementation.getJavaScope().getScope());
+ }
+
+ public void start() {
+ componentContextProvider.start();
+ }
+
+ public void stop() {
+ componentContextProvider.stop();
+ }
+
+ public InstanceWrapper createInstanceWrapper() {
+ return componentContextProvider.createInstanceWrapper();
+ }
+
+ public boolean isEagerInit() {
+ return implementation.isEagerInit();
+ }
+
+ public long getMaxAge() {
+ return implementation.getMaxAge();
+ }
+
+ public long getMaxIdleTime() {
+ return implementation.getMaxIdleTime();
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProviderFactory.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProviderFactory.java
new file mode 100644
index 0000000000..9b78439012
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaImplementationProviderFactory.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.java.invocation;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.context.ComponentContextFactory;
+import org.apache.tuscany.sca.context.RequestContextFactory;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory;
+import org.apache.tuscany.sca.policy.util.PolicyHandlerTuple;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.provider.ImplementationProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaImplementationProviderFactory implements ImplementationProviderFactory<JavaImplementation> {
+ private JavaPropertyValueObjectFactory propertyValueObjectFactory;
+ private DataBindingExtensionPoint dataBindingRegistry;
+ private ProxyFactory proxyService;
+ private ComponentContextFactory componentContextFactory;
+ private RequestContextFactory requestContextFactory;
+ private List<PolicyHandlerTuple> policyHandlerClassNames = null;
+
+ public JavaImplementationProviderFactory(ProxyFactory proxyService,
+ DataBindingExtensionPoint dataBindingRegistry,
+ JavaPropertyValueObjectFactory propertyValueObjectFactory,
+ ComponentContextFactory componentContextFactory,
+ RequestContextFactory requestContextFactory,
+ List<PolicyHandlerTuple> policyHandlerClassNames) {
+ super();
+ this.proxyService = proxyService;
+ this.dataBindingRegistry = dataBindingRegistry;
+ this.propertyValueObjectFactory = propertyValueObjectFactory;
+ this.componentContextFactory = componentContextFactory;
+ this.requestContextFactory = requestContextFactory;
+ this.policyHandlerClassNames = policyHandlerClassNames;
+ }
+
+ public ImplementationProvider createImplementationProvider(RuntimeComponent component,
+ JavaImplementation implementation) {
+ return new JavaImplementationProvider(component,
+ implementation,
+ proxyService,
+ dataBindingRegistry,
+ propertyValueObjectFactory,
+ componentContextFactory,
+ requestContextFactory,
+ policyHandlerClassNames);
+ }
+
+ public Class<JavaImplementation> getModelType() {
+ return JavaImplementation.class;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaInstanceFactoryProvider.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaInstanceFactoryProvider.java
new file mode 100644
index 0000000000..95a9f63688
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaInstanceFactoryProvider.java
@@ -0,0 +1,183 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.invocation;
+
+import java.lang.annotation.ElementType;
+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 org.apache.tuscany.sca.core.factory.ObjectFactory;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.context.InstanceFactory;
+import org.apache.tuscany.sca.implementation.java.context.InstanceFactoryProvider;
+import org.apache.tuscany.sca.implementation.java.context.ReflectiveInstanceFactory;
+import org.apache.tuscany.sca.implementation.java.impl.JavaConstructorImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.apache.tuscany.sca.implementation.java.injection.ArrayMultiplicityObjectFactory;
+import org.apache.tuscany.sca.implementation.java.injection.FieldInjector;
+import org.apache.tuscany.sca.implementation.java.injection.Injector;
+import org.apache.tuscany.sca.implementation.java.injection.InvalidAccessorException;
+import org.apache.tuscany.sca.implementation.java.injection.ListMultiplicityObjectFactory;
+import org.apache.tuscany.sca.implementation.java.injection.MethodInjector;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.JavaIntrospectionHelper;
+
+/**
+ * Encapsulates configuration for a Java-based atomic component
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaInstanceFactoryProvider<T> implements InstanceFactoryProvider<T> {
+ private JavaImplementation definition;
+ private ProxyFactory proxyService;
+
+ private final List<JavaElementImpl> injectionSites;
+ private final EventInvoker<T> initInvoker;
+ private final EventInvoker<T> destroyInvoker;
+ private final Map<JavaElementImpl, Object> factories = new HashMap<JavaElementImpl, Object>();
+
+ public JavaInstanceFactoryProvider(JavaImplementation definition) {
+ this.definition = definition;
+ this.initInvoker = definition.getInitMethod() == null ? null : new MethodEventInvoker<T>(definition
+ .getInitMethod());
+ this.destroyInvoker = definition.getDestroyMethod() == null ? null : new MethodEventInvoker<T>(definition
+ .getDestroyMethod());
+ injectionSites = new ArrayList<JavaElementImpl>();
+ }
+
+ ProxyFactory getProxyFactory() {
+ return proxyService;
+ }
+
+ void setProxyFactory(ProxyFactory proxyService) {
+ this.proxyService = proxyService;
+ }
+
+ /**
+ * @return the definition
+ */
+ JavaImplementation getImplementation() {
+ return definition;
+ }
+
+ @SuppressWarnings("unchecked")
+ public InstanceFactory<T> createFactory() {
+ ObjectFactory<?>[] initArgs = getConstructorArgs();
+ Injector<T>[] injectors = getInjectors();
+ return new ReflectiveInstanceFactory<T>((Constructor<T>)definition.getConstructor().getConstructor(),
+ initArgs, injectors, initInvoker, destroyInvoker);
+ }
+
+ private ObjectFactory<?>[] getConstructorArgs() {
+ JavaConstructorImpl<?> constructor = definition.getConstructor();
+ ObjectFactory<?>[] initArgs = new ObjectFactory<?>[constructor.getParameters().length];
+ for (int i = 0; i < initArgs.length; i++) {
+ ObjectFactory<?> factory = (ObjectFactory<?>)factories.get(constructor.getParameters()[i]);
+ assert factory != null;
+ initArgs[i] = factory;
+ }
+ return initArgs;
+ }
+
+ @SuppressWarnings("unchecked")
+ private Injector<T>[] getInjectors() {
+ // work around JDK1.5 issue with allocating generic arrays
+ @SuppressWarnings("unchecked")
+ Injector<T>[] injectors = new Injector[injectionSites.size()];
+
+ int i = 0;
+ for (JavaElementImpl element : injectionSites) {
+ Object obj = factories.get(element);
+ if (obj != null) {
+ if (obj instanceof ObjectFactory) {
+ ObjectFactory<?> factory = (ObjectFactory<?>)obj;
+ Member member = (Member)element.getAnchor();
+ if (element.getElementType() == ElementType.FIELD) {
+ injectors[i++] = new FieldInjector<T>((Field)member, factory);
+ } else if (element.getElementType() == ElementType.PARAMETER && member instanceof Method) {
+ injectors[i++] = new MethodInjector<T>((Method)member, factory);
+ } else if (member instanceof Constructor) {
+ // Ignore
+ } else {
+ throw new AssertionError(String.valueOf(element));
+ }
+ } else {
+ injectors[i++] = createMultiplicityInjector(element, (List<ObjectFactory<?>>)obj);
+ }
+ }
+ }
+ return injectors;
+ }
+
+ private Injector<T> createMultiplicityInjector(JavaElementImpl element, List<ObjectFactory<?>> factories) {
+ Class<?> interfaceType = JavaIntrospectionHelper.getBaseType(element.getType(), element.getGenericType());
+
+ if (element.getAnchor() instanceof Field) {
+ Field field = (Field)element.getAnchor();
+ if (field.getType().isArray()) {
+ return new FieldInjector<T>(field, new ArrayMultiplicityObjectFactory(interfaceType, factories));
+ } else {
+ return new FieldInjector<T>(field, new ListMultiplicityObjectFactory(factories));
+ }
+ } else if (element.getAnchor() instanceof Method) {
+ Method method = (Method)element.getAnchor();
+ if (method.getParameterTypes()[0].isArray()) {
+ return new MethodInjector<T>(method, new ArrayMultiplicityObjectFactory(interfaceType, factories));
+ } else {
+ return new MethodInjector<T>(method, new ListMultiplicityObjectFactory(factories));
+ }
+ } else {
+ throw new InvalidAccessorException("Member must be a field or method: " + element.getName());
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ public Class<T> getImplementationClass() {
+ return (Class<T>)definition.getJavaClass();
+ }
+
+ public void setObjectFactory(JavaElementImpl element, ObjectFactory<?> objectFactory) {
+ factories.put(element, objectFactory);
+ }
+
+ public void setObjectFactories(JavaElementImpl element, List<ObjectFactory<?>> objectFactory) {
+ factories.put(element, objectFactory);
+ }
+
+ /**
+ * @return the injectionSites
+ */
+ List<JavaElementImpl> getInjectionSites() {
+ return injectionSites;
+ }
+
+ /**
+ * @return the factories
+ */
+ Map<JavaElementImpl, Object> getFactories() {
+ return factories;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaPolicyHandlingRuntimeWireProcessor.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaPolicyHandlingRuntimeWireProcessor.java
new file mode 100644
index 0000000000..ee3507ef80
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/JavaPolicyHandlingRuntimeWireProcessor.java
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.java.invocation;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.apache.tuscany.sca.assembly.ComponentReference;
+import org.apache.tuscany.sca.assembly.ConfiguredOperation;
+import org.apache.tuscany.sca.assembly.OperationsConfigurator;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+import org.apache.tuscany.sca.policy.util.PolicyHandler;
+import org.apache.tuscany.sca.policy.util.PolicyHandlerUtils;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.apache.tuscany.sca.runtime.RuntimeWireProcessor;
+
+/**
+ * Processor to inject policy handling interceptor whenever PolicySets are specified in a Java Implementation
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaPolicyHandlingRuntimeWireProcessor implements RuntimeWireProcessor {
+ private static final Logger logger = Logger.getLogger(JavaPolicyHandlingRuntimeWireProcessor.class.getName());
+
+ public JavaPolicyHandlingRuntimeWireProcessor() {
+ super();
+ }
+
+ public void process(RuntimeWire wire) {
+ /*Contract contract = wire.getSource().getContract();
+ if (!(contract instanceof RuntimeComponentReference)) {
+ return;
+ }*/
+
+ RuntimeComponent component = wire.getTarget().getComponent();
+ if (component != null && component.getImplementation() instanceof JavaImplementation) {
+ JavaImplementation javaImpl = (JavaImplementation)component.getImplementation();
+ if (javaImpl instanceof PolicySetAttachPoint) {
+ PolicyHandler policyHandler = null;
+ List<PolicyHandler> implPolicyHandlers = new ArrayList<PolicyHandler>();
+ PolicySetAttachPoint policiedImpl = (PolicySetAttachPoint)javaImpl;
+
+ try {
+ //for ( PolicySet policySet : policiedImpl.getPolicySets() ) {
+ for (PolicySet policySet : component.getPolicySets()) {
+ policyHandler =
+ PolicyHandlerUtils.findPolicyHandler(policySet, javaImpl.getPolicyHandlerClassNames());
+ if (policyHandler != null) {
+ policyHandler.setUp(javaImpl);
+ implPolicyHandlers.add(policyHandler);
+ } else {
+ //FIXME: to be removed after the PolicyHandler story has crystalized..
+ //maybe replace with exception then...
+ logger.warning("No PolicyHandler registered for PolicySet - " + policySet.getName());
+ }
+ }
+
+ List<PolicyHandler> applicablePolicyHandlers = null;
+ for (InvocationChain chain : wire.getInvocationChains()) {
+ applicablePolicyHandlers = new ArrayList<PolicyHandler>();
+ if (javaImpl instanceof OperationsConfigurator) {
+ String operationName = chain.getTargetOperation().getName();
+ OperationsConfigurator opConfigurator = (OperationsConfigurator)component;
+ for (ConfiguredOperation confOp : opConfigurator.getConfiguredOperations()) {
+ if (confOp.getName().equals(operationName)) {
+ for (PolicySet policySet : confOp.getPolicySets()) {
+ policyHandler =
+ PolicyHandlerUtils.findPolicyHandler(policySet, javaImpl
+ .getPolicyHandlerClassNames());
+ if (policyHandler != null) {
+ policyHandler.setUp(javaImpl);
+ applicablePolicyHandlers.add(policyHandler);
+ } else {
+ logger.warning("No PolicyHandler registered for " + policySet);
+ }
+ }
+ break;
+ }
+ }
+
+ //if no policies have been specified at the operation level then simply
+ //apply whatever is specified for the implementation level
+ if (applicablePolicyHandlers.isEmpty()) {
+ applicablePolicyHandlers = implPolicyHandlers;
+ }
+ }
+
+ if (!applicablePolicyHandlers.isEmpty()) {
+ String phase =
+ (wire.getSource().getContract() instanceof ComponentReference) ? Phase.REFERENCE_POLICY
+ : Phase.SERVICE_POLICY;
+
+ chain.addInterceptor(Phase.IMPLEMENTATION_POLICY, new PolicyHandlingInterceptor(chain.getTargetOperation(),
+ applicablePolicyHandlers));
+ }
+ }
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/MethodEventInvoker.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/MethodEventInvoker.java
new file mode 100644
index 0000000000..515a7c8a43
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/MethodEventInvoker.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.implementation.java.invocation;
+
+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;
+
+ /**
+ * Instantiates an invoker for the given method
+ */
+ public MethodEventInvoker(Method method) {
+ assert method != null;
+ this.method = method;
+ }
+
+ public void invokeEvent(T instance) throws EventInvocationException {
+ try {
+ method.invoke(instance, (Object[]) null);
+ } catch (IllegalArgumentException e) {
+ String name = method.getName();
+ throw new EventInvocationException("Exception thrown by event method [" + name + "]", e.getCause());
+ } catch (IllegalAccessException e) {
+ String name = method.getName();
+ throw new EventInvocationException("Method is not accessible [" + name + "]");
+ } catch (InvocationTargetException e) {
+ String name = method.getName();
+ throw new EventInvocationException("Exception thrown by event method [" + name + "]", e.getCause());
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/NoConversationalContractException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/NoConversationalContractException.java
new file mode 100644
index 0000000000..a7b175cf9b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/NoConversationalContractException.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.invocation;
+
+
+/**
+ * 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 Exception {
+
+ private static final long serialVersionUID = -1157790036638157539L;
+
+ public NoConversationalContractException(String message) {
+ super(message);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/PolicyHandlingInterceptor.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/PolicyHandlingInterceptor.java
new file mode 100644
index 0000000000..8c85b46c65
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/invocation/PolicyHandlingInterceptor.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.invocation;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.policy.util.PolicyHandler;
+
+/**
+ * An interceptor to invoke policy handlers before and after the invocation of operations on
+ * an implementation.
+ *
+ * @version $Rev$ $Date$
+ */
+public class PolicyHandlingInterceptor implements Interceptor {
+ private Invoker next;
+ private List<PolicyHandler> policyHandlers = null;
+ private Operation targetOperation = null;
+
+ public PolicyHandlingInterceptor(Operation targetOperation, List<PolicyHandler> policyHandlers) {
+ this.policyHandlers = policyHandlers;
+ this.targetOperation = targetOperation;
+ }
+
+ public Message invoke(Message msg) {
+ try {
+ applyPreInvocationPolicies(targetOperation, msg);
+ msg = next.invoke(msg);
+ } finally {
+ applyPostInvocationPolices(targetOperation, msg);
+ }
+ return msg;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ private void applyPreInvocationPolicies(Object... context) {
+ for (PolicyHandler policyHandler : policyHandlers) {
+ policyHandler.beforeInvoke(context);
+ }
+ }
+
+ private void applyPostInvocationPolices(Object... context) {
+ for ( int count = policyHandlers.size() - 1 ; count >= 0 ; --count) {
+ policyHandlers.get(count).afterInvoke(context);
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java
new file mode 100644
index 0000000000..111b008b96
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/java/org/apache/tuscany/sca/implementation/java/module/JavaRuntimeModuleActivator.java
@@ -0,0 +1,103 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.java.module;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.context.ComponentContextFactory;
+import org.apache.tuscany.sca.context.ContextFactoryExtensionPoint;
+import org.apache.tuscany.sca.context.RequestContextFactory;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ModuleActivator;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.core.invocation.CglibProxyFactory;
+import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint;
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.databinding.TransformerExtensionPoint;
+import org.apache.tuscany.sca.databinding.impl.MediatorImpl;
+import org.apache.tuscany.sca.implementation.java.injection.JavaPropertyValueObjectFactory;
+import org.apache.tuscany.sca.implementation.java.invocation.JavaCallbackRuntimeWireProcessor;
+import org.apache.tuscany.sca.implementation.java.invocation.JavaImplementationProviderFactory;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.policy.util.PolicyHandlerDefinitionsLoader;
+import org.apache.tuscany.sca.policy.util.PolicyHandlerTuple;
+import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
+import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaRuntimeModuleActivator implements ModuleActivator {
+
+ public JavaRuntimeModuleActivator() {
+ }
+
+ public void start(ExtensionPointRegistry registry) {
+
+ ModelFactoryExtensionPoint factories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ MessageFactory messageFactory = factories.getFactory(MessageFactory.class);
+
+ UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
+ InterfaceContractMapper interfaceContractMapper = utilities.getUtility(InterfaceContractMapper.class);
+
+ ProxyFactoryExtensionPoint proxyFactories = registry.getExtensionPoint(ProxyFactoryExtensionPoint.class);
+ proxyFactories.setClassProxyFactory(new CglibProxyFactory(messageFactory, interfaceContractMapper));
+
+ JavaInterfaceFactory javaFactory = factories.getFactory(JavaInterfaceFactory.class);
+
+ DataBindingExtensionPoint dataBindings = registry.getExtensionPoint(DataBindingExtensionPoint.class);
+ TransformerExtensionPoint transformers = registry.getExtensionPoint(TransformerExtensionPoint.class);
+ MediatorImpl mediator = new MediatorImpl(dataBindings, transformers);
+ JavaPropertyValueObjectFactory factory = new JavaPropertyValueObjectFactory(mediator);
+
+ ContextFactoryExtensionPoint contextFactories = registry.getExtensionPoint(ContextFactoryExtensionPoint.class);
+ ComponentContextFactory componentContextFactory = contextFactories.getFactory(ComponentContextFactory.class);
+ RequestContextFactory requestContextFactory = contextFactories.getFactory(RequestContextFactory.class);
+
+ List<PolicyHandlerTuple> policyHandlerClassNames = null;
+ policyHandlerClassNames = PolicyHandlerDefinitionsLoader.loadPolicyHandlerClassnames();
+
+ ProxyFactory proxyFactory = new ExtensibleProxyFactory(proxyFactories);
+
+ JavaImplementationProviderFactory javaImplementationProviderFactory =
+ new JavaImplementationProviderFactory(proxyFactory, dataBindings, factory, componentContextFactory,
+ requestContextFactory, policyHandlerClassNames);
+
+ ProviderFactoryExtensionPoint providerFactories =
+ registry.getExtensionPoint(ProviderFactoryExtensionPoint.class);
+ providerFactories.addProviderFactory(javaImplementationProviderFactory);
+
+ RuntimeWireProcessorExtensionPoint wireProcessorExtensionPoint =
+ registry.getExtensionPoint(RuntimeWireProcessorExtensionPoint.class);
+ if (wireProcessorExtensionPoint != null) {
+ wireProcessorExtensionPoint.addWireProcessor(new JavaCallbackRuntimeWireProcessor(interfaceContractMapper,
+ javaFactory));
+ //wireProcessorExtensionPoint.addWireProcessor(new JavaPolicyHandlingRuntimeWireProcessor());
+ }
+ }
+
+ public void stop(ExtensionPointRegistry registry) {
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator
new file mode 100644
index 0000000000..0871ddf4be
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# Implementation class for the ModuleActivator
+org.apache.tuscany.sca.implementation.java.module.JavaRuntimeModuleActivator
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/context/MultiplicityTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/context/MultiplicityTestCase.java
new file mode 100644
index 0000000000..ba8da101c6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/context/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.sca.implementation.java.context;
+
+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/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceWrapperTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceWrapperTestCase.java
new file mode 100644
index 0000000000..628a308c86
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/context/ReflectiveInstanceWrapperTestCase.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.context;
+
+import static org.easymock.EasyMock.createMock;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.core.scope.TargetDestructionException;
+import org.apache.tuscany.sca.core.scope.TargetInitializationException;
+import org.apache.tuscany.sca.implementation.java.invocation.EventInvoker;
+import org.easymock.EasyMock;
+
+/**
+ * @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);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+ instance = new Object();
+ initInvoker = createMock(EventInvoker.class);
+ destroyInvoker = createMock(EventInvoker.class);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/CallbackWireObjectFactoryTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/CallbackWireObjectFactoryTestCase.java
new file mode 100644
index 0000000000..29dcfa8169
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/CallbackWireObjectFactoryTestCase.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.implementation.java.injection;
+
+import static org.easymock.EasyMock.createMock;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.core.invocation.CallbackWireObjectFactory;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.runtime.RuntimeWire;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class CallbackWireObjectFactoryTestCase extends TestCase {
+
+ @SuppressWarnings({"unchecked"})
+ public void testCreateInstance() throws Exception {
+ ProxyFactory service = createMock(ProxyFactory.class);
+ Foo foo = new Foo() {
+ };
+ EasyMock.expect(service.createCallbackProxy(EasyMock.eq(Foo.class), EasyMock.isA(List.class))).andReturn(foo);
+ EasyMock.replay(service);
+ List<RuntimeWire> wires = new ArrayList<RuntimeWire>();
+ CallbackWireObjectFactory factory = new CallbackWireObjectFactory(Foo.class, service, wires);
+ assertEquals(foo, factory.getInstance());
+ EasyMock.verify(service);
+ }
+
+ private interface Foo {
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/FieldInjectorTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/FieldInjectorTestCase.java
new file mode 100644
index 0000000000..cc852cc677
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/FieldInjectorTestCase.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.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);
+ }
+
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ protectedField = Foo.class.getDeclaredField("hidden");
+ }
+
+ private class Foo {
+ private String hidden;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactoryTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactoryTestCase.java
new file mode 100644
index 0000000000..d502462688
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/JavaPropertyValueObjectFactoryTestCase.java
@@ -0,0 +1,449 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.injection;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+import org.apache.tuscany.sca.databinding.DataBindingExtensionPoint;
+import org.apache.tuscany.sca.databinding.DefaultDataBindingExtensionPoint;
+import org.apache.tuscany.sca.databinding.Mediator;
+import org.apache.tuscany.sca.databinding.impl.SimpleTypeMapperImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.easymock.EasyMock;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * This test case will test the JavaPropertyValueObjectFactory.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaPropertyValueObjectFactoryTestCase {
+
+ /**
+ * The factory we should use for testing.
+ */
+ private static JavaPropertyValueObjectFactory factory;
+
+ /**
+ * The assembly factory used to create Properties.
+ */
+ private static AssemblyFactory assemblyFactory;
+
+ /**
+ * Test Setup.
+ */
+ @BeforeClass
+ public static void setup() {
+ // Create the factory
+ Mediator mediator = EasyMock.createNiceMock(Mediator.class);
+ DataBindingExtensionPoint dpep = new DefaultDataBindingExtensionPoint();
+ EasyMock.expect(mediator.getDataBindings()).andReturn(dpep).anyTimes();
+ EasyMock.replay(mediator);
+ factory = new JavaPropertyValueObjectFactory(mediator);
+
+ // Create the AssemblyFactory we should use
+ assemblyFactory = new DefaultAssemblyFactory();
+ }
+
+ /**
+ * A test that will attempt to inject positive, negative and zero into an
+ * int property.
+ */
+ @Test
+ public void testIntegerInjectionValid() {
+ InjectionTestParams params = new InjectionTestParams();
+ params.propertyName = "intField";
+ params.xsdType = SimpleTypeMapperImpl.XSD_INT;
+ params.expectedType = Integer.TYPE;
+
+ for (int i = -5; i <= 5; i++) {
+ params.propertyValue = Integer.toString(i);
+ params.expectedValueFromFactory = i;
+ doInjection(params);
+ }
+ }
+
+ /**
+ * A test that will attempt to inject positive, negative and zero into an
+ * int property using a JavaElement.
+ */
+ @Test
+ public void testIntegerInjectionValidWithJavaElement() {
+ InjectionTestParams params = new InjectionTestParams();
+ params.propertyName = "intField";
+ params.xsdType = SimpleTypeMapperImpl.XSD_INT;
+ params.expectedJavaElement = new JavaElementImpl(int.class);
+
+ for (int i = -5; i <= 5; i++) {
+ params.propertyValue = Integer.toString(i);
+ params.expectedValueFromFactory = i;
+ doInjection(params);
+ }
+ }
+
+ /**
+ * A test that will attempt to inject multiple int values into an
+ * int property.
+ */
+ @Test
+ public void testIntegerArrayInjectionValid() {
+ InjectionTestParams params = new InjectionTestParams();
+ params.propertyName = "intField";
+ params.xsdType = SimpleTypeMapperImpl.XSD_INT;
+ params.isMany = true;
+ params.expectedType = int.class;
+ params.propertyValue = "1 2 3 4 5";
+ params.expectedValueFromFactory = Arrays.asList(1, 2, 3, 4, 5);
+ doInjection(params);
+ }
+
+ /**
+ * A test that will attempt to inject multiple int values into an
+ * int property using a JavaElement.
+ */
+ @Test
+ public void testIntegerArrayInjectionValidWithJavaElement() {
+ InjectionTestParams params = new InjectionTestParams();
+ params.propertyName = "intField";
+ params.xsdType = SimpleTypeMapperImpl.XSD_INT;
+ params.isMany = true;
+ params.expectedJavaElement = new JavaElementImpl(int[].class);
+ params.propertyValue = "1 2 3 4 5";
+ int[] expected = { 1, 2, 3, 4, 5 };
+ params.expectedValueFromFactory = expected;
+ doInjection(params);
+ }
+
+ /**
+ * A test that will attempt to inject a non-number into an
+ * int property.
+ */
+ @Test
+ public void testIntegerInjectionBadNumberInvalid() {
+ InjectionTestParams params = new InjectionTestParams();
+ params.propertyName = "intField";
+ params.xsdType = SimpleTypeMapperImpl.XSD_INT;
+ params.expectedType = Integer.TYPE;
+ params.propertyValue = "a";
+ params.exceptionExpected = true;
+ doInjection(params);
+ }
+
+ /**
+ * A test that will attempt to inject a non-number into an
+ * int property using a JavaElement.
+ */
+ @Test
+ public void testIntegerInjectionBadNumberInvalidWithJavaElement() {
+ InjectionTestParams params = new InjectionTestParams();
+ params.propertyName = "intField";
+ params.xsdType = SimpleTypeMapperImpl.XSD_INT;
+ params.expectedJavaElement = new JavaElementImpl(Integer.TYPE);
+ params.propertyValue = "a";
+ params.exceptionExpected = true;
+ doInjection(params);
+ }
+
+ /**
+ * A test that will attempt to inject multiple int values into an
+ * int property where one of the property values is not a number.
+ * The injection should throw ObjectCreationException
+ */
+ @Test
+ public void testIntegerArrayInjectionBadNumberInvalid() {
+ InjectionTestParams params = new InjectionTestParams();
+ params.propertyName = "intField";
+ params.xsdType = SimpleTypeMapperImpl.XSD_INT;
+ params.isMany = true;
+ params.expectedType = int.class;
+ params.propertyValue = "1 2 aa 4 5";
+ params.exceptionExpected = true;
+ doInjection(params);
+ }
+
+ /**
+ * A test that will attempt to inject multiple int values into an
+ * int property using a JavaElement where one of the property
+ * values is not a number.
+ * The injection should throw ObjectCreationException
+ */
+ @Test
+ public void testIntegerArrayInjectionBadNumberInvalidWithJavaElement() {
+ InjectionTestParams params = new InjectionTestParams();
+ params.propertyName = "intField";
+ params.xsdType = SimpleTypeMapperImpl.XSD_INT;
+ params.isMany = true;
+ params.expectedJavaElement = new JavaElementImpl(int[].class);
+ params.propertyValue = "1 2 aa 4 5";
+ params.exceptionExpected = true;
+ doInjection(params);
+ }
+
+ /**
+ * A test that will attempt to inject an empty string into an int property.
+ * The injection should throw ObjectCreationException
+ */
+ @Test
+ public void testIntegerInjectionEmptyStringInvalid() {
+ InjectionTestParams params = new InjectionTestParams();
+ params.propertyName = "intField";
+ params.xsdType = SimpleTypeMapperImpl.XSD_INT;
+ params.expectedType = Integer.TYPE;
+ params.propertyValue = "";
+ params.exceptionExpected = true;
+ doInjection(params);
+ }
+
+ /**
+ * A test that will attempt to inject an empty string into an int property
+ * using a JavaElement.
+ * The injection should throw ObjectCreationException
+ */
+ @Test
+ public void testIntegerInjectionEmptyStringInvalidWithJavaElement() {
+ InjectionTestParams params = new InjectionTestParams();
+ params.propertyName = "intField";
+ params.xsdType = SimpleTypeMapperImpl.XSD_INT;
+ params.expectedJavaElement = new JavaElementImpl(Integer.TYPE);
+ params.propertyValue = "";
+ params.exceptionExpected = true;
+ doInjection(params);
+ }
+
+ /**
+ * A test that will attempt to inject a String into a String
+ * property.
+ */
+ @Test
+ public void testStringInjectionValid() {
+ InjectionTestParams params = new InjectionTestParams();
+ params.propertyName = "StringField";
+ params.xsdType = SimpleTypeMapperImpl.XSD_STRING;
+ params.expectedType = String.class;
+
+ params.propertyValue = "Some Test String";
+ params.expectedValueFromFactory = "Some Test String";
+ doInjection(params);
+ }
+
+ /**
+ * A test that will attempt to inject a String into a String
+ * property using a JavaElement.
+ */
+ @Test
+ public void testStringInjectionValidWithJavaElement() {
+ InjectionTestParams params = new InjectionTestParams();
+ params.propertyName = "StringField";
+ params.xsdType = SimpleTypeMapperImpl.XSD_STRING;
+ params.expectedJavaElement = new JavaElementImpl(String.class);
+
+ params.propertyValue = "Some Test String";
+ params.expectedValueFromFactory = "Some Test String";
+ doInjection(params);
+ }
+
+ /**
+ * This class defines all the parameters for the Property Injection test.
+ */
+ private class InjectionTestParams {
+ // Input parameters for the test
+ public boolean isMany = false;
+ public String propertyName;
+ public String propertyValue;
+ public QName xsdType;
+
+ // Expected result for test
+ public Object expectedValueFromFactory;
+ public Class<?> expectedType;
+ public JavaElementImpl expectedJavaElement;
+ public boolean exceptionExpected = false;
+ }
+
+ /**
+ * A test that will attempt to inject multiple String values into an
+ * String property.
+ */
+ @Test
+ public void testStringArrayInjectionValid() {
+ InjectionTestParams params = new InjectionTestParams();
+ params.propertyName = "StringField";
+ params.xsdType = SimpleTypeMapperImpl.XSD_STRING;
+ params.isMany = true;
+ params.expectedType = String.class;
+ params.propertyValue = "\"String1\" \"String2\" \"String3\" \"String4\" \"String5\"";
+ params.expectedValueFromFactory = Arrays.asList(
+ "String1", "String2", "String3", "String4", "String5");
+ doInjection(params);
+ }
+
+ /**
+ * A test that will attempt to inject multiple String values into an
+ * String property using a JavaElement.
+ */
+ @Test
+ public void testStringArrayInjectionValidWithJavaElement() {
+ InjectionTestParams params = new InjectionTestParams();
+ params.propertyName = "StringField";
+ params.xsdType = SimpleTypeMapperImpl.XSD_STRING;
+ params.isMany = true;
+ params.expectedJavaElement = new JavaElementImpl(String.class);
+ params.propertyValue = "\"String1\" \"String2\" \"String3\" \"String4\" \"String5\"";
+ params.expectedValueFromFactory = Arrays.asList(
+ "String1", "String2", "String3", "String4", "String5");
+ doInjection(params);
+ }
+
+ /**
+ * Utility method for testing creating properties with the
+ * JavaPropertyValueObjectFactory.
+ *
+ * @param testParams The parameters for the test
+ */
+ private void doInjection(final InjectionTestParams testParams) {
+ // Create the property
+ Property prop = assemblyFactory.createProperty();
+ prop.setMany(testParams.isMany);
+ prop.setName(testParams.propertyName);
+ prop.setXSDType(testParams.xsdType);
+
+ // Mock up the XML that will contain the Property details
+ Document doc = EasyMock.createNiceMock(Document.class);
+ Element rootElement = EasyMock.createMock(Element.class);
+ EasyMock.expect(doc.getDocumentElement()).andReturn(rootElement);
+ NodeList nodeList = EasyMock.createMock(NodeList.class);
+ EasyMock.expect(rootElement.getChildNodes()).andReturn(nodeList).anyTimes();
+ EasyMock.expect(nodeList.getLength()).andReturn(1);
+ Node node = EasyMock.createMock(Node.class);
+ EasyMock.expect(nodeList.item(0)).andReturn(node);
+ EasyMock.expect(node.getTextContent()).andReturn(testParams.propertyValue);
+ EasyMock.replay(doc, rootElement, nodeList, node);
+
+ // Create a factory either using the Class or JavaElementImpl constructor
+ ObjectFactory<?> objectFactory;
+ if (testParams.expectedJavaElement != null) {
+ objectFactory = factory.createValueFactory(prop, doc, testParams.expectedJavaElement);
+ } else {
+ objectFactory = factory.createValueFactory(prop, doc, testParams.expectedType);
+ }
+ Assert.assertNotNull(objectFactory);
+
+ // Lets test the factory
+ try {
+ // Create a new instance with the factory
+ Object value = objectFactory.getInstance();
+
+ // Did we expect an exception to be thrown?
+ if (testParams.exceptionExpected) {
+ Assert.fail("Test should have thrown ObjectCreationException");
+ }
+
+ // Make sure the result is of the correct type
+ if (testParams.expectedValueFromFactory instanceof Collection<?>) {
+ // Make sure the Collections contain the same type
+ Assert.assertTrue(value instanceof Collection<?>);
+ Iterator<?> iter1 = ((Collection<?>) testParams.expectedValueFromFactory).iterator();
+ Iterator<?> iter2 = ((Collection<?>) value).iterator();
+ Assert.assertEquals(iter1.next().getClass(), iter2.next().getClass());
+ } else {
+ Assert.assertEquals(testParams.expectedValueFromFactory.getClass(), value.getClass());
+ }
+
+ // Validate the result
+ Assert.assertNotNull(value);
+ if (testParams.expectedValueFromFactory.getClass().isArray()) {
+ Assert.assertTrue(compareArrays(testParams.expectedValueFromFactory, value));
+ } else {
+ Assert.assertEquals(testParams.expectedValueFromFactory, value);
+ }
+ } catch (ObjectCreationException ex) {
+ // Is this an expected exception?
+ if (testParams.exceptionExpected) {
+ // Make sure the exception error message contains the property name
+ Assert.assertTrue(ex.toString().indexOf(testParams.propertyName) != -1);
+
+ // Make sure the exception error message contains the property value
+ if (testParams.propertyValue != null) {
+ if (testParams.isMany) {
+ // FIXME: No simple way to do this for multi-value properties
+ } else {
+ Assert.assertTrue(ex.toString().indexOf(testParams.propertyValue) != -1);
+ }
+ }
+ } else {
+ // Test failure. We were not expecting an exception
+ ex.printStackTrace();
+ Assert.fail("Unexpected exception " + ex);
+ }
+ }
+ }
+
+ /**
+ * Compares two Objects that are actually arrays to make sure that they are
+ * equal.
+ *
+ * @param array1 The first array
+ * @param array2 The second array
+ * @return True if they are equal. False if they are not
+ */
+ private boolean compareArrays(final Object array1, final Object array2) {
+ // Check for primitive array types
+ if (array1 instanceof boolean[]) {
+ return Arrays.equals((boolean[]) array1, (boolean[]) array2);
+ }
+ if (array1 instanceof byte[]) {
+ return Arrays.equals((byte[]) array1, (byte[]) array2);
+ }
+ if (array1 instanceof char[]) {
+ return Arrays.equals((char[]) array1, (char[]) array2);
+ }
+ if (array1 instanceof double[]) {
+ return Arrays.equals((double[]) array1, (double[]) array2);
+ }
+ if (array1 instanceof float[]) {
+ return Arrays.equals((float[]) array1, (float[]) array2);
+ }
+ if (array1 instanceof int[]) {
+ return Arrays.equals((int[]) array1, (int[]) array2);
+ }
+ if (array1 instanceof long[]) {
+ return Arrays.equals((long[]) array1, (long[]) array2);
+ }
+ if (array1 instanceof short[]) {
+ return Arrays.equals((short[]) array1, (short[]) array2);
+ }
+
+ // Not a primitive so must be an Object[]
+ return Arrays.equals((Object[]) array1, (Object[]) array2);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/MethodEventInvokerTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/MethodEventInvokerTestCase.java
new file mode 100644
index 0000000000..4de0a4e8c7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/MethodEventInvokerTestCase.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.injection;
+
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.implementation.java.invocation.EventInvocationException;
+import org.apache.tuscany.sca.implementation.java.invocation.MethodEventInvoker;
+
+/**
+ * @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 (EventInvocationException 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
+ }
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ privateMethod = MethodEventInvokerTestCase.Foo.class.getDeclaredMethod("hidden");
+ exceptionMethod = MethodEventInvokerTestCase.Foo.class.getDeclaredMethod("exception");
+
+ }
+
+ public class Foo {
+
+ public void foo() {
+ }
+
+ private void hidden() {
+ }
+
+ public void exception() {
+ throw new RuntimeException();
+ }
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/MethodInjectorTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/MethodInjectorTestCase.java
new file mode 100644
index 0000000000..214779ed3f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/MethodInjectorTestCase.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.injection;
+
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+
+/**
+ * @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
+ }
+ }
+
+ @Override
+ 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/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/RequestContextObjectFactoryTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/RequestContextObjectFactoryTestCase.java
new file mode 100644
index 0000000000..c470b8cf3d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/RequestContextObjectFactoryTestCase.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.implementation.java.injection;
+
+import junit.framework.TestCase;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class RequestContextObjectFactoryTestCase extends TestCase {
+
+ public void testInstanceCreate() {
+ RequestContextObjectFactory factory = new RequestContextObjectFactory(null);
+ assertNotNull(factory.getInstance());
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/ResourceObjectFactoryTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/ResourceObjectFactoryTestCase.java
new file mode 100644
index 0000000000..ed7a0e7d03
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/ResourceObjectFactoryTestCase.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.injection;
+
+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);
+//
+// RuntimeWire wire = EasyMock.createMock(RuntimeWire.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/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/SingletonObjectFactory.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/SingletonObjectFactory.java
new file mode 100644
index 0000000000..c1650c3a83
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/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.sca.implementation.java.injection;
+
+import org.apache.tuscany.sca.core.factory.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/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/SingletonObjectFactoryTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/SingletonObjectFactoryTestCase.java
new file mode 100644
index 0000000000..40ad1b1e95
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/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.sca.implementation.java.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/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/TestObjectFactory.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/TestObjectFactory.java
new file mode 100644
index 0000000000..de371e09bb
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/TestObjectFactory.java
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.injection;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.util.List;
+
+import org.apache.tuscany.sca.core.factory.ObjectCreationException;
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+
+/**
+ * Creates new instances of a Java class
+ *
+ * @version $Rev$ $Date$
+ * @see org.apache.tuscany.sca.implementation.java.injection.Injector
+ */
+public class TestObjectFactory<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 TestObjectFactory(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 TestObjectFactory(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/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/TestObjectFactoryTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/TestObjectFactoryTestCase.java
new file mode 100644
index 0000000000..1fb7abb917
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/injection/TestObjectFactoryTestCase.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.implementation.java.injection;
+
+import java.lang.reflect.Constructor;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.core.factory.ObjectFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class TestObjectFactoryTestCase extends TestCase {
+
+ private Constructor<Foo> ctor;
+
+ public void testConstructorInjection() throws Exception {
+ List<ObjectFactory> initializers = new ArrayList<ObjectFactory>();
+ initializers.add(new SingletonObjectFactory<String>("foo"));
+ TestObjectFactory<Foo> factory = new TestObjectFactory<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);
+ TestObjectFactory<Foo> factory = new TestObjectFactory<Foo>(ctor, initializers);
+ Foo foo = factory.getInstance();
+ assertNull(foo.foo);
+ }
+
+ public void testConstructorInitializerInjection() throws Exception {
+ TestObjectFactory<Foo> factory = new TestObjectFactory<Foo>(ctor);
+ factory.setInitializerFactory(0, new SingletonObjectFactory<String>("foo"));
+ Foo foo = factory.getInstance();
+ assertEquals("foo", foo.foo);
+ }
+
+ @Override
+ 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/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/Bean1.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/Bean1.java
new file mode 100644
index 0000000000..e993cdd382
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/Bean1.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.implementation.java.util;
+
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+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) {
+ }
+
+ @Override
+ public void override(String param) throws Exception {
+ }
+
+
+ public void noOverride(String param) throws Exception {
+ }
+
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/Bean2.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/Bean2.java
new file mode 100644
index 0000000000..82264c77c9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/Bean2.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.util;
+
+import java.util.List;
+
+import junit.framework.AssertionFailedError;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+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/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/Entry.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/Entry.java
new file mode 100644
index 0000000000..a5e12d181c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/Entry.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.util;
+
+/**
+ * Implementations are used in wiring tests
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Entry {
+
+ String getString();
+
+ void setString(String val);
+}
+
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/JavaIntrospectionHelperTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/JavaIntrospectionHelperTestCase.java
new file mode 100644
index 0000000000..ed6bf7ddc4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/JavaIntrospectionHelperTestCase.java
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.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.sca.implementation.java.introspect.impl.JavaIntrospectionHelper;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaIntrospectionHelperTestCase extends TestCase {
+
+ private List testNoGenericsList;
+ private List<String> testList;
+ private Map<String, Bean1> testMap;
+ private Entry[] 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, true);
+ assertEquals(4, beanFields.size()); //Bean1.ALL_BEAN1_PUBLIC_PROTECTED_FIELDS
+ }
+
+ public void testGetSuperAllMethods() throws Exception {
+ Set<Method> superBeanMethods = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(SuperBean.class, true);
+ assertEquals(SuperBean.ALL_SUPER_METHODS, superBeanMethods.size());
+ }
+
+ public void testGetBean1AllMethods() throws Exception {
+ Set<Method> beanMethods = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(Bean1.class, true);
+ assertEquals(Bean1.ALL_BEAN1_METHODS, beanMethods.size());
+ }
+
+ public void testOverrideMethod() throws Exception {
+ Set<Method> beanFields = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(Bean1.class, true);
+ 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, true);
+ 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(Entry[] 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/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/SuperBean.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/util/SuperBean.java
new file mode 100644
index 0000000000..408cedb8be
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-runtime/src/test/java/org/apache/tuscany/sca/implementation/java/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.sca.implementation.java.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/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/LICENSE b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/META-INF/README b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/NOTICE b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/pom.xml b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/pom.xml
new file mode 100644
index 0000000000..d89d7fd406
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/pom.xml
@@ -0,0 +1,112 @@
+<?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.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-implementation-java-xml</artifactId>
+ <name>Apache Tuscany SCA Java Implementation XML Model</name>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-interface-java-xml</artifactId>
+ <version>${version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution-impl</artifactId>
+ <version>${version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-definitions</artifactId>
+ <version>${version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-policy-xml</artifactId>
+ <version>${version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-policy-xml-ws</artifactId>
+ <version>${version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-definitions-xml</artifactId>
+ <version>${version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-implementation-java</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-binding-sca</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.implementation.java.xml</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.implementation.java.xml*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationConstants.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationConstants.java
new file mode 100644
index 0000000000..ecbf0c4c78
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationConstants.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.xml;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.xml.Constants;
+
+/**
+ * Constants for the Java Implementation.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface JavaImplementationConstants {
+
+ String IMPLEMENTATION_JAVA = "implementation.java";
+ QName IMPLEMENTATION_JAVA_QNAME = new QName(Constants.SCA10_NS, "implementation.java");
+ String CLASS = "class";
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java
new file mode 100644
index 0000000000..11934ec6bb
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/main/java/org/apache/tuscany/sca/implementation/java/xml/JavaImplementationProcessor.java
@@ -0,0 +1,315 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.java.xml;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.assembly.ConfiguredOperation;
+import org.apache.tuscany.sca.assembly.OperationsConfigurator;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.assembly.xml.ConfiguredOperationProcessor;
+import org.apache.tuscany.sca.assembly.xml.Constants;
+import org.apache.tuscany.sca.assembly.xml.PolicyAttachPointProcessor;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ClassReference;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.JavaIntrospectionHelper;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaImplementationProcessor implements StAXArtifactProcessor<JavaImplementation>,
+ JavaImplementationConstants {
+
+ private JavaImplementationFactory javaFactory;
+ private AssemblyFactory assemblyFactory;
+ private PolicyFactory policyFactory;
+ private PolicyAttachPointProcessor policyProcessor;
+ private IntentAttachPointTypeFactory intentAttachPointTypeFactory;
+ private ConfiguredOperationProcessor configuredOperationProcessor;
+ private Monitor monitor;
+
+ public JavaImplementationProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
+ this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ this.policyFactory = modelFactories.getFactory(PolicyFactory.class);
+ this.javaFactory = modelFactories.getFactory(JavaImplementationFactory.class);
+ this.policyProcessor = new PolicyAttachPointProcessor(policyFactory);
+ this.intentAttachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class);
+ this.monitor = monitor;
+ this.configuredOperationProcessor = new ConfiguredOperationProcessor(modelFactories, this.monitor);
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "impl-javaxml-validation-messages", Severity.ERROR, model, message,(Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "impl-javaxml-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
+ public JavaImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+
+ // Read an <implementation.java>
+ JavaImplementation javaImplementation = javaFactory.createJavaImplementation();
+
+ /*if ( javaImplementation instanceof PolicySetAttachPoint ) {
+ IntentAttachPointType implType = intentAttachPointTypeFactory.createImplementationType();
+ implType.setName(getArtifactType());
+ implType.setUnresolved(true);
+ ((PolicySetAttachPoint)javaImplementation).setType(implType);
+ }*/
+
+ javaImplementation.setUnresolved(true);
+ javaImplementation.setName(reader.getAttributeValue(null, CLASS));
+
+ // Read policies
+ policyProcessor.readPolicies(javaImplementation, reader);
+
+ // read operation elements if exists or skip unto end element
+ int event;
+ ConfiguredOperation confOp = null;
+ while (reader.hasNext()) {
+ event = reader.next();
+ switch ( event ) {
+ case START_ELEMENT : {
+ if ( Constants.OPERATION_QNAME.equals(reader.getName()) ) {
+ confOp = configuredOperationProcessor.read(reader);
+ if ( confOp != null ) {
+ ((OperationsConfigurator)javaImplementation).getConfiguredOperations().add(confOp);
+ }
+ }
+ }
+ break;
+ }
+
+ if (event == END_ELEMENT && IMPLEMENTATION_JAVA_QNAME.equals(reader.getName())) {
+ break;
+ }
+ }
+ return javaImplementation;
+ }
+
+ public void write(JavaImplementation javaImplementation, XMLStreamWriter writer) throws ContributionWriteException,
+ XMLStreamException {
+
+ // Write an <implementation.java>
+ policyProcessor.writePolicyPrefixes(javaImplementation, writer);
+ writer.writeStartElement(Constants.SCA10_NS, IMPLEMENTATION_JAVA);
+ policyProcessor.writePolicyAttributes(javaImplementation, writer);
+
+ if (javaImplementation.getName() != null) {
+ writer.writeAttribute(CLASS, javaImplementation.getName());
+ }
+
+ writer.writeEndElement();
+ }
+
+ public void resolve(JavaImplementation javaImplementation, ModelResolver resolver)
+ throws ContributionResolveException {
+
+ ClassReference classReference = new ClassReference(javaImplementation.getName());
+ classReference = resolver.resolveModel(ClassReference.class, classReference);
+ Class javaClass = classReference.getJavaClass();
+ if (javaClass == null) {
+ error("ClassNotFoundException", resolver, javaImplementation.getName());
+ //throw new ContributionResolveException(new ClassNotFoundException(javaImplementation.getName()));
+ return;
+ }
+
+ javaImplementation.setJavaClass(javaClass);
+
+ try {
+ javaFactory.createJavaImplementation(javaImplementation, javaImplementation.getJavaClass());
+ } catch (IntrospectionException e) {
+ ContributionResolveException ce = new ContributionResolveException(e);
+ error("ContributionResolveException", javaFactory, ce);
+ //throw ce;
+ return;
+ }
+
+ javaImplementation.setUnresolved(false);
+ mergeComponentType(resolver, javaImplementation);
+
+ // FIXME the introspector should always create at least one service
+ if (javaImplementation.getServices().isEmpty()) {
+ javaImplementation.getServices().add(assemblyFactory.createService());
+ }
+ }
+
+ private JavaElementImpl getMemeber(JavaImplementation impl, String name, Class<?> type) {
+ String setter = JavaIntrospectionHelper.toSetter(name);
+ try {
+ Method method = impl.getJavaClass().getDeclaredMethod(setter, type);
+ int mod = method.getModifiers();
+ if ((Modifier.isPublic(mod) || Modifier.isProtected(mod)) && (!Modifier.isStatic(mod))) {
+ return new JavaElementImpl(method, 0);
+ }
+ } catch (NoSuchMethodException e) {
+ Field field;
+ try {
+ field = impl.getJavaClass().getDeclaredField(name);
+ int mod = field.getModifiers();
+ if ((Modifier.isPublic(mod) || Modifier.isProtected(mod)) && (!Modifier.isStatic(mod))) {
+ return new JavaElementImpl(field);
+ }
+ } catch (NoSuchFieldException e1) {
+ // Ignore
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Merge the componentType from introspection and external file
+ * @param resolver
+ * @param impl
+ */
+ private void mergeComponentType(ModelResolver resolver, JavaImplementation impl) {
+ // FIXME: Need to clarify how to merge
+ ComponentType componentType = getComponentType(resolver, impl);
+ if (componentType != null && !componentType.isUnresolved()) {
+ Map<String, Reference> refMap = new HashMap<String, Reference>();
+ for (Reference ref : impl.getReferences()) {
+ refMap.put(ref.getName(), ref);
+ }
+ for (Reference reference : componentType.getReferences()) {
+ refMap.put(reference.getName(), reference);
+ }
+ impl.getReferences().clear();
+ impl.getReferences().addAll(refMap.values());
+
+ // Try to match references by type
+ Map<String, JavaElementImpl> refMembers = impl.getReferenceMembers();
+ for (Reference ref : impl.getReferences()) {
+ if (ref.getInterfaceContract() != null) {
+ Interface i = ref.getInterfaceContract().getInterface();
+ if (i instanceof JavaInterface) {
+ Class<?> type = ((JavaInterface)i).getJavaClass();
+ if (!refMembers.containsKey(ref.getName())) {
+ JavaElementImpl e = getMemeber(impl, ref.getName(), type);
+ if (e != null) {
+ refMembers.put(ref.getName(), e);
+ }
+ }
+ }
+ }
+ }
+
+ Map<String, Service> serviceMap = new HashMap<String, Service>();
+ for (Service svc : impl.getServices()) {
+ serviceMap.put(svc.getName(), svc);
+ }
+ for (Service service : componentType.getServices()) {
+ serviceMap.put(service.getName(), service);
+ }
+ impl.getServices().clear();
+ impl.getServices().addAll(serviceMap.values());
+
+ Map<String, Property> propMap = new HashMap<String, Property>();
+ for (Property prop : impl.getProperties()) {
+ propMap.put(prop.getName(), prop);
+ }
+ for (Property property : componentType.getProperties()) {
+ propMap.put(property.getName(), property);
+ }
+ impl.getProperties().clear();
+ impl.getProperties().addAll(propMap.values());
+
+ if (componentType.getConstrainingType() != null) {
+ impl.setConstrainingType(componentType.getConstrainingType());
+ }
+ }
+ }
+
+ private ComponentType getComponentType(ModelResolver resolver, JavaImplementation impl) {
+ String className = impl.getJavaClass().getName();
+ String componentTypeURI = className.replace('.', '/') + ".componentType";
+ ComponentType componentType = assemblyFactory.createComponentType();
+ componentType.setUnresolved(true);
+ componentType.setURI(componentTypeURI);
+ componentType = resolver.resolveModel(ComponentType.class, componentType);
+ if (!componentType.isUnresolved()) {
+ return componentType;
+ }
+ return null;
+ }
+
+ public QName getArtifactType() {
+ return IMPLEMENTATION_JAVA_QNAME;
+ }
+
+ public Class<JavaImplementation> getModelType() {
+ return JavaImplementation.class;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
new file mode 100644
index 0000000000..ff43eebcfc
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for the artifact processor extension
+org.apache.tuscany.sca.implementation.java.xml.JavaImplementationProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#implementation.java,model=org.apache.tuscany.sca.implementation.java.JavaImplementation
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/main/resources/impl-javaxml-validation-messages.properties b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/main/resources/impl-javaxml-validation-messages.properties
new file mode 100644
index 0000000000..210b715da8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/main/resources/impl-javaxml-validation-messages.properties
@@ -0,0 +1,23 @@
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+ClassNotFoundException = Class Not Found Exception: {0}
+ContributionResolveException = Contribution Resolve Exception occured due to:
+
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/AddService.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/AddService.java
new file mode 100644
index 0000000000..9c22177684
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/AddService.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+/**
+ * Interface for the Add Service.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface AddService {
+
+ double add(double n1, double n2);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/AddServiceImpl.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/AddServiceImpl.java
new file mode 100644
index 0000000000..3f28d740a7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/AddServiceImpl.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+import org.osoa.sca.annotations.EagerInit;
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * An implementation of the Add service.
+ *
+ * @version $Rev$ $Date$
+ */
+@Scope("COMPOSITE")
+@EagerInit
+public class AddServiceImpl implements AddService {
+
+ public double add(double n1, double n2) {
+ return n1 + n2;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/CalculatorService.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/CalculatorService.java
new file mode 100644
index 0000000000..e0cf23dc17
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/CalculatorService.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+/**
+ * The Calculator service interface.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface CalculatorService {
+
+ double add(double n1, double n2);
+
+ double subtract(double n1, double n2);
+
+ double multiply(double n1, double n2);
+
+ double divide(double n1, double n2);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/CalculatorServiceImpl.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/CalculatorServiceImpl.java
new file mode 100644
index 0000000000..c1fceb575d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/CalculatorServiceImpl.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * An implementation of the Calculator service.
+ *
+ * @version $Rev$ $Date$
+ */
+@Scope("COMPOSITE")
+public class CalculatorServiceImpl implements CalculatorService {
+
+ private AddService addService;
+ private SubtractService subtractService;
+ private MultiplyService multiplyService;
+ private DivideService divideService;
+
+ @Reference
+ public void setAddService(AddService addService) {
+ this.addService = addService;
+ }
+
+ @Reference
+ public void setSubtractService(SubtractService subtractService) {
+ this.subtractService = subtractService;
+ }
+
+ @Reference
+ public void setDivideService(DivideService divideService) {
+ this.divideService = divideService;
+ }
+
+ @Reference
+ public void setMultiplyService(MultiplyService multiplyService) {
+ this.multiplyService = multiplyService;
+ }
+
+ public double add(double n1, double n2) {
+ return addService.add(n1, n2);
+ }
+
+ public double subtract(double n1, double n2) {
+ return subtractService.subtract(n1, n2);
+ }
+
+ public double multiply(double n1, double n2) {
+ return multiplyService.multiply(n1, n2);
+ }
+
+ public double divide(double n1, double n2) {
+ return divideService.divide(n1, n2);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/DivideService.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/DivideService.java
new file mode 100644
index 0000000000..9599c86292
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/DivideService.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+/**
+ * Interface for the Divide Service.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface DivideService {
+
+ double divide(double n1, double n2);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/DivideServiceImpl.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/DivideServiceImpl.java
new file mode 100644
index 0000000000..e1f35f99b5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/DivideServiceImpl.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * An implementation of the Divide service.
+ *
+ * @version $Rev$ $Date$
+ */
+@Scope("COMPOSITE")
+public class DivideServiceImpl implements DivideService {
+
+ public double divide(double n1, double n2) {
+ return n1 / n2;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/MultiplyService.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/MultiplyService.java
new file mode 100644
index 0000000000..7a3d06c15e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/MultiplyService.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+/**
+ * Interface for the Multiply Service.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface MultiplyService {
+
+ double multiply(double n1, double n2);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/MultiplyServiceImpl.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/MultiplyServiceImpl.java
new file mode 100644
index 0000000000..d621407908
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/MultiplyServiceImpl.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * An implementation of the Multiply service.
+ *
+ * @version $Rev$ $Date$
+ */
+@Scope("COMPOSITE")
+public class MultiplyServiceImpl implements MultiplyService {
+
+ public double multiply(double n1, double n2) {
+ return n1 * n2;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/SubtractService.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/SubtractService.java
new file mode 100644
index 0000000000..21af91f392
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/SubtractService.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+/**
+ * Interface for the Subtract Service.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface SubtractService {
+
+ double subtract(double n1, double n2);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/SubtractServiceImpl.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/SubtractServiceImpl.java
new file mode 100644
index 0000000000..4fed0a8c6a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/calculator/SubtractServiceImpl.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package calculator;
+
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * An implementation of the subtract service.
+ *
+ * @version $Rev$ $Date$
+ */
+@Scope("COMPOSITE")
+public class SubtractServiceImpl implements SubtractService {
+
+ public double subtract(double n1, double n2) {
+ return n1 - n2;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/ReadTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/ReadTestCase.java
new file mode 100644
index 0000000000..e5912906f5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/ReadTestCase.java
@@ -0,0 +1,224 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.java.xml;
+
+import java.io.InputStream;
+import java.net.URI;
+import java.net.URL;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.OperationsConfigurator;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+
+/**
+ * Test reading Java implementations.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReadTestCase extends TestCase {
+
+ private XMLInputFactory inputFactory;
+ private StAXArtifactProcessor<Object> staxProcessor;
+ private URLArtifactProcessor<SCADefinitions> policyDefinitionsProcessor;
+ private CompositeBuilder compositeBuilder;
+
+ @Override
+ public void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ inputFactory = XMLInputFactory.newInstance();
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null);
+
+ ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ SCABindingFactory scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class);
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class);
+ IntentAttachPointTypeFactory attachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class);
+ compositeBuilder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, attachPointTypeFactory, mapper, null);
+
+ URLArtifactProcessorExtensionPoint documentProcessors = extensionPoints.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ policyDefinitionsProcessor = documentProcessors.getProcessor(SCADefinitions.class);
+ }
+
+ public void testReadComposite() throws Exception {
+ InputStream is = getClass().getResourceAsStream("Calculator.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = (Composite)staxProcessor.read(reader);
+ assertNotNull(composite);
+
+ compositeBuilder.build(composite);
+
+ }
+
+ public void fixmeTestPolicyIntents() throws Exception {
+ ModelResolver resolver = new TestModelResolver(getClass().getClassLoader());
+
+ URL url = getClass().getResource("definitions.xml");
+ URI uri = URI.create("definitions.xml");
+ SCADefinitions scaDefns = policyDefinitionsProcessor.read(null, uri, url);
+
+ InputStream is = getClass().getResourceAsStream("Calculator.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = (Composite)staxProcessor.read(reader);
+ assertNotNull(composite);
+
+ staxProcessor.resolve(scaDefns, resolver);
+ staxProcessor.resolve(composite, resolver);
+
+ compositeBuilder.build(composite);
+
+ //intents are computed and aggregate intents from ancestor elements
+ assertEquals(((PolicySetAttachPoint)composite.getComponents().get(0)).getRequiredIntents().size(), 3);
+ assertEquals(((PolicySetAttachPoint)composite.getComponents().get(5)).getRequiredIntents().size(), 3);
+
+ //assertEquals(((OperationsConfigurator)composite.getComponents().get(0)).getConfiguredOperations().isEmpty(), true);
+ //assertEquals(((OperationsConfigurator)composite.getComponents().get(5)).getConfiguredOperations().isEmpty(), false);
+
+
+ //test for proper aggregation of policy intents on implementation elements
+ for ( Intent intent : ((PolicySetAttachPoint)composite.getComponents().get(0).getImplementation()).getRequiredIntents() ) {
+ String intentName = intent.getName().getLocalPart();
+ if ( !(intentName.equals("tuscanyIntent_1") || intentName.equals("tuscanyIntent_2") ||
+ intentName.equals("tuscanyIntent_3")) ) {
+ fail();
+ }
+ }
+
+ for ( Intent intent : ((PolicySetAttachPoint)composite.getComponents().get(5)).getRequiredIntents() ) {
+ String intentName = intent.getName().getLocalPart();
+ if ( !(intentName.equals("tuscanyIntent_1") || intentName.equals("tuscanyIntent_4") ||
+ intentName.equals("tuscanyIntent_5")) ) {
+ fail();
+ }
+ }
+
+ //test for proper aggregation of policy intents and policysets on operations of implementation
+ OperationsConfigurator opConf = (OperationsConfigurator)composite.getComponents().get(5);
+ assertEquals(opConf.getConfiguredOperations().get(0).getRequiredIntents().size(), 4);
+ for ( Intent intent : opConf.getConfiguredOperations().get(0).getRequiredIntents()) {
+ String intentName = intent.getName().getLocalPart();
+ if ( !(intentName.equals("tuscanyIntent_1") || intentName.equals("tuscanyIntent_4") ||
+ intentName.equals("tuscanyIntent_5") || intentName.equals("tuscanyIntent_6") ) ) {
+ fail();
+ }
+ }
+
+ opConf = (OperationsConfigurator)composite.getComponents().get(6);
+ assertEquals(opConf.getConfiguredOperations().get(0).getRequiredIntents().size(), 3);
+ for ( Intent intent : opConf.getConfiguredOperations().get(0).getRequiredIntents()) {
+ String intentName = intent.getName().getLocalPart();
+ if ( !(intentName.equals("tuscanyIntent_1") || intentName.equals("tuscanyIntent_4") ||
+ intentName.equals("tuscanyIntent_6.qualified2") ) ) {
+ fail();
+ }
+ }
+ }
+
+ public void testPolicySets() throws Exception {
+ ModelResolver resolver = new TestModelResolver(getClass().getClassLoader());
+
+ URL url = getClass().getResource("definitions_with_policysets.xml");
+ URI uri = URI.create("definitions_with_policysets.xml");
+ SCADefinitions policyDefinitions = policyDefinitionsProcessor.read(null, uri, url);
+
+ InputStream is = getClass().getResourceAsStream("Calculator.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = (Composite)staxProcessor.read(reader);
+ assertNotNull(composite);
+
+ for ( Component component : composite.getComponents() ) {
+ for ( PolicySet policySet : policyDefinitions.getPolicySets() ) {
+ component.getApplicablePolicySets().add(policySet);
+ }
+ }
+
+ staxProcessor.resolve(policyDefinitions, resolver);
+ staxProcessor.resolve(composite, resolver);
+
+ compositeBuilder.build(composite);
+
+ //test for determination of policysets for implementation
+ assertEquals(((PolicySetAttachPoint)composite.getComponents().get(0)).getPolicySets().size(), 1);
+ for ( PolicySet policySet : ((PolicySetAttachPoint)composite.getComponents().get(0).getImplementation()).getPolicySets() ) {
+ String policySetName = policySet.getName().getLocalPart();
+ if ( !(policySetName.equals("tuscanyPolicySet_1")) ) {
+ fail();
+ }
+ }
+
+ assertEquals(((PolicySetAttachPoint)composite.getComponents().get(5)).getPolicySets().size(), 2);
+ for ( PolicySet policySet : ((PolicySetAttachPoint)composite.getComponents().get(5).getImplementation()).getPolicySets() ) {
+ String policySetName = policySet.getName().getLocalPart();
+ if ( !(policySetName.equals("tuscanyPolicySet_1") || policySetName.equals("tuscanyPolicySet_2")) ) {
+ fail();
+ }
+ }
+
+ //test for computation of policysets on operations of implementation
+ OperationsConfigurator opConf = (OperationsConfigurator)composite.getComponents().get(5);
+ assertEquals(opConf.getConfiguredOperations().get(0).getPolicySets().size(), 3);
+ for ( PolicySet policySet : opConf.getConfiguredOperations().get(0).getPolicySets() ) {
+ String policySetName = policySet.getName().getLocalPart();
+ if ( !(policySetName.equals("tuscanyPolicySet_1") || policySetName.equals("tuscanyPolicySet_2")
+ || policySetName.equals("tuscanyPolicySet_3")) ) {
+ fail();
+ }
+ }
+
+ opConf = (OperationsConfigurator)composite.getComponents().get(6);
+ assertEquals(opConf.getConfiguredOperations().get(0).getPolicySets().size(), 4);
+ for ( PolicySet policySet : opConf.getConfiguredOperations().get(0).getPolicySets() ) {
+ String policySetName = policySet.getName().getLocalPart();
+ if ( !(policySetName.equals("tuscanyPolicySet_1") || policySetName.equals("tuscanyPolicySet_2")
+ || policySetName.equals("tuscanyPolicySet_3")
+ || policySetName.equals("tuscanyPolicySet_4")) ) {
+ fail();
+ }
+ }
+ //new PrintUtil(System.out).print(composite);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/TestModelResolver.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/TestModelResolver.java
new file mode 100644
index 0000000000..27e3579c35
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/TestModelResolver.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.implementation.java.xml;
+
+import java.lang.ref.WeakReference;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.tuscany.sca.contribution.resolver.ClassReference;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+
+
+/**
+ * A default implementation of an artifact resolver, based on a map.
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestModelResolver implements ModelResolver {
+ private static final long serialVersionUID = -7826976465762296634L;
+
+ private Map<Object, Object> map = new HashMap<Object, Object>();
+
+ private WeakReference<ClassLoader> classLoader;
+
+ public TestModelResolver(ClassLoader classLoader) {
+ this.classLoader = new WeakReference<ClassLoader>(classLoader);
+ }
+
+ public <T> T resolveModel(Class<T> modelClass, T unresolved) {
+ Object resolved = map.get(unresolved);
+ if (resolved != null) {
+
+ // Return the resolved object
+ return modelClass.cast(resolved);
+
+ } else if (unresolved instanceof ClassReference) {
+
+ // Load a class on demand
+ ClassReference classReference = (ClassReference)unresolved;
+ Class clazz;
+ try {
+ clazz = Class.forName(classReference.getClassName(), true, classLoader.get());
+ } catch (ClassNotFoundException e) {
+
+ // Return the unresolved object
+ return unresolved;
+ }
+
+ // Store a new ClassReference wrapping the loaded class
+ resolved = new ClassReference(clazz);
+ map.put(resolved, resolved);
+
+ // Return the resolved ClassReference
+ return modelClass.cast(resolved);
+
+ } else {
+
+ // Return the unresolved object
+ return unresolved;
+ }
+ }
+
+ public void addModel(Object resolved) {
+ map.put(resolved, resolved);
+ }
+
+ public Object removeModel(Object resolved) {
+ return map.remove(resolved);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.java
new file mode 100644
index 0000000000..646b5db617
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/java/org/apache/tuscany/sca/implementation/java/xml/WriteTestCase.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.java.xml;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+
+/**
+ * Test writing Java implementations.
+ *
+ * @version $Rev$ $Date$
+ */
+public class WriteTestCase extends TestCase {
+
+ private StAXArtifactProcessor<Object> staxProcessor;
+ private XMLInputFactory inputFactory;
+ private XMLOutputFactory outputFactory;
+
+ @Override
+ public void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ inputFactory = XMLInputFactory.newInstance();
+ outputFactory = XMLOutputFactory.newInstance();
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null);
+ }
+
+ public void testReadWriteComposite() throws Exception {
+ InputStream is = getClass().getResourceAsStream("Calculator.composite");
+ Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is));
+ assertNotNull(composite);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos));
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/resources/org/apache/tuscany/sca/implementation/java/xml/Calculator.composite b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/resources/org/apache/tuscany/sca/implementation/java/xml/Calculator.composite
new file mode 100644
index 0000000000..a58fa0c072
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/resources/org/apache/tuscany/sca/implementation/java/xml/Calculator.composite
@@ -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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:calc="http://sample.calculator"
+ requires="cns:tuscanyIntent_1"
+ targetNamespace="http://sample.calculator"
+ xmlns:cns="http://test"
+ name="Calculator">
+
+ <service name="CalculatorService" promote="CalculatorServiceComponent">
+ <interface.java interface="calculator.CalculatorService"/>
+ </service>
+
+ <component name="CalculatorServiceComponent" requires="cns:tuscanyIntent_2">
+ <implementation.java class="calculator.CalculatorServiceImpl" requires="cns:tuscanyIntent_3" />
+ <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>
+
+ <component name="AnotherCalculatorServiceComponent" requires="cns:tuscanyIntent_4">
+ <implementation.java class="calculator.CalculatorServiceImpl" requires="cns:tuscanyIntent_5">
+ <operation name="add" requires="cns:tuscanyIntent_6"/>
+ </implementation.java>
+ </component>
+
+ <component name="YetAnotherCalculatorServiceComponent" requires="cns:tuscanyIntent_4">
+ <implementation.java class="calculator.CalculatorServiceImpl" requires="cns:tuscanyIntent_6.qualified1">
+ <operation name="add" requires="cns:tuscanyIntent_6.qualified2" policySets="cns:tuscanyPolicySet_4"/>
+ </implementation.java>
+ </component>
+</composite>
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/resources/org/apache/tuscany/sca/implementation/java/xml/definitions.xml b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/resources/org/apache/tuscany/sca/implementation/java/xml/definitions.xml
new file mode 100644
index 0000000000..cddc134c2c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/resources/org/apache/tuscany/sca/implementation/java/xml/definitions.xml
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<sca:definitions xmlns="http://test"
+ targetNamespace="http://test"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0">
+
+<!-- simple intent -->
+ <sca:intent name="tuscanyIntent_1"
+ constrains="sca:binding sca:implementation.java">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+ <sca:intent name="tuscanyIntent_2"
+ constrains="sca:binding sca:implementation.java">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+ <sca:intent name="tuscanyIntent_3"
+ constrains="sca:binding sca:implementation.java">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+ <sca:intent name="tuscanyIntent_4"
+ constrains="sca:binding sca:implementation.java">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+<sca:intent name="tuscanyIntent_5"
+ constrains="sca:binding sca:implementation.java">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+ <sca:intent name="tuscanyIntent_6"
+ constrains="sca:binding sca:implementation.java">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+ <sca:intent name="tuscanyIntent_7"
+ constrains="sca:binding sca:implementation.java">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+ <sca:intent name="tuscanyIntent_8"
+ constrains="sca:binding sca:implementation.java">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+ <!-- qualified intents -->
+ <sca:intent name="tuscanyIntent_1.qualified" />
+ <sca:intent name="tuscanyIntent_2.qualified" />
+ <sca:intent name="tuscanyIntent_6.qualified1" />
+ <sca:intent name="tuscanyIntent_6.qualified2" />
+
+ <sca:policySet name="tuscanyPolicySet_4"
+ provides="tuscanyIntent_6"
+ appliesTo="/sca:composite/sca:component"
+ xmlns="http://test"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <sca:intentMap provides="tuscanyIntent_6" default="qualified2">
+ <sca:qualifier name="qualified2">
+ <wsp:Policy>
+ <!-- policy expression and policy subject for "qualified2" alternative" -->
+ </wsp:Policy>
+ </sca:qualifier>
+ </sca:intentMap>
+ </sca:policySet>
+</sca:definitions> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/resources/org/apache/tuscany/sca/implementation/java/xml/definitions_with_policysets.xml b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/resources/org/apache/tuscany/sca/implementation/java/xml/definitions_with_policysets.xml
new file mode 100644
index 0000000000..9147133d5d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java-xml/src/test/resources/org/apache/tuscany/sca/implementation/java/xml/definitions_with_policysets.xml
@@ -0,0 +1,133 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<sca:definitions xmlns="http://test"
+ targetNamespace="http://test"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0">
+
+<!-- simple intent -->
+ <sca:intent name="tuscanyIntent_1"
+ constrains="sca:binding sca:implementation.java">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+ <sca:intent name="tuscanyIntent_2"
+ constrains="sca:binding sca:implementation.java">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+ <sca:intent name="tuscanyIntent_3"
+ constrains="sca:binding sca:implementation.java">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+ <sca:intent name="tuscanyIntent_4"
+ constrains="sca:binding sca:implementation.java">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+<sca:intent name="tuscanyIntent_5"
+ constrains="sca:binding sca:implementation.java">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+ <sca:intent name="tuscanyIntent_6"
+ constrains="sca:binding sca:implementation.java">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+ <sca:intent name="tuscanyIntent_7"
+ constrains="sca:binding sca:implementation.java">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+ <sca:intent name="tuscanyIntent_8"
+ constrains="sca:binding sca:implementation.java">
+ <sca:description>
+ Sample Intent
+ </sca:description>
+ </sca:intent>
+
+ <sca:policySet name="tuscanyPolicySet_1"
+ provides="tuscanyIntent_1 tuscanyIntent_2 tuscanyIntent_3"
+ appliesTo="/sca:composite/sca:component"
+ xmlns="http://test"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ </sca:policySet>
+
+ <sca:policySet name="tuscanyPolicySet_2"
+ provides="tuscanyIntent_4 tuscanyIntent_5"
+ appliesTo="/sca:composite/sca:component"
+ xmlns="http://test"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ </sca:policySet>
+
+ <sca:policySet name="tuscanyPolicySet_3"
+ provides="tuscanyIntent_6"
+ appliesTo="/sca:composite/sca:component"
+ xmlns="http://test"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <sca:intentMap provides="tuscanyIntent_6" default="qualified1">
+ <sca:qualifier name="qualified1">
+ <wsp:Policy>
+ <!-- policy expression and policy subject for "qualified1" alternative -->
+ </wsp:Policy>
+ </sca:qualifier>
+ <sca:qualifier name="qualifed2">
+ <wsp:Policy>
+ <!-- policy expression and policy subject for "qualified2" alternative" -->
+ </wsp:Policy>
+ </sca:qualifier>
+ </sca:intentMap>
+ </sca:policySet>
+
+ <sca:policySet name="tuscanyPolicySet_4"
+ provides="tuscanyIntent_6"
+ appliesTo="/sca:composite/sca:component"
+ xmlns="http://test"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <sca:intentMap provides="tuscanyIntent_6" default="qualified2">
+ <sca:qualifier name="qualified2">
+ <wsp:Policy>
+ <!-- policy expression and policy subject for "qualified2" alternative" -->
+ </wsp:Policy>
+ </sca:qualifier>
+ </sca:intentMap>
+ </sca:policySet>
+
+ <!-- qualified intents -->
+ <sca:intent name="tuscanyIntent_1.qualified" />
+ <sca:intent name="tuscanyIntent_2.qualified" />
+ <sca:intent name="tuscanyIntent_6.qualified1" />
+ <sca:intent name="tuscanyIntent_6.qualified2" />
+</sca:definitions> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/LICENSE b/sca-java-1.x/branches/sca-android/modules/implementation-java/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/META-INF/README b/sca-java-1.x/branches/sca-android/modules/implementation-java/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/NOTICE b/sca-java-1.x/branches/sca-android/modules/implementation-java/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/pom.xml b/sca-java-1.x/branches/sca-android/modules/implementation-java/pom.xml
new file mode 100644
index 0000000000..19adeeaf46
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/pom.xml
@@ -0,0 +1,84 @@
+<?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.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-implementation-java</artifactId>
+ <name>Apache Tuscany SCA Java Implementation Model</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-interface-java</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-sca-api</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.jws</groupId>
+ <artifactId>jsr181-api</artifactId>
+ <version>1.0-MR1</version>
+ </dependency>
+ </dependencies>
+
+ <repositories>
+ <repository>
+ <id>java.net</id>
+ <name>java.net Maven 1.x Repository</name>
+ <url>http://download.java.net/maven/1</url>
+ <layout>legacy</layout>
+ </repository>
+ </repositories>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.implementation.java</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.implementation.java*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/BaseJavaImplementation.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/BaseJavaImplementation.java
new file mode 100644
index 0000000000..c8b7c072ac
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/BaseJavaImplementation.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java;
+
+import org.apache.tuscany.sca.assembly.Extensible;
+import org.apache.tuscany.sca.assembly.Implementation;
+
+/**
+ * Represents a Java implementation.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface BaseJavaImplementation extends Implementation, Extensible {
+
+ /**
+ * Returns the name of the Java implementation class.
+ *
+ * @return the name of the Java implementation class
+ */
+ String getName();
+
+ /**
+ * Sets the name of the Java implementation class.
+ *
+ * @param className the name of the Java implementation class
+ */
+ void setName(String className);
+
+ /**
+ * Returns the Java implementation class.
+ *
+ * @return the Java implementation class
+ */
+ Class<?> getJavaClass();
+
+ /**
+ * Sets the Java implementation class.
+ *
+ * @param javaClass the Java implementation class
+ */
+ void setJavaClass(Class<?> javaClass);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/DefaultJavaImplementationFactory.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/DefaultJavaImplementationFactory.java
new file mode 100644
index 0000000000..e44ebd7c91
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/DefaultJavaImplementationFactory.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.implementation.java;
+
+/**
+ * A factory for the Java model.
+ *
+ * @version $Rev$ $Date$
+ */
+import org.apache.tuscany.sca.implementation.java.impl.JavaImplementationFactoryImpl;
+
+public class DefaultJavaImplementationFactory extends JavaImplementationFactoryImpl implements JavaImplementationFactory {
+
+ public DefaultJavaImplementationFactory() {
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/IntrospectionException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/IntrospectionException.java
new file mode 100644
index 0000000000..2198a632c0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/IntrospectionException.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java;
+
+import java.lang.reflect.Member;
+
+/**
+ * Denotes a problem processing annotations on a POJO implementation
+ *
+ * @version $Rev$ $Date$
+ */
+public class IntrospectionException extends Exception {
+ private static final long serialVersionUID = -361025119035104470L;
+ private Member member;
+
+ public IntrospectionException() {
+ }
+
+ public IntrospectionException(String message) {
+ super(message);
+ }
+
+ public IntrospectionException(String message, Member member) {
+ super(message);
+ this.member = member;
+ }
+
+ public IntrospectionException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public IntrospectionException(Throwable cause) {
+ super(cause);
+ }
+
+ public Member getMember() {
+ return member;
+ }
+
+ public void setMember(Member member) {
+ this.member = member;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/JavaImplementation.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/JavaImplementation.java
new file mode 100644
index 0000000000..2ad7edbd6f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/JavaImplementation.java
@@ -0,0 +1,198 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.java;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.sca.implementation.java.impl.JavaConstructorImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaResourceImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaScopeImpl;
+import org.apache.tuscany.sca.policy.util.PolicyHandlerTuple;
+
+/**
+ * Represents a Java implementation.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface JavaImplementation extends BaseJavaImplementation {
+
+ /**
+ * Returns the constructor used to instantiate implementation instances.
+ *
+ * @return the constructor used to instantiate implementation instances
+ */
+ JavaConstructorImpl<?> getConstructor();
+
+ /**
+ * Sets the constructor used to instantiate implementation instances
+ *
+ * @param definition the constructor used to instantiate implementation instances
+ */
+ void setConstructor(JavaConstructorImpl<?> definition);
+
+ /**
+ * Returns the component initializer method.
+ *
+ * @return the component initializer method
+ */
+ Method getInitMethod();
+
+ /**
+ * Sets the component initializer method.
+ *
+ * @param initMethod the component initializer method
+ */
+ void setInitMethod(Method initMethod);
+
+ /**
+ * Returns the component destructor method.
+ *
+ * @return the component destructor method
+ */
+ Method getDestroyMethod();
+
+ /**
+ * Sets the component destructor method.
+ *
+ * @param destroyMethod the component destructor method
+ */
+ void setDestroyMethod(Method destroyMethod);
+
+ /**
+ * Returns the resources injected into this implementation.
+ *
+ * @return
+ */
+ Map<String, JavaResourceImpl> getResources();
+
+ /**
+ * Returns the Java member used to inject a conversation ID.
+ *
+ * @return
+ */
+ List<Member> getConversationIDMembers();
+
+ /**
+ * Sets the Java member used to inject a conversation ID.
+ *
+ * @param conversationIDMember
+ */
+ void addConversationIDMember(Member conversationIDMember);
+
+ /**
+ * Returns true if AllowsPassReference is set.
+ *
+ * @return true if AllowsPassByReference is set
+ */
+ boolean isAllowsPassByReference();
+
+ /**
+ * @param allowsPassByReference the allowsPassByReference to set
+ */
+ void setAllowsPassByReference(boolean allowsPassByReference);
+
+ /**
+ * @return the allowsPassByReferenceMethods
+ */
+ List<Method> getAllowsPassByReferenceMethods();
+
+ /**
+ * @param method
+ * @return
+ */
+ boolean isAllowsPassByReference(Method method);
+
+ /**
+ * @return the constructors
+ */
+ Map<Constructor, JavaConstructorImpl> getConstructors();
+
+ /**
+ * @return the eagerInit
+ */
+ boolean isEagerInit();
+
+ /**
+ * @param eagerInit the eagerInit to set
+ */
+ void setEagerInit(boolean eagerInit);
+
+ /**
+ * @return the callbacks
+ */
+ Map<String, Collection<JavaElementImpl>> getCallbackMembers();
+
+ /**
+ * @return the properties
+ */
+ Map<String, JavaElementImpl> getPropertyMembers();
+
+ /**
+ * @return the references
+ */
+ Map<String, JavaElementImpl> getReferenceMembers();
+
+ /**
+ * @return the scope
+ */
+ JavaScopeImpl getJavaScope();
+
+ /**
+ * @param scope the scope to set
+ */
+ void setJavaScope(JavaScopeImpl scope);
+
+ /**
+ * @return the maxAge
+ */
+ long getMaxAge();
+
+ /**
+ * @param maxAge the maxAge to set
+ */
+ void setMaxAge(long maxAge);
+
+ /**
+ * @return the maxIdleTime
+ */
+ long getMaxIdleTime();
+
+ /**
+ * @param maxIdleTime the maxIdleTime to set
+ */
+ void setMaxIdleTime(long maxIdleTime);
+
+ /**
+ * @return the map of a policy handler class names
+ */
+ List<PolicyHandlerTuple> getPolicyHandlerClassNames();
+
+ /**
+ * @param policyHandlerClassNames Map of policyhandler class names
+ */
+ void setPolicyHandlerClassNames(List<PolicyHandlerTuple> policyHandlerClassNames);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/JavaImplementationFactory.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/JavaImplementationFactory.java
new file mode 100644
index 0000000000..8228c80372
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/JavaImplementationFactory.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor;
+
+
+/**
+ * Factory for the Java model
+ *
+ * @version $Rev$ $Date$
+ */
+public interface JavaImplementationFactory {
+
+ /**
+ * Creates a new Java implementation model.
+ *
+ * @return
+ */
+ JavaImplementation createJavaImplementation();
+
+ /**
+ * Creates a new Java implementation model from an implementation class.
+ *
+ * @param implementationClass The implementation class to introspect.
+ * @return
+ */
+ JavaImplementation createJavaImplementation(Class<?> implementationClass) throws IntrospectionException;
+
+ /**
+ * Creates the contents of a Java implementation model from an implementation class.
+ *
+ * @param implementationClass The implementation class to introspect.
+ * @return
+ */
+ void createJavaImplementation(JavaImplementation javaImplementation, Class<?> implementationClass) throws IntrospectionException;
+
+ /**
+ * Registers the given visitor.
+ *
+ * @param visitor
+ */
+ void addClassVisitor(JavaClassVisitor visitor);
+
+ /**
+ * Deregisters the given visitor.
+ */
+ void removeClassVisitor(JavaClassVisitor visitor);
+
+ /**
+ * Returns the list of visitors.
+ *
+ * @return
+ */
+ List<JavaClassVisitor> getClassVisitors();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/BaseJavaImplementationImpl.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/BaseJavaImplementationImpl.java
new file mode 100644
index 0000000000..97773879fa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/BaseJavaImplementationImpl.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.impl;
+
+import org.apache.tuscany.sca.assembly.impl.ImplementationImpl;
+import org.apache.tuscany.sca.implementation.java.BaseJavaImplementation;
+
+/**
+ * Represents a Java implementation.
+ *
+ * @version $Rev$ $Date$
+ */
+abstract class BaseJavaImplementationImpl extends ImplementationImpl implements BaseJavaImplementation {
+
+ private String className;
+ private Class<?> javaClass;
+
+ protected BaseJavaImplementationImpl() {
+ }
+
+ public String getName() {
+ if (isUnresolved()) {
+ return className;
+ } else if (javaClass != null) {
+ return javaClass.getName();
+ } else {
+ return null;
+ }
+ }
+
+ public void setName(String className) {
+ if (!isUnresolved()) {
+ throw new IllegalStateException();
+ }
+ this.className = className;
+ }
+
+ public Class<?> getJavaClass() {
+ return javaClass;
+ }
+
+ public void setJavaClass(Class<?> javaClass) {
+ this.javaClass = javaClass;
+ if (this.className == null) {
+ this.className = javaClass.getName();
+ }
+ }
+
+ @Override
+ public String toString() {
+ return getName();
+ }
+
+ @Override
+ public int hashCode() {
+ return String.valueOf(getName()).hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ } else if (obj instanceof BaseJavaImplementation) {
+ if (getName() != null) {
+ return getName().equals(((BaseJavaImplementation)obj).getName());
+ } else {
+ return ((BaseJavaImplementation)obj).getName() == null;
+ }
+ } else {
+ return false;
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaClassIntrospectorImpl.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaClassIntrospectorImpl.java
new file mode 100644
index 0000000000..0bcec3c78f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaClassIntrospectorImpl.java
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.impl;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.JavaIntrospectionHelper;
+
+/**
+ * An extensible Java class introspector implementation.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaClassIntrospectorImpl {
+
+ private List<JavaClassVisitor> visitors;
+
+ public JavaClassIntrospectorImpl(List<JavaClassVisitor> visitors) {
+ this.visitors = visitors;
+ }
+
+ /**
+ * JSR-250 PFD recommends the following guidelines for how annotations
+ * interact with inheritance in order to keep the resulting complexity in
+ * control:
+ * <ol>
+ * <li>Class-level annotations only affect the class they annotate and
+ * their members, that is, its methods and fields. They never affect a
+ * member declared by a superclass, even if it is not hidden or overridden
+ * by the class in question.
+ * <li>In addition to affecting the annotated class, class-level
+ * annotations may act as a shorthand for member-level annotations. If a
+ * member carries a specific member-level annotation, any annotations of the
+ * same type implied by a class-level annotation are ignored. In other
+ * words, explicit member-level annotations have priority over member-level
+ * annotations implied by a class-level annotation.
+ * <li>The interfaces implemented by a class never contribute annotations
+ * to the class itself or any of its members.
+ * <li>Members inherited from a superclass and which are not hidden or
+ * overridden maintain the annotations they had in the class that declared
+ * them, including member-level annotations implied by class-level ones.
+ * <li>Member-level annotations on a hidden or overridden member are always
+ * ignored.
+ * </ol>
+ */
+ public void introspectClass(JavaImplementation type, Class<?> clazz)
+ throws IntrospectionException {
+ for (JavaClassVisitor extension : visitors) {
+ extension.visitClass(clazz, type);
+ }
+
+ for (Constructor<?> constructor : clazz.getConstructors()) {
+ for (JavaClassVisitor extension : visitors) {
+ extension.visitConstructor(constructor, type);
+ // Assuming the visitClass or visitConstructor will populate the
+ // type.getConstructors
+ JavaConstructorImpl<?> definition = type.getConstructors().get(constructor);
+ if (definition != null) {
+ for (JavaParameterImpl p : definition.getParameters()) {
+ extension.visitConstructorParameter(p, type);
+ }
+ }
+ }
+ }
+
+ Set<Field> fields = JavaIntrospectionHelper.getAllPublicAndProtectedFields(clazz, true);
+ for (Field field : fields) {
+ for (JavaClassVisitor extension : visitors) {
+ extension.visitField(field, type);
+ }
+ }
+
+ // Check if any private fields have illegal annotations that should be raised as errors
+ Set<Field> privateFields = JavaIntrospectionHelper.getPrivateFields(clazz);
+ for (Field field : privateFields) {
+ for (JavaClassVisitor processor : visitors) {
+ processor.visitField(field, type);
+ }
+ }
+
+ Set<Method> methods = JavaIntrospectionHelper.getAllUniquePublicProtectedMethods(clazz, true);
+ for (Method method : methods) {
+ for (JavaClassVisitor processor : visitors) {
+ processor.visitMethod(method, type);
+ }
+ }
+
+ // Check if any private methods have illegal annotations that should be raised as errors
+ Set<Method> privateMethods = JavaIntrospectionHelper.getPrivateMethods(clazz);
+ for (Method method : privateMethods) {
+ for (JavaClassVisitor processor : visitors) {
+ processor.visitMethod(method, type);
+ }
+ }
+
+ Class superClass = clazz.getSuperclass();
+ if (superClass != null) {
+ visitSuperClass(superClass, type);
+ }
+
+ for (JavaClassVisitor extension : visitors) {
+ extension.visitEnd(clazz, type);
+ }
+ }
+
+ private void visitSuperClass(Class<?> clazz, JavaImplementation type) throws IntrospectionException {
+ if (!Object.class.equals(clazz)) {
+ for (JavaClassVisitor extension : visitors) {
+ extension.visitSuperClass(clazz, type);
+ }
+ clazz = clazz.getSuperclass();
+ if (clazz != null) {
+ visitSuperClass(clazz, type);
+ }
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaConstructorImpl.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaConstructorImpl.java
new file mode 100644
index 0000000000..c0b04b4b4e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaConstructorImpl.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.impl;
+
+import java.lang.reflect.Constructor;
+
+/**
+ * Hold injection information for the constructor used to instantiate a
+ * component implementation instance
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaConstructorImpl<T> {
+
+ private Constructor<T> constructor;
+ private JavaParameterImpl[] parameters;
+
+ public JavaConstructorImpl(Constructor<T> constructor) {
+ this.constructor = constructor;
+ int size = constructor.getParameterTypes().length;
+ parameters = new JavaParameterImpl[size];
+ for (int i = 0; i < size; i++) {
+ parameters[i] = new JavaParameterImpl(constructor, i);
+ }
+ }
+
+ public Constructor<T> getConstructor() {
+ return constructor;
+ }
+
+ /**
+ * @return the parameters
+ */
+ public JavaParameterImpl[] getParameters() {
+ return parameters;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaElementImpl.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaElementImpl.java
new file mode 100644
index 0000000000..2365298f71
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaElementImpl.java
@@ -0,0 +1,224 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.java.impl;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+
+/**
+ * This class represents a java element such as a Package, Class, Constructor,
+ * Field, Method or Parameter.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaElementImpl {
+ private AnnotatedElement anchor;
+ private ElementType elementType;
+ private Class<?> type;
+ private Type genericType;
+ private int index = -1;
+ private String name;
+ private Class<? extends Annotation> classifer;
+
+ public JavaElementImpl(Package pkg) {
+ this.anchor = pkg;
+ this.elementType = ElementType.PACKAGE;
+ this.name = pkg.getName();
+ }
+
+ public JavaElementImpl(Class<?> cls) {
+ this.anchor = cls;
+ this.elementType = ElementType.TYPE;
+ this.type = cls;
+ this.genericType = cls;
+ this.name = cls.getName();
+ }
+
+ public JavaElementImpl(Field field) {
+ this.anchor = field;
+ this.elementType = ElementType.FIELD;
+ this.type = field.getType();
+ this.genericType = field.getGenericType();
+ this.name = field.getName();
+ }
+
+ public JavaElementImpl(Constructor<?> constructor, int index) {
+ this.anchor = constructor;
+ this.elementType = ElementType.PARAMETER;
+ this.type = constructor.getParameterTypes()[index];
+ this.genericType = constructor.getGenericParameterTypes()[index];
+ this.index = index;
+ this.name = "";
+ }
+
+ public JavaElementImpl(Method method, int index) {
+ this.anchor = method;
+ this.elementType = ElementType.PARAMETER;
+ this.type = method.getParameterTypes()[index];
+ this.genericType = method.getGenericParameterTypes()[index];
+ this.index = index;
+ this.name = "";
+ }
+
+ /**
+ * For testing purpose
+ *
+ * @param name
+ * @param type
+ * @param classifer TODO
+ * @param elementType
+ */
+ public JavaElementImpl(String name, Class<?> type, Class<? extends Annotation> classifer) {
+ super();
+ this.type = type;
+ this.name = name;
+ this.classifer = classifer;
+ }
+
+ /**
+ * @return the anchor
+ */
+ public AnnotatedElement getAnchor() {
+ return anchor;
+ }
+
+ /**
+ * @return the elementType
+ */
+ public ElementType getElementType() {
+ return elementType;
+ }
+
+ /**
+ * @return the genericType
+ */
+ public Type getGenericType() {
+ return genericType;
+ }
+
+ /**
+ * @return the index
+ */
+ public int getIndex() {
+ return index;
+ }
+
+ /**
+ * @return the type
+ */
+ public Class<?> getType() {
+ return type;
+ }
+
+ public Annotation[] getAnnotations() {
+ if (elementType == ElementType.PARAMETER) {
+ if (anchor instanceof Method) {
+ // We only care about the method-level annotations
+ return ((Method)anchor).getAnnotations();
+ }
+ if (anchor instanceof Constructor) {
+ return ((Constructor)anchor).getParameterAnnotations()[index];
+ }
+ }
+ return anchor.getAnnotations();
+ }
+
+ public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
+ for (Annotation a : getAnnotations()) {
+ if (a.annotationType() == annotationType) {
+ return annotationType.cast(a);
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ return anchor.toString() + (elementType == ElementType.PARAMETER ? "[" + index + "]" : "");
+ }
+
+ @Override
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + ((anchor == null) ? 0 : anchor.hashCode());
+ result = PRIME * result + index;
+ 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 JavaElementImpl other = (JavaElementImpl)obj;
+ if (anchor == null) {
+ if (other.anchor != null) {
+ return false;
+ }
+ } else if (!anchor.equals(other.anchor)) {
+ return false;
+ }
+ if (index != other.index) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @return the classifier
+ */
+ public Class<? extends Annotation> getClassifer() {
+ return classifer;
+ }
+
+ /**
+ * @param classifer the classifier to set
+ */
+ public void setClassifer(Class<? extends Annotation> classifer) {
+ this.classifer = classifer;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaImplementationActivator.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaImplementationActivator.java
new file mode 100644
index 0000000000..46594e0f50
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaImplementationActivator.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.java.impl;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ModuleActivator;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.AllowsPassByReferenceProcessor;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.BaseJavaClassVisitor;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.ComponentNameProcessor;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.ConstructorProcessor;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.ContextProcessor;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.ConversationIDProcessor;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.ConversationProcessor;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.DestroyProcessor;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.EagerInitProcessor;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.HeuristicPojoProcessor;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.InitProcessor;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.PolicyProcessor;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.PropertyProcessor;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.ReferenceProcessor;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.ResourceProcessor;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.ScopeProcessor;
+import org.apache.tuscany.sca.implementation.java.introspect.impl.ServiceProcessor;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+
+/**
+ * A module activator for the Java implementation model.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaImplementationActivator implements ModuleActivator {
+
+ public void start(ExtensionPointRegistry registry) {
+ ModelFactoryExtensionPoint modelFactories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ JavaInterfaceFactory javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class);
+ PolicyFactory policyFactory = modelFactories.getFactory(PolicyFactory.class);
+
+ BaseJavaClassVisitor[] extensions =
+ new BaseJavaClassVisitor[] {new ConstructorProcessor(assemblyFactory),
+ new AllowsPassByReferenceProcessor(assemblyFactory),
+ new ComponentNameProcessor(assemblyFactory),
+ new ContextProcessor(assemblyFactory),
+ new ConversationIDProcessor(assemblyFactory),
+ new ConversationProcessor(assemblyFactory),
+ new DestroyProcessor(assemblyFactory), new EagerInitProcessor(assemblyFactory),
+ new InitProcessor(assemblyFactory), new PropertyProcessor(assemblyFactory),
+ new ReferenceProcessor(assemblyFactory, javaFactory),
+ new ResourceProcessor(assemblyFactory), new ScopeProcessor(assemblyFactory),
+ new ServiceProcessor(assemblyFactory, javaFactory),
+ new HeuristicPojoProcessor(assemblyFactory, javaFactory),
+ new PolicyProcessor(assemblyFactory, policyFactory)};
+
+ JavaImplementationFactory javaImplementationFactory = modelFactories.getFactory(JavaImplementationFactory.class);
+ for (JavaClassVisitor extension : extensions) {
+ javaImplementationFactory.addClassVisitor(extension);
+ }
+
+ }
+
+ public void stop(ExtensionPointRegistry registry) {
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaImplementationFactoryImpl.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaImplementationFactoryImpl.java
new file mode 100644
index 0000000000..0cc78498e6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaImplementationFactoryImpl.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor;
+
+/**
+ * A factory for the Java model.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class JavaImplementationFactoryImpl implements JavaImplementationFactory {
+
+ private List<JavaClassVisitor> visitors = new ArrayList<JavaClassVisitor>();
+ private JavaClassIntrospectorImpl introspector;
+
+ public JavaImplementationFactoryImpl() {
+ introspector = new JavaClassIntrospectorImpl(visitors);
+ }
+
+ public JavaImplementation createJavaImplementation() {
+ JavaImplementation javaImplementation = new JavaImplementationImpl();
+ return javaImplementation;
+ }
+
+ public JavaImplementation createJavaImplementation(Class<?> implementationClass) throws IntrospectionException {
+ JavaImplementation javaImplementation = createJavaImplementation();
+ introspector.introspectClass(javaImplementation, implementationClass);
+ return javaImplementation;
+ }
+
+ public void createJavaImplementation(JavaImplementation javaImplementation, Class<?> implementationClass) throws IntrospectionException {
+ introspector.introspectClass(javaImplementation, implementationClass);
+ }
+
+ public void addClassVisitor(JavaClassVisitor visitor) {
+ visitors.add(visitor);
+ }
+
+ public void removeClassVisitor(JavaClassVisitor visitor) {
+ visitors.remove(visitor);
+ }
+
+ public List<JavaClassVisitor> getClassVisitors() {
+ return visitors;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaImplementationImpl.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaImplementationImpl.java
new file mode 100644
index 0000000000..375896cf26
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaImplementationImpl.java
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.impl;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.policy.util.PolicyHandlerTuple;
+
+/**
+ * A component type specialization for POJO implementations
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaImplementationImpl extends BaseJavaImplementationImpl implements JavaImplementation {
+ private JavaConstructorImpl<?> constructorDefinition;
+ private Map<Constructor, JavaConstructorImpl> constructors = new HashMap<Constructor, JavaConstructorImpl>();
+ private Method initMethod;
+ private Method destroyMethod;
+ private final Map<String, JavaResourceImpl> resources = new HashMap<String, JavaResourceImpl>();
+ private final Map<String, JavaElementImpl> propertyMembers = new HashMap<String, JavaElementImpl>();
+ private final Map<String, JavaElementImpl> referenceMembers = new HashMap<String, JavaElementImpl>();
+ private final Map<String, Collection<JavaElementImpl>> callbackMembers = new HashMap<String, Collection<JavaElementImpl>>();
+ private List<Member> conversationIDMember = new ArrayList<Member>();
+ private boolean eagerInit;
+ private boolean allowsPassByReference;
+ private List<Method> allowsPassByReferenceMethods = new ArrayList<Method>();
+ private long maxAge = -1;
+ private long maxIdleTime = -1;
+ private JavaScopeImpl scope = JavaScopeImpl.STATELESS;
+ private List<PolicyHandlerTuple> policyHandlerClassNames = null;
+
+ protected JavaImplementationImpl() {
+ super();
+ }
+
+ public JavaConstructorImpl<?> getConstructor() {
+ return constructorDefinition;
+ }
+
+ public void setConstructor(JavaConstructorImpl<?> definition) {
+ this.constructorDefinition = definition;
+ }
+
+ public Method getInitMethod() {
+ return initMethod;
+ }
+
+ public void setInitMethod(Method initMethod) {
+ this.initMethod = initMethod;
+ }
+
+ public Method getDestroyMethod() {
+ return destroyMethod;
+ }
+
+ public void setDestroyMethod(Method destroyMethod) {
+ this.destroyMethod = destroyMethod;
+ }
+
+ public Map<String, JavaResourceImpl> getResources() {
+ return resources;
+ }
+
+ public List<Member> getConversationIDMembers() {
+ return this.conversationIDMember;
+ }
+
+ public void addConversationIDMember(Member conversationIDMember) {
+ this.conversationIDMember.add(conversationIDMember);
+ }
+
+ public boolean isAllowsPassByReference() {
+ return allowsPassByReference;
+ }
+
+ public void setAllowsPassByReference(boolean allowsPassByReference) {
+ this.allowsPassByReference = allowsPassByReference;
+ }
+
+ public List<Method> getAllowsPassByReferenceMethods() {
+ return allowsPassByReferenceMethods;
+ }
+
+ public boolean isAllowsPassByReference(Method method) {
+ return allowsPassByReference || allowsPassByReferenceMethods.contains(method);
+ }
+
+ public Map<Constructor, JavaConstructorImpl> getConstructors() {
+ return constructors;
+ }
+
+ public boolean isEagerInit() {
+ return eagerInit;
+ }
+
+ public void setEagerInit(boolean eagerInit) {
+ this.eagerInit = eagerInit;
+ }
+
+ public Map<String, Collection<JavaElementImpl>> getCallbackMembers() {
+ return callbackMembers;
+ }
+
+ public Map<String, JavaElementImpl> getPropertyMembers() {
+ return propertyMembers;
+ }
+
+ public Map<String, JavaElementImpl> getReferenceMembers() {
+ return referenceMembers;
+ }
+
+ public JavaScopeImpl getJavaScope() {
+ return scope;
+ }
+
+ public void setJavaScope(JavaScopeImpl scope) {
+ this.scope = scope;
+ }
+
+ public long getMaxAge() {
+ return maxAge;
+ }
+
+ public void setMaxAge(long maxAge) {
+ this.maxAge = maxAge;
+ }
+
+ public long getMaxIdleTime() {
+ return maxIdleTime;
+ }
+
+ public void setMaxIdleTime(long maxIdleTime) {
+ this.maxIdleTime = maxIdleTime;
+ }
+
+ public List<PolicyHandlerTuple> getPolicyHandlerClassNames() {
+ return policyHandlerClassNames;
+ }
+
+ public void setPolicyHandlerClassNames(List<PolicyHandlerTuple> policyHandlerClassNames) {
+ this.policyHandlerClassNames = policyHandlerClassNames;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaParameterImpl.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaParameterImpl.java
new file mode 100644
index 0000000000..c4c528f4f2
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaParameterImpl.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.implementation.java.impl;
+
+import java.lang.reflect.Constructor;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaParameterImpl extends JavaElementImpl {
+ /**
+ * @param constructor
+ * @param index
+ */
+ public JavaParameterImpl(Constructor<?> constructor, int index) {
+ super(constructor, index);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaResourceImpl.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaResourceImpl.java
new file mode 100644
index 0000000000..1aca15ebb8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaResourceImpl.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.impl;
+
+
+/**
+ * A resource dependency declared by a Java component implementation
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaResourceImpl {
+ private JavaElementImpl element;
+ private String mappedName;
+ private boolean optional;
+
+ public JavaResourceImpl(JavaElementImpl element) {
+ this.element = element;
+ }
+
+ /**
+ * The name of the resource
+ *
+ * @return the name of the resource
+ */
+ public String getName() {
+ return element.getName();
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * @return the element
+ */
+ public JavaElementImpl getElement() {
+ return element;
+ }
+
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaScopeImpl.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaScopeImpl.java
new file mode 100644
index 0000000000..85c2f73f75
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/impl/JavaScopeImpl.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.impl;
+
+/**
+ * The default implementation scopes supported by assemblies.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaScopeImpl {
+ public static final JavaScopeImpl STATELESS = new JavaScopeImpl("STATELESS");
+ public static final JavaScopeImpl REQUEST = new JavaScopeImpl("REQUEST");
+ public static final JavaScopeImpl SESSION = new JavaScopeImpl("SESSION");
+ public static final JavaScopeImpl CONVERSATION = new JavaScopeImpl("CONVERSATION");
+ public static final JavaScopeImpl COMPOSITE = new JavaScopeImpl("COMPOSITE");
+ public static final JavaScopeImpl SYSTEM = new JavaScopeImpl("SYSTEM");
+ public static final JavaScopeImpl UNDEFINED = new JavaScopeImpl("UNDEFINED");
+
+ private String scope;
+
+ public JavaScopeImpl(String scope) {
+ this.scope = scope.toUpperCase().intern();
+ }
+
+ public String getScope() {
+ return scope;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ final JavaScopeImpl scope1 = (JavaScopeImpl) o;
+ return !(scope != null ? scope != scope1.scope.intern() : scope1.scope != null);
+ }
+
+ @Override
+ public int hashCode() {
+ return scope != null ? scope.hashCode() : 0;
+ }
+
+ @Override
+ public String toString() {
+ return scope;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/JavaClassVisitor.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/JavaClassVisitor.java
new file mode 100644
index 0000000000..4fa40dee4b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/JavaClassVisitor.java
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.impl.JavaParameterImpl;
+
+/**
+ * Implementations process class-level metadata, typically parsing annotations
+ * and updating the corresponding <code>ComponentType</code>. A processor
+ * may, for example, create a Property 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 evaluating an assembly. It is the responsibility of the parser to
+ * determine whether to perform an action during the callback.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface JavaClassVisitor {
+
+ /**
+ * 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
+ * @throws IntrospectionException if an error is encountered while processing
+ * metadata
+ */
+ <T> void visitClass(Class<T> clazz, JavaImplementation type) throws IntrospectionException;
+
+ /**
+ * 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
+ * @throws IntrospectionException if an error is encountered while processing
+ * metadata
+ */
+ <T> void visitSuperClass(Class<T> clazz, JavaImplementation type) throws IntrospectionException;
+
+ /**
+ * 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
+ * @throws IntrospectionException if an error is encountered while processing
+ * metadata
+ */
+ void visitMethod(Method method, JavaImplementation type) throws IntrospectionException;
+
+ /**
+ * 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
+ * @throws IntrospectionException if an error is encountered while processing
+ * metadata
+ */
+ <T> void visitConstructor(Constructor<T> constructor, JavaImplementation type) throws IntrospectionException;
+
+ /**
+ * @param parameter
+ * @param type
+ * @throws IntrospectionException
+ */
+ void visitConstructorParameter(JavaParameterImpl parameter, JavaImplementation type) throws IntrospectionException;
+
+ /**
+ * 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
+ * @throws IntrospectionException if an error is encountered while processing
+ * metadata
+ */
+ void visitField(Field field, JavaImplementation type) throws IntrospectionException;
+
+ /**
+ * 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
+ * @throws IntrospectionException if an error is encountered while processing
+ * metadata
+ */
+ <T> void visitEnd(Class<T> clazz, JavaImplementation type) throws IntrospectionException;
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java
new file mode 100644
index 0000000000..9596fe0808
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessor.java
@@ -0,0 +1,192 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.annotation.Annotation;
+import java.lang.annotation.ElementType;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaParameterImpl;
+import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper;
+
+/**
+ * Base class for ImplementationProcessors that handle annotations that add
+ * Properties.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class AbstractPropertyProcessor<A extends Annotation> extends BaseJavaClassVisitor {
+ private final Class<A> annotationClass;
+
+ protected AbstractPropertyProcessor(AssemblyFactory assemblyFactory, Class<A> annotationClass) {
+ super(assemblyFactory);
+ this.annotationClass = annotationClass;
+ }
+
+ private boolean removeProperty(JavaElementImpl prop, JavaImplementation type) {
+ if(prop==null) {
+ return false;
+ }
+ List<Property> props = type.getProperties();
+ for(int i=0;i<props.size();i++) {
+ if(props.get(i).getName().equals(prop.getName())) {
+ props.remove(i);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException {
+ A annotation = method.getAnnotation(annotationClass);
+ if (annotation == null) {
+ return;
+ }
+
+ if (!JavaIntrospectionHelper.isSetter(method)) {
+ throw new IllegalPropertyException("Annotated method is not a setter: " + method, method);
+ }
+
+ String name = getName(annotation);
+ if (name == null || "".equals(name)) {
+ name = method.getName();
+ if (name.startsWith("set")) {
+ name = JavaIntrospectionHelper.toPropertyName(method.getName());
+ }
+ }
+
+ Map<String, JavaElementImpl> properties = type.getPropertyMembers();
+ JavaElementImpl prop = properties.get(name);
+ // Setter override field
+ if (prop != null && prop.getElementType() != ElementType.FIELD) {
+ throw new DuplicatePropertyException(name);
+ }
+
+ removeProperty(prop, type);
+
+ JavaElementImpl element = new JavaElementImpl(method, 0);
+ Property property = createProperty(name, element);
+
+ // add databinding available as annotations, as extensions
+
+ initProperty(property, annotation);
+ type.getProperties().add(property);
+ properties.put(name, element);
+ }
+
+ @Override
+ public void visitField(Field field, JavaImplementation type) throws IntrospectionException {
+
+ A annotation = field.getAnnotation(annotationClass);
+ if (annotation == null) {
+ return;
+ }
+
+ String name = getName(annotation);
+ if (name == null) {
+ name = "";
+ }
+ if ("".equals(name) || name.equals(field.getType().getName())) {
+ name = field.getName();
+ }
+
+ Map<String, JavaElementImpl> properties = type.getPropertyMembers();
+ JavaElementImpl prop = properties.get(name);
+ // Setter override field
+ if (prop != null && prop.getElementType() == ElementType.FIELD) {
+ throw new DuplicatePropertyException(name);
+ }
+
+ if (prop == null) {
+ JavaElementImpl element = new JavaElementImpl(field);
+ Property property = createProperty(name, element);
+ initProperty(property, annotation);
+ type.getProperties().add(property);
+ properties.put(name, element);
+ }
+ }
+
+ @Override
+ public void visitConstructorParameter(JavaParameterImpl parameter, JavaImplementation type)
+ throws IntrospectionException {
+
+ Map<String, JavaElementImpl> properties = type.getPropertyMembers();
+ A annotation = parameter.getAnnotation(annotationClass);
+ if (annotation != null) {
+ String name = getName(annotation);
+ if (name == null) {
+ name = parameter.getType().getName();
+ }
+ if (!"".equals(name) && !"".equals(parameter.getName()) && !name.equals(parameter.getName())) {
+ throw new InvalidConstructorException("Mismatched property name: " + parameter);
+ }
+ if ("".equals(name) && "".equals(parameter.getName())) {
+ throw new InvalidPropertyException("Missing property name: " + parameter);
+ }
+ if ("".equals(name)) {
+ name = parameter.getName();
+ }
+
+ JavaElementImpl prop = properties.get(name);
+ // Setter override field
+ if (prop != null && prop.getElementType() != ElementType.FIELD) {
+ throw new DuplicatePropertyException(name);
+ }
+ removeProperty(prop, type);
+
+ parameter.setName(name);
+ parameter.setClassifer(annotationClass);
+ Property property = createProperty(name, parameter);
+ initProperty(property, annotation);
+ type.getProperties().add(property);
+ properties.put(name, parameter);
+ }
+ }
+
+ protected abstract String getName(A annotation);
+
+ protected abstract void initProperty(Property property, A annotation) throws IntrospectionException;
+
+ @SuppressWarnings("unchecked")
+ protected Property createProperty(String name, JavaElementImpl element) throws IntrospectionException {
+
+ Property property = assemblyFactory.createProperty();
+ property.setName(name);
+ Class<?> baseType = JavaIntrospectionHelper.getBaseType(element.getType(), element.getGenericType());
+ property.setXSDType(JavaXMLMapper.getXMLType(baseType));
+
+ Class<?> javaType = element.getType();
+ if (javaType.isArray() || Collection.class.isAssignableFrom(javaType)) {
+ property.setMany(true);
+ }
+ return property;
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AllowsPassByReferenceProcessor.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AllowsPassByReferenceProcessor.java
new file mode 100644
index 0000000000..4a3ce0c343
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AllowsPassByReferenceProcessor.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.osoa.sca.annotations.AllowsPassByReference;
+
+/**
+ * Processes {@link AllowsPassByReference} on an implementation
+ *
+ * @version $Rev$ $Date$
+ */
+public class AllowsPassByReferenceProcessor extends BaseJavaClassVisitor {
+
+ public AllowsPassByReferenceProcessor(AssemblyFactory factory) {
+ super(factory);
+ }
+
+ @Override
+ public <T> void visitClass(Class<T> clazz, JavaImplementation type) throws IntrospectionException {
+ type.setAllowsPassByReference(clazz.isAnnotationPresent(AllowsPassByReference.class));
+ }
+
+ @Override
+ public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException {
+ boolean pbr = method.isAnnotationPresent(AllowsPassByReference.class);
+ if (pbr) {
+ type.getAllowsPassByReferenceMethods().add(method);
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AmbiguousConstructorException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AmbiguousConstructorException.java
new file mode 100644
index 0000000000..c6e6b6e4d6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AmbiguousConstructorException.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Member;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+
+/**
+ * Thrown when constructor parameters cannot be unambiguously resolved to a property or reference
+ *
+ * @version $Rev$ $Date$
+ */
+public class AmbiguousConstructorException extends IntrospectionException {
+ private static final long serialVersionUID = 3662860753837091880L;
+
+ public AmbiguousConstructorException(String message) {
+ super(message);
+ }
+
+ public AmbiguousConstructorException(String message, Member member) {
+ super(message, member);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/BaseJavaClassVisitor.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/BaseJavaClassVisitor.java
new file mode 100644
index 0000000000..bc6551d45d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/BaseJavaClassVisitor.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.impl.JavaParameterImpl;
+import org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor;
+
+/**
+ * A convenience class for annotation processors which alleviates the need to
+ * implement unused callbacks
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class BaseJavaClassVisitor implements JavaClassVisitor {
+ protected AssemblyFactory assemblyFactory;
+
+ protected BaseJavaClassVisitor(AssemblyFactory factory) {
+ this.assemblyFactory = factory;
+ }
+
+ public <T> void visitClass(Class<T> clazz, JavaImplementation type) throws IntrospectionException {
+ }
+
+ public <T> void visitSuperClass(Class<T> clazz, JavaImplementation type) throws IntrospectionException {
+ }
+
+ public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException {
+ }
+
+ public <T> void visitConstructor(Constructor<T> constructor, JavaImplementation type) throws IntrospectionException {
+ }
+
+ public void visitField(Field field, JavaImplementation type) throws IntrospectionException {
+ }
+
+ public <T> void visitEnd(Class<T> clazz, JavaImplementation type) throws IntrospectionException {
+ }
+
+ public void visitConstructorParameter(JavaParameterImpl parameter, JavaImplementation type) throws IntrospectionException {
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ComponentNameProcessor.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ComponentNameProcessor.java
new file mode 100644
index 0000000000..556f0b77e9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ComponentNameProcessor.java
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaResourceImpl;
+import org.osoa.sca.annotations.ComponentName;
+
+/**
+ * Processes {@link @ComponentName} annotations on a component implementation and adds
+ * a {@link JavaMappedProperty} to the component type which will be used to
+ * inject the appropriate component name.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ComponentNameProcessor extends BaseJavaClassVisitor {
+
+ public ComponentNameProcessor(AssemblyFactory factory) {
+ super(factory);
+ }
+
+ @Override
+ public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException {
+ if (method.getAnnotation(ComponentName.class) == null) {
+ return;
+ }
+ if (method.getParameterTypes().length != 1) {
+ throw new IllegalContextException("ComponentName setter must have one parameter", method);
+ }
+ Class<?> paramType = method.getParameterTypes()[0];
+ String name = JavaIntrospectionHelper.toPropertyName(method.getName());
+ if (String.class.equals(paramType)) {
+ JavaElementImpl element = new JavaElementImpl(method, 0);
+ element.setName(name);
+ element.setClassifer(org.apache.tuscany.sca.implementation.java.introspect.impl.Resource.class);
+ JavaResourceImpl resource = new JavaResourceImpl(element);
+ type.getResources().put(resource.getName(), resource);
+ } else {
+ throw new IllegalContextException(paramType.getName());
+ }
+ }
+
+ @Override
+ public void visitField(Field field, JavaImplementation type) throws IntrospectionException {
+ if (field.getAnnotation(ComponentName.class) == null) {
+ return;
+ }
+ Class<?> paramType = field.getType();
+ if (String.class.equals(paramType)) {
+ JavaElementImpl element = new JavaElementImpl(field);
+ element.setClassifer(Resource.class);
+ JavaResourceImpl resource = new JavaResourceImpl(element);
+ type.getResources().put(resource.getName(), resource);
+ } else {
+ throw new IllegalContextException(paramType.getName());
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessor.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessor.java
new file mode 100644
index 0000000000..17e28479d3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessor.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Constructor;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.impl.JavaConstructorImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaParameterImpl;
+
+/**
+ * Handles processing of a constructor decorated with
+ * {@link org.osoa.sca.annotations.Constructor}
+ *
+ * @version $Rev$ $Date$
+ */
+@SuppressWarnings("unchecked")
+public class ConstructorProcessor extends BaseJavaClassVisitor {
+
+ public ConstructorProcessor(AssemblyFactory factory) {
+ super(factory);
+ }
+
+ @Override
+ public <T> void visitClass(Class<T> clazz, JavaImplementation type) throws IntrospectionException {
+ Constructor[] ctors = clazz.getConstructors();
+ boolean found = false;
+ for (Constructor constructor : ctors) {
+ JavaConstructorImpl<?> definition = new JavaConstructorImpl(constructor);
+ type.getConstructors().put(constructor, definition);
+ if (constructor.getAnnotation(org.osoa.sca.annotations.Constructor.class) != null) {
+ if (found) {
+ throw new DuplicateConstructorException("Multiple constructors marked with @Constructor", constructor);
+ }
+ found = true;
+ type.setConstructor(definition);
+ }
+ }
+ }
+
+ @Override
+ public <T> void visitConstructor(Constructor<T> constructor, JavaImplementation type)
+ throws IntrospectionException {
+ org.osoa.sca.annotations.Constructor annotation = constructor
+ .getAnnotation(org.osoa.sca.annotations.Constructor.class);
+ if (annotation == null) {
+ return;
+ }
+ JavaConstructorImpl<?> definition = type.getConstructor();
+ if (definition == null) {
+ definition = new JavaConstructorImpl(constructor);
+ type.setConstructor(definition);
+ }
+ JavaParameterImpl[] parameters = definition.getParameters();
+ String[] value = annotation.value();
+ boolean isDefault = value.length == 0 || (value.length == 1 && "".equals(value[0]));
+ if (!isDefault && value.length != parameters.length) {
+ throw new InvalidConstructorException("Invalid Number of names in @Constructor");
+ }
+ for (int i = 0; i < parameters.length; i++) {
+ parameters[i].setName(i < value.length ? value[i] : "");
+ }
+ type.setConstructor(definition);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ContextProcessor.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ContextProcessor.java
new file mode 100644
index 0000000000..177ceaa57c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ContextProcessor.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaResourceImpl;
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.RequestContext;
+import org.osoa.sca.annotations.Context;
+
+/**
+ * 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 BaseJavaClassVisitor {
+
+ public ContextProcessor(AssemblyFactory factory) {
+ super(factory);
+ }
+
+ @Override
+ public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException {
+ if (method.getAnnotation(Context.class) == null) {
+ return;
+ }
+ if (method.getParameterTypes().length != 1) {
+ throw new IllegalContextException("Context setter must have one parameter", method);
+ }
+ Class<?> paramType = method.getParameterTypes()[0];
+ String name = JavaIntrospectionHelper.toPropertyName(method.getName());
+ if (ComponentContext.class.equals(paramType) || RequestContext.class.equals(paramType)) {
+ JavaElementImpl element = new JavaElementImpl(method, 0);
+ element.setName(name);
+ element.setClassifer(org.apache.tuscany.sca.implementation.java.introspect.impl.Resource.class);
+ JavaResourceImpl resource = new JavaResourceImpl(element);
+ type.getResources().put(resource.getName(), resource);
+ } else {
+ throw new UnknownContextTypeException(paramType.getName());
+ }
+ }
+
+ @Override
+ public void visitField(Field field, JavaImplementation type) throws IntrospectionException {
+ if (field.getAnnotation(Context.class) == null) {
+ return;
+ }
+ Class<?> paramType = field.getType();
+ if (ComponentContext.class.equals(paramType) || RequestContext.class.equals(paramType)) {
+ JavaElementImpl element = new JavaElementImpl(field);
+ element.setClassifer(Resource.class);
+ JavaResourceImpl resource = new JavaResourceImpl(element);
+ type.getResources().put(resource.getName(), resource);
+ } else {
+ throw new UnknownContextTypeException(paramType.getName());
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessor.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessor.java
new file mode 100644
index 0000000000..985f8baa82
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessor.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaResourceImpl;
+import org.osoa.sca.annotations.ConversationID;
+
+/**
+ * Processes {@link @ConversationID} annotations on a component implementation and adds
+ * a {@link JavaMappedProperty} to the component type which will be used to
+ * inject the appropriate conversationId
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConversationIDProcessor extends BaseJavaClassVisitor {
+
+ public ConversationIDProcessor(AssemblyFactory factory) {
+ super(factory);
+ }
+
+ @Override
+ public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException {
+ if (method.getAnnotation(ConversationID.class) == null) {
+ return;
+ }
+ if (method.getParameterTypes().length != 1) {
+ throw new IllegalContextException("ConversationID setter must have one parameter", method);
+ }
+ String name = JavaIntrospectionHelper.toPropertyName(method.getName());
+ JavaElementImpl element = new JavaElementImpl(method, 0);
+ element.setName(name);
+ element.setClassifer(org.apache.tuscany.sca.implementation.java.introspect.impl.Resource.class);
+ JavaResourceImpl resource = new JavaResourceImpl(element);
+ type.getResources().put(resource.getName(), resource);
+ }
+
+ @Override
+ public void visitField(Field field, JavaImplementation type) throws IntrospectionException {
+ if (field.getAnnotation(ConversationID.class) == null) {
+ return;
+ }
+ JavaElementImpl element = new JavaElementImpl(field);
+ element.setClassifer(org.apache.tuscany.sca.implementation.java.introspect.impl.Resource.class);
+ JavaResourceImpl resource = new JavaResourceImpl(element);
+ type.getResources().put(resource.getName(), resource);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationProcessor.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationProcessor.java
new file mode 100644
index 0000000000..efd04262dd
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationProcessor.java
@@ -0,0 +1,132 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.osoa.sca.annotations.ConversationAttributes;
+import org.osoa.sca.annotations.ConversationID;
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConversationProcessor extends BaseJavaClassVisitor {
+ 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 ConversationProcessor(AssemblyFactory factory) {
+ super(factory);
+ }
+
+ @Override
+ public <T> void visitClass(Class<T> clazz, JavaImplementation type) throws IntrospectionException {
+
+ ConversationAttributes conversation = clazz.getAnnotation(ConversationAttributes.class);
+ if (conversation == null) {
+ return;
+ }
+ Scope scope = clazz.getAnnotation(Scope.class);
+ if (scope == null) {
+ // implicitly assume conversation
+ type.setJavaScope(org.apache.tuscany.sca.implementation.java.impl.JavaScopeImpl.CONVERSATION);
+ } else if (conversation != null) {
+ long maxAge;
+ long maxIdleTime;
+ String maxAgeVal = conversation.maxAge();
+ String maxIdleTimeVal = conversation.maxIdleTime();
+ try {
+ if (maxAgeVal.length() > 0) {
+ maxAge = convertTimeMillis(maxAgeVal);
+ type.setMaxAge(maxAge);
+ }
+ } catch (NumberFormatException e) {
+ throw new InvalidConversationalImplementation("Invalid maximum age", e);
+ }
+ try {
+ if (maxIdleTimeVal.length() > 0) {
+ maxIdleTime = convertTimeMillis(maxIdleTimeVal);
+ type.setMaxIdleTime(maxIdleTime);
+ }
+ } catch (NumberFormatException e) {
+ throw new InvalidConversationalImplementation("Invalid maximum idle time", e);
+ }
+ }
+
+ }
+
+ @Override
+ public void visitMethod(Method method,
+ JavaImplementation type) throws IntrospectionException {
+ ConversationID conversationID = method.getAnnotation(ConversationID.class);
+ if (conversationID == null) {
+ return;
+ }
+ type.addConversationIDMember(method);
+ }
+
+ @Override
+ public void visitField(Field field,
+ JavaImplementation type) throws IntrospectionException {
+ ConversationID conversationID = field.getAnnotation(ConversationID.class);
+ if (conversationID == null) {
+ return;
+ }
+ type.addConversationIDMember(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/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DestroyProcessor.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DestroyProcessor.java
new file mode 100644
index 0000000000..50e4d46e97
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/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.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.osoa.sca.annotations.Destroy;
+
+/**
+ * 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 BaseJavaClassVisitor {
+
+ public DestroyProcessor(AssemblyFactory factory) {
+ super(factory);
+ }
+
+ @Override
+ public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException {
+ Destroy annotation = method.getAnnotation(Destroy.class);
+ if (annotation == null) {
+ return;
+ }
+ if (method.getParameterTypes().length != 0) {
+ throw new IllegalDestructorException("Destructor must not have argments", method);
+ }
+ if(!method.getReturnType().equals(void.class)) {
+ throw new IllegalDestructorException("Destructor must return void.", method);
+ }
+ if (type.getDestroyMethod() != null) {
+ throw new DuplicateDestructorException("More than one destructor found on implementation");
+ }
+ if (!Modifier.isPublic(method.getModifiers())) {
+ throw new IllegalDestructorException("Destructor must be a public method. Invalid annotation @Destroy found on "+method);
+ }
+ type.setDestroyMethod(method);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateConstructorException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateConstructorException.java
new file mode 100644
index 0000000000..88a245cbf3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateConstructorException.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Member;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+
+/**
+ * Thrown when more than one component implementation constructor is annotated with {@link
+ * org.osoa.sca.annotations.Constructor}
+ *
+ * @version $Rev$ $Date$
+ */
+public class DuplicateConstructorException extends IntrospectionException {
+ private static final long serialVersionUID = -5926763756570552986L;
+
+ public DuplicateConstructorException(String message) {
+ super(message);
+ }
+
+ public DuplicateConstructorException(String message, Member member) {
+ super(message, member);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateDestructorException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateDestructorException.java
new file mode 100644
index 0000000000..9b834e7e87
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateDestructorException.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.implementation.java.introspect.impl;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+
+/**
+ * Thrown when an implementation is annotated multiple times with {@link org.osoa.sca.annotations.Destroy}
+ *
+ * @version $Rev$ $Date$
+ */
+public class DuplicateDestructorException extends IntrospectionException {
+ private static final long serialVersionUID = -7474912510114895203L;
+
+ public DuplicateDestructorException(String message) {
+ super(message);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateInitException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateInitException.java
new file mode 100644
index 0000000000..4325faef26
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateInitException.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.implementation.java.introspect.impl;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+
+/**
+ * Thrown when an implementation is annotated multiple times with {@link @org.osoa.sca.annotations.Init}
+ *
+ * @version $Rev$ $Date$
+ */
+public class DuplicateInitException extends IntrospectionException {
+ private static final long serialVersionUID = -6282935288115512057L;
+
+ public DuplicateInitException(String message) {
+ super(message);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicatePropertyException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicatePropertyException.java
new file mode 100644
index 0000000000..b9e1923e73
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicatePropertyException.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+
+/**
+ * Thrown when an implementation has more than one property injection site with the same name
+ *
+ * @version $Rev$ $Date$
+ */
+public class DuplicatePropertyException extends IntrospectionException {
+ private static final long serialVersionUID = 5536415875694904037L;
+
+ public DuplicatePropertyException(String message) {
+ super(message);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateReferenceException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateReferenceException.java
new file mode 100644
index 0000000000..300ad6817e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateReferenceException.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.implementation.java.introspect.impl;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+
+/**
+ * Thrown when an implementation has more than one reference injection site with the same name
+ *
+ * @version $Rev$ $Date$
+ */
+public class DuplicateReferenceException extends IntrospectionException {
+ private static final long serialVersionUID = 907910648213477158L;
+
+ public DuplicateReferenceException(String message) {
+ super(message);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateResourceException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateResourceException.java
new file mode 100644
index 0000000000..2d177b3f76
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DuplicateResourceException.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+
+/**
+ * Thrown when an implementation has more than one resource injection site with the same name
+ *
+ * @version $Rev$ $Date$
+ */
+public class DuplicateResourceException extends IntrospectionException {
+
+ private static final long serialVersionUID = 1619276459330463299L;
+
+ public DuplicateResourceException(String message) {
+ super(message);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/EagerInitProcessor.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/EagerInitProcessor.java
new file mode 100644
index 0000000000..5619275b82
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/EagerInitProcessor.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.osoa.sca.annotations.EagerInit;
+
+/**
+ * Handles processing of {@link org.osoa.sca.annotations.EagerInit}
+ *
+ * @version $Rev$ $Date$
+ */
+public class EagerInitProcessor extends BaseJavaClassVisitor {
+
+ public EagerInitProcessor(AssemblyFactory factory) {
+ super(factory);
+ }
+
+ @Override
+ public <T> void visitClass(Class<T> clazz,
+ JavaImplementation type) throws IntrospectionException {
+ super.visitClass(clazz, type);
+ 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.setEagerInit(true);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java
new file mode 100644
index 0000000000..b7f6748ed2
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessor.java
@@ -0,0 +1,615 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.JavaIntrospectionHelper.getAllInterfaces;
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.JavaIntrospectionHelper.getAllPublicAndProtectedFields;
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.JavaIntrospectionHelper.getAllUniquePublicProtectedMethods;
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.JavaIntrospectionHelper.toPropertyName;
+
+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.Type;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.jws.WebService;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Contract;
+import org.apache.tuscany.sca.assembly.Multiplicity;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.impl.JavaConstructorImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaParameterImpl;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper;
+import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.Context;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Remotable;
+
+/**
+ * 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 interface 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 BaseJavaClassVisitor {
+ private JavaInterfaceFactory javaFactory;
+
+ public HeuristicPojoProcessor(AssemblyFactory assemblyFactory, JavaInterfaceFactory javaFactory) {
+ super(assemblyFactory);
+ this.javaFactory = javaFactory;
+ }
+
+ @Override
+ public <T> void visitEnd(Class<T> clazz, JavaImplementation type) throws IntrospectionException {
+ List<org.apache.tuscany.sca.assembly.Service> services = type.getServices();
+ if (services.isEmpty()) {
+ // heuristically determine the service
+ /**
+ * The following is quoted from Java Specification 1.2.1.3. Introspecting services offered by a Java implementation
+ * In the cases described below, the services offered by a Java implementation class may be determined
+ * through introspection, eliding the need to specify them using @Service. The following algorithm is used
+ * to determine how services are introspected from an implementation class:
+ *
+ * If the interfaces of the SCA services are not specified with the @Service annotation on the
+ * implementation class, it is assumed that all implemented interfaces that have been annotated
+ * as @Remotable are the service interfaces provided by the component. If none of the implemented
+ * interfaces is remotable, then by default the implementation offers a single service whose type
+ * is the implementation class.
+ */
+ Set<Class> interfaces = getAllInterfaces(clazz);
+ for (Class<?> i : interfaces) {
+ if (i.isAnnotationPresent(Remotable.class) || i.isAnnotationPresent(WebService.class)) {
+ addService(type, i);
+ }
+ }
+ if (services.isEmpty()) {
+ // class is the interface
+ addService(type, clazz);
+ }
+ }
+ Set<Method> methods = getAllUniquePublicProtectedMethods(clazz, false);
+ if (!type.getReferenceMembers().isEmpty() || !type.getPropertyMembers().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 void addService(JavaImplementation type, Class<?> clazz) throws IntrospectionException {
+ try {
+ org.apache.tuscany.sca.assembly.Service service = createService(clazz);
+ type.getServices().add(service);
+ } catch (InvalidInterfaceException e) {
+ throw new IntrospectionException(e);
+ }
+ }
+
+ private boolean isPublicSetter(Method method) {
+ return method.getParameterTypes().length == 1 && Modifier.isPublic(method.getModifiers())
+ && method.getName().startsWith("set")
+ && method.getReturnType() == void.class;
+ }
+
+ private boolean isProtectedSetter(Method method) {
+ return method.getParameterTypes().length == 1 && Modifier.isProtected(method.getModifiers())
+ && method.getName().startsWith("set")
+ && method.getReturnType() == void.class;
+ }
+
+ private <T> void calcPropRefs(Set<Method> methods,
+ List<org.apache.tuscany.sca.assembly.Service> services,
+ JavaImplementation type,
+ Class<T> clazz) throws IntrospectionException {
+ // heuristically determine the properties references
+ // make a first pass through all public methods with one param
+ Set<String> setters = new HashSet<String>();
+ Set<String> others = new HashSet<String>();
+ for (Method method : methods) {
+ if (!isPublicSetter(method)) {
+ continue;
+ }
+ if (method.isAnnotationPresent(Callback.class) || method.isAnnotationPresent(Context.class)) {
+ // Add the property name as others
+ others.add(toPropertyName(method.getName()));
+ continue;
+ }
+ if (!isInServiceInterface(method, services)) {
+ // Not part of the service interface
+ String name = toPropertyName(method.getName());
+ setters.add(name);
+ // avoid duplicate property or ref names
+ if (!type.getPropertyMembers().containsKey(name) && !type.getReferenceMembers().containsKey(name)) {
+ Class<?> param = method.getParameterTypes()[0];
+ Type genericType = method.getGenericParameterTypes()[0];
+ if (isReferenceType(param, genericType)) {
+ type.getReferences().add(createReference(name, param));
+ type.getReferenceMembers().put(name, new JavaElementImpl(method, 0));
+ } else {
+ type.getProperties().add(createProperty(name, param));
+ type.getPropertyMembers().put(name, new JavaElementImpl(method, 0));
+ }
+ }
+ }
+ }
+ // second pass for protected methods with one param
+ for (Method method : methods) {
+ if (!isProtectedSetter(method)) {
+ continue;
+ }
+ if (method.isAnnotationPresent(Callback.class) || method.isAnnotationPresent(Context.class)) {
+ // Add the property name as others
+ others.add(toPropertyName(method.getName()));
+ continue;
+ }
+ Class<?> param = method.getParameterTypes()[0];
+ String name = toPropertyName(method.getName());
+ setters.add(name);
+ // avoid duplicate property or ref names
+ if (isReferenceType(param, method.getGenericParameterTypes()[0])) {
+ if (!type.getReferenceMembers().containsKey(name)) {
+ type.getReferences().add(createReference(name, param));
+ type.getReferenceMembers().put(name, new JavaElementImpl(method, 0));
+ }
+ } else {
+ if (!type.getPropertyMembers().containsKey(name)) {
+ type.getProperties().add(createProperty(name, param));
+ type.getPropertyMembers().put(name, new JavaElementImpl(method, 0));
+ }
+ }
+ }
+
+ // Public or protected fields unless there is a public or protected
+ // setter method
+ // for the same name
+ Set<Field> fields = getAllPublicAndProtectedFields(clazz, false);
+ for (Field field : fields) {
+ if (field.isAnnotationPresent(Callback.class) || field.isAnnotationPresent(Context.class)) {
+ continue;
+ }
+ if (setters.contains(field.getName()) || others.contains(field.getName())) {
+ continue;
+ }
+ String name = field.getName();
+ Class<?> paramType = field.getType();
+ if (isReferenceType(paramType, field.getGenericType())) {
+ if (!type.getReferenceMembers().containsKey(name)) {
+ type.getReferences().add(createReference(name, paramType));
+ type.getReferenceMembers().put(name, new JavaElementImpl(field));
+ }
+ } else {
+ if (!type.getPropertyMembers().containsKey(name)) {
+ type.getProperties().add(createProperty(name, paramType));
+ type.getPropertyMembers().put(name, new JavaElementImpl(field));
+ }
+ }
+ }
+ }
+
+ /**
+ * 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(JavaImplementation type, Class<T> clazz) throws IntrospectionException {
+ // determine constructor if one is not annotated
+ JavaConstructorImpl<?> definition = type.getConstructor();
+ Constructor constructor;
+ boolean explict = false;
+ if (definition != null && definition.getConstructor()
+ .isAnnotationPresent(org.osoa.sca.annotations.Constructor.class)) {
+ // 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");
+ } else if (constructors.length == 1) {
+ // Only one constructor, take it
+ constructor = constructors[0];
+ } else {
+ // FIXME multiple constructors, none yet done
+ Constructor<T> selected = null;
+ int sites = type.getPropertyMembers().size() + type.getReferenceMembers().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 = type.getConstructors().get(selected);
+ type.setConstructor(definition);
+ // return;
+ }
+ definition = type.getConstructors().get(constructor);
+ type.setConstructor(definition);
+ }
+ JavaParameterImpl[] parameters = definition.getParameters();
+ if (parameters.length == 0) {
+ return;
+ }
+ Map<String, JavaElementImpl> props = type.getPropertyMembers();
+ Map<String, JavaElementImpl> refs = type.getReferenceMembers();
+ 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 = injectionAnnotationsPresent(annotations);
+ }
+ if (explict) {
+ for (int i = 0; i < parameters.length; i++) {
+ if (isAnnotated(parameters[i])) {
+ continue;
+ } else if (!findReferenceOrProperty(parameters[i], props, refs)) {
+ throw new AmbiguousConstructorException(parameters[i].toString());
+ }
+ }
+ } else {
+ if (!areUnique(parameters)) {
+ 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");
+ }
+ if (!(props.isEmpty() && refs.isEmpty())) {
+ calcParamNames(parameters, props, refs);
+ } else {
+ heuristicParamNames(type, parameters);
+
+ }
+ }
+ }
+
+ private void calcParamNames(JavaParameterImpl[] parameters,
+ Map<String, JavaElementImpl> props,
+ Map<String, JavaElementImpl> refs) throws AmbiguousConstructorException {
+ // the constructor param types must unambiguously match defined
+ // reference or property types
+ for (JavaParameterImpl param : parameters) {
+ if (!findReferenceOrProperty(param, props, refs)) {
+ throw new AmbiguousConstructorException(param.getName());
+ }
+ }
+ }
+
+ private void heuristicParamNames(JavaImplementation type, JavaParameterImpl[] parameters)
+ throws IntrospectionException {
+ // heuristically determine refs and props from the parameter types
+ for (JavaParameterImpl p : parameters) {
+ String name = p.getType().getSimpleName().toLowerCase();
+ if (isReferenceType(p.getType(), p.getGenericType())) {
+ type.getReferences().add(createReference(name, p.getType()));
+ p.setClassifer(Reference.class);
+ type.getReferenceMembers().put(name, p);
+ } else {
+ type.getProperties().add(createProperty(name, p.getType()));
+ p.setClassifer(Property.class);
+ type.getPropertyMembers().put(name, p);
+ }
+ p.setName(name);
+ }
+ }
+
+ private static boolean areUnique(Class[] collection) {
+ Set<Class> set = new HashSet<Class>(Arrays.asList(collection));
+ return set.size() == collection.length;
+ }
+
+ /**
+ * Returns true if the union of the given collections of properties and
+ * references have unique Java types
+ */
+ private boolean calcPropRefUniqueness(Collection<JavaElementImpl> props, Collection<JavaElementImpl> refs) {
+
+ Class[] classes = new Class[props.size() + refs.size()];
+ int i = 0;
+ for (JavaElementImpl property : props) {
+ classes[i] = property.getType();
+ i++;
+ }
+ for (JavaElementImpl reference : refs) {
+ classes[i] = reference.getType();
+ i++;
+ }
+ return 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 boolean findReferenceOrProperty(JavaParameterImpl parameter,
+ Map<String, JavaElementImpl> props,
+ Map<String, JavaElementImpl> refs) throws AmbiguousConstructorException {
+
+ boolean found = false;
+ if (!"".equals(parameter.getName())) {
+ // Match by name
+ JavaElementImpl prop = props.get(parameter.getName());
+ if (prop != null && prop.getType() == parameter.getType()) {
+ parameter.setClassifer(Property.class);
+ return true;
+ }
+ JavaElementImpl ref = refs.get(parameter.getName());
+ if (ref != null && ref.getType() == parameter.getType()) {
+ parameter.setClassifer(Reference.class);
+ return true;
+ }
+ }
+ for (JavaElementImpl property : props.values()) {
+ if (property.getType() == parameter.getType()) {
+ if (found) {
+ throw new AmbiguousConstructorException("Ambiguous property or reference for constructor type",
+ (Member)parameter.getAnchor());
+ }
+ parameter.setClassifer(Property.class);
+ parameter.setName(property.getName());
+ found = true;
+ // do not break since ambiguities must be checked, i.e. more
+ // than one prop or ref of the same type
+ }
+ }
+ for (JavaElementImpl reference : refs.values()) {
+ if (reference.getType() == parameter.getType()) {
+ if (found) {
+ throw new AmbiguousConstructorException("Ambiguous property or reference for constructor type",
+ (Member)parameter.getAnchor());
+ }
+ parameter.setClassifer(Reference.class);
+ parameter.setName(reference.getName());
+ found = true;
+ // do not break since ambiguities must be checked, i.e. more
+ // than one prop or ref of the same type
+ }
+ }
+ return found;
+ }
+
+ /**
+ * Returns true if a given type is reference according to the SCA
+ * specification rules for determining reference types The following rules
+ * are used to determine whether an unannotated field or setter method is a
+ * property or reference:
+ * <ol>
+ * <li>If its type is simple, then it is a property.
+ * <li>If its type is complex, then if the type is an interface marked by
+ *
+ * @Remotable, then it is a reference; otherwise, it is a property.
+ * <li>Otherwise, if the type associated with the member is an
+ * array or a java.util.Collection, the basetype is the element
+ * type of the array or the parameterized type of the
+ * Collection; otherwise the basetype is the member type. If the
+ * basetype is an interface with an
+ * @Remotable or
+ * @Service annotation then the member is defined as a reference. Otherwise,
+ * it is defined as a property.
+ * </ol>
+ * <p>
+ * The name of the reference or of the property is derived from the
+ * name found on the setter method or on the field.
+ */
+ private boolean isReferenceType(Class<?> cls, Type genericType) {
+ Class<?> baseType = JavaIntrospectionHelper.getBaseType(cls, genericType);
+ return baseType.isInterface() && baseType.isAnnotationPresent(Remotable.class);
+ }
+
+ /**
+ * Returns true if the given operation is defined in the collection of
+ * service interfaces
+ */
+ private boolean isInServiceInterface(Method operation, List<org.apache.tuscany.sca.assembly.Service> services) {
+ for (org.apache.tuscany.sca.assembly.Service service : services) {
+ Interface interface1 = service.getInterfaceContract().getInterface();
+ if (interface1 instanceof JavaInterface) {
+ Class<?> clazz = ((JavaInterface)interface1).getJavaClass();
+ if (isMethodMatched(clazz, operation)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Test if the class declares a method which matches the signature of the
+ * given method
+ *
+ * @param clazz
+ * @param method
+ * @return
+ */
+ private boolean isMethodMatched(Class<?> clazz, Method method) {
+ if (method.getDeclaringClass() == clazz) {
+ return true;
+ }
+ Method[] methods = clazz.getMethods();
+ for (Method m : methods) {
+ if (JavaIntrospectionHelper.exactMethodMatch(method, m)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Creates a mapped property.
+ *
+ * @param name the property name
+ * @param paramType the property type
+ */
+ private org.apache.tuscany.sca.assembly.Property createProperty(String name, Class<?> paramType) {
+ org.apache.tuscany.sca.assembly.Property property = assemblyFactory.createProperty();
+ property.setName(name);
+ property.setXSDType(JavaXMLMapper.getXMLType(paramType));
+ return property;
+ }
+
+ private boolean isAnnotated(JavaParameterImpl parameter) {
+ for (Annotation annotation : parameter.getAnnotations()) {
+ Class<? extends Annotation> annotType = annotation.annotationType();
+ if (annotType.equals(Property.class) || annotType.equals(Reference.class)
+ || annotType.equals(Resource.class)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public boolean areUnique(JavaParameterImpl[] parameters) {
+ Set<Class> set = new HashSet<Class>(parameters.length);
+ for (JavaParameterImpl p : parameters) {
+ if (!set.add(p.getType())) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public org.apache.tuscany.sca.assembly.Reference createReference(String name, Class<?> paramType)
+ throws IntrospectionException {
+ org.apache.tuscany.sca.assembly.Reference reference = assemblyFactory.createReference();
+ reference.setName(name);
+ JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract();
+ reference.setInterfaceContract(interfaceContract);
+ try {
+ JavaInterface callInterface = javaFactory.createJavaInterface(paramType);
+ reference.getInterfaceContract().setInterface(callInterface);
+ if (callInterface.getCallbackClass() != null) {
+ JavaInterface callbackInterface = javaFactory.createJavaInterface(callInterface.getCallbackClass());
+ reference.getInterfaceContract().setCallbackInterface(callbackInterface);
+ }
+ reference.setMultiplicity(Multiplicity.ZERO_ONE);
+ } catch (InvalidInterfaceException e1) {
+ throw new IntrospectionException(e1);
+ }
+
+ // FIXME: This part seems to have already been taken care above!!
+ try {
+ processCallback(paramType, reference);
+ } catch (InvalidServiceType e) {
+ throw new IntrospectionException(e);
+ }
+ return reference;
+ }
+
+ public org.apache.tuscany.sca.assembly.Service createService(Class<?> interfaze) throws InvalidInterfaceException {
+ org.apache.tuscany.sca.assembly.Service service = assemblyFactory.createService();
+ service.setName(interfaze.getSimpleName());
+
+ JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract();
+ service.setInterfaceContract(interfaceContract);
+
+ JavaInterface callInterface = javaFactory.createJavaInterface(interfaze);
+ service.getInterfaceContract().setInterface(callInterface);
+ if (callInterface.getCallbackClass() != null) {
+ JavaInterface callbackInterface = javaFactory.createJavaInterface(callInterface.getCallbackClass());
+ service.getInterfaceContract().setCallbackInterface(callbackInterface);
+ }
+
+ Interface javaInterface = service.getInterfaceContract().getInterface();
+ javaInterface.setRemotable(interfaze.getAnnotation(Remotable.class) != null);
+ service.getInterfaceContract().setInterface(javaInterface);
+ return service;
+ }
+
+ public void processCallback(Class<?> interfaze, Contract contract) throws InvalidServiceType {
+ Callback callback = interfaze.getAnnotation(Callback.class);
+ if (callback != null && !Void.class.equals(callback.value())) {
+ Class<?> callbackClass = callback.value();
+ JavaInterface javaInterface;
+ try {
+ javaInterface = javaFactory.createJavaInterface(callbackClass);
+ contract.getInterfaceContract().setCallbackInterface(javaInterface);
+ } catch (InvalidInterfaceException e) {
+ throw new InvalidServiceType("Invalid callback interface "+callbackClass, interfaze);
+ }
+ } else if (callback != null && Void.class.equals(callback.value())) {
+ throw new InvalidServiceType("No callback interface specified on annotation", interfaze);
+ }
+ }
+
+ 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;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalCallbackReferenceException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalCallbackReferenceException.java
new file mode 100644
index 0000000000..9fe2fcd468
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalCallbackReferenceException.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Member;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+
+/**
+ * Denotes an illegal use of {@link org.osoa.sca.annotations.Callback} on a reference
+ *
+ * @version $Rev$ $Date$
+ */
+public class IllegalCallbackReferenceException extends IntrospectionException {
+ private static final long serialVersionUID = -8932525723147700591L;
+
+ public IllegalCallbackReferenceException(String message) {
+ super(message);
+ }
+
+ public IllegalCallbackReferenceException(String message, Member member) {
+ super(message, member);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalContextException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalContextException.java
new file mode 100644
index 0000000000..f5696122df
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalContextException.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Member;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+
+/**
+ * Denotes an illegal signature for a method decorated with {@link org.osoa.sca.annotations.Context}
+ *
+ * @version $Rev$ $Date$
+ */
+public class IllegalContextException extends IntrospectionException {
+ private static final long serialVersionUID = -6946383136750117008L;
+
+ public IllegalContextException(String message) {
+ super(message);
+ }
+
+ public IllegalContextException(String message, Member member) {
+ super(message, member);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalDestructorException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalDestructorException.java
new file mode 100644
index 0000000000..6a0d60c92f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalDestructorException.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Member;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+
+/**
+ * Denotes an illegal signature for a method decorated with {@link org.osoa.sca.annotations.Destroy}
+ *
+ * @version $Rev$ $Date$
+ */
+public class IllegalDestructorException extends IntrospectionException {
+ private static final long serialVersionUID = 365719353107446326L;
+
+ public IllegalDestructorException(String message) {
+ super(message);
+ }
+
+ public IllegalDestructorException(String message, Member member) {
+ super(message, member);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalInitException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalInitException.java
new file mode 100644
index 0000000000..8f50852c2d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalInitException.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Member;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+
+/**
+ * Denotes an illegal signature for a method decorated with {@link @org.osoa.sca.annotations.Init}
+ *
+ * @version $Rev$ $Date$
+ */
+public class IllegalInitException extends IntrospectionException {
+ private static final long serialVersionUID = -3690763271986854701L;
+
+ public IllegalInitException(String message) {
+ super(message);
+ }
+
+ public IllegalInitException(String message, Member member) {
+ super(message, member);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalPropertyException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalPropertyException.java
new file mode 100644
index 0000000000..54f7dfad1e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalPropertyException.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Member;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+
+/**
+ * Denotes an illegal property definition in a component type
+ *
+ * @version $Rev$ $Date$
+ */
+public class IllegalPropertyException extends IntrospectionException {
+ private static final long serialVersionUID = -2836849110706758494L;
+
+ public IllegalPropertyException(String message) {
+ super(message);
+ }
+
+ public IllegalPropertyException(String message, Member member) {
+ super(message, member);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalReferenceException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalReferenceException.java
new file mode 100644
index 0000000000..25196c56e5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalReferenceException.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Member;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+
+/**
+ * Denotes an illegal reference definition in a component type
+ *
+ * @version $Rev$ $Date$
+ */
+public class IllegalReferenceException extends IntrospectionException {
+ private static final long serialVersionUID = 4612984122225271395L;
+
+ public IllegalReferenceException(String message) {
+ super(message);
+ }
+
+ public IllegalReferenceException(String message, Member member) {
+ super(message, member);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalResourceException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalResourceException.java
new file mode 100644
index 0000000000..ccfbaf0043
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalResourceException.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Member;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+
+/**
+ * Denotes an illegal resource definition in a component type
+ *
+ * @version $Rev$ $Date$
+ */
+public class IllegalResourceException extends IntrospectionException {
+ private static final long serialVersionUID = -1100936539412435579L;
+
+ public IllegalResourceException(String message) {
+ super(message);
+ }
+
+ public IllegalResourceException(String message, Member member) {
+ super(message, member);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalServiceDefinitionException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalServiceDefinitionException.java
new file mode 100644
index 0000000000..e130f4221d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/IllegalServiceDefinitionException.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.implementation.java.introspect.impl;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+
+/**
+ * Denotes an illegal use of the {@link @org.osoa.sca.annotations.Service} annotation
+ *
+ * @version $Rev$ $Date$
+ */
+public class IllegalServiceDefinitionException extends IntrospectionException {
+ private static final long serialVersionUID = -7151534258405092548L;
+
+ public IllegalServiceDefinitionException(String message) {
+ super(message);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InitProcessor.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InitProcessor.java
new file mode 100644
index 0000000000..583ccc86cd
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/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.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.osoa.sca.annotations.Init;
+
+/**
+ * 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 BaseJavaClassVisitor {
+
+ public InitProcessor(AssemblyFactory factory) {
+ super(factory);
+ }
+
+ @Override
+ public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException {
+ Init annotation = method.getAnnotation(Init.class);
+ if (annotation == null) {
+ return;
+ }
+ if (method.getParameterTypes().length != 0) {
+ throw new IllegalInitException("Initializer must not have argments", method);
+ }
+ if(!method.getReturnType().equals(void.class)) {
+ throw new IllegalInitException("Initializer must return void.", method);
+ }
+ if (type.getInitMethod() != null) {
+ throw new DuplicateInitException("More than one initializer found on implementaton");
+ }
+ if (!Modifier.isPublic(method.getModifiers())) {
+ throw new IllegalInitException("Initializer must be a public method. Invalid annotation @Init found on "+method);
+ }
+ type.setInitMethod(method);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidConstructorException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidConstructorException.java
new file mode 100644
index 0000000000..91b97b2caf
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidConstructorException.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+
+/**
+ * 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 IntrospectionException {
+ private static final long serialVersionUID = 1411492435210741512L;
+
+ public InvalidConstructorException(String message) {
+ super(message);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidConversationalImplementation.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidConversationalImplementation.java
new file mode 100644
index 0000000000..a1e1d01ab3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidConversationalImplementation.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+
+/**
+ * Raised when an implementation specifies improper conversational metadata
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidConversationalImplementation extends IntrospectionException {
+ private static final long serialVersionUID = -5487291552769408149L;
+
+ public InvalidConversationalImplementation(String message) {
+ super(message);
+ }
+
+ public InvalidConversationalImplementation(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidPropertyException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidPropertyException.java
new file mode 100644
index 0000000000..976b4da120
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidPropertyException.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.implementation.java.introspect.impl;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+
+/**
+ * Denotes an invalid usage of {@link org.osoa.sca.annotations.Property}
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidPropertyException extends IntrospectionException {
+ private static final long serialVersionUID = -2682862652069727948L;
+
+ public InvalidPropertyException(String message) {
+ super(message);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidReferenceException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidReferenceException.java
new file mode 100644
index 0000000000..e77a6beb0d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidReferenceException.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+
+/**
+ * Denotes an invalid usage of {@link org.osoa.sca.annotations.Reference}
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidReferenceException extends IntrospectionException {
+ private static final long serialVersionUID = -3285246635989254165L;
+
+ public InvalidReferenceException(String message) {
+ super(message);
+ }
+
+ public InvalidReferenceException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public InvalidReferenceException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidResourceException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidResourceException.java
new file mode 100644
index 0000000000..debb5cbacc
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidResourceException.java
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Member;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+
+/**
+ * Denotes an invalid usage of {@link @org.apache.tuscany.api.annotation.Resource}
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidResourceException extends IntrospectionException {
+ private static final long serialVersionUID = 511728001735534934L;
+
+ public InvalidResourceException(String message) {
+ super(message);
+ }
+
+ public InvalidResourceException(String message, Member member) {
+ super(message, member);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidServiceType.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidServiceType.java
new file mode 100644
index 0000000000..7147da55b4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InvalidServiceType.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+
+/**
+ * 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 IntrospectionException {
+ private static final long serialVersionUID = -1076466639416644386L;
+ private Class<?> serviceType;
+
+ public InvalidServiceType(String message) {
+ super(message);
+ }
+
+ public InvalidServiceType(String message, Class<?> clazz) {
+ super(message);
+ this.serviceType = clazz;
+ }
+
+ /**
+ * @return the serviceType
+ */
+ public Class<?> getServiceType() {
+ return serviceType;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JavaIntrospectionHelper.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JavaIntrospectionHelper.java
new file mode 100644
index 0000000000..6039bd91f8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JavaIntrospectionHelper.java
@@ -0,0 +1,577 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.beans.Introspector;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.GenericArrayType;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+import java.lang.reflect.WildcardType;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import org.osoa.sca.CallableReference;
+
+/**
+ * Implements various reflection-related operations
+ *
+ * @version $Rev$ $Date$
+ */
+public final class JavaIntrospectionHelper {
+ private static final Logger logger = Logger.getLogger(JavaIntrospectionHelper.class.getName());
+ 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, boolean validating) {
+ return getAllPublicAndProtectedFields(clazz, new HashSet<Field>(), validating);
+ }
+
+ private static void checkInvalidAnnotations(AnnotatedElement element) {
+ for (Annotation a : element.getAnnotations()) {
+ if (a.annotationType().getName().startsWith("org.osoa.sca.annotations.")) {
+ logger.warning("Invalid annotation " + a + " is found on " + element);
+ }
+ }
+ }
+
+ /**
+ * Recursively evaluates the type hierarchy to return all fields that are
+ * public or protected
+ */
+ private static Set<Field> getAllPublicAndProtectedFields(Class clazz, Set<Field> fields, boolean validating) {
+ if (clazz == null || clazz.isArray() || Object.class.equals(clazz)) {
+ return fields;
+ }
+ fields = getAllPublicAndProtectedFields(clazz.getSuperclass(), fields, validating);
+ Field[] declaredFields = clazz.getDeclaredFields();
+ for (final Field field : declaredFields) {
+ int modifiers = field.getModifiers();
+ if ((Modifier.isPublic(modifiers) || Modifier.isProtected(modifiers)) && !Modifier.isStatic(modifiers)) {
+ // Allow privileged access to set accessibility. Requires ReflectPermission
+ // in security policy.
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ field.setAccessible(true); // ignore Java accessibility
+ return null;
+ }
+ });
+ fields.add(field);
+ } else {
+ if (validating) {
+ checkInvalidAnnotations(field);
+ }
+ }
+ }
+ return fields;
+ }
+
+ /**
+ * Returns a collection of public and protected methods declared by a class
+ * or one of its supertypes. Note that overridden 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, boolean validating) {
+ return getAllUniqueMethods(clazz, new HashSet<Method>(), validating);
+ }
+
+ /**
+ * Recursively evaluates the type hierarchy to return all unique methods
+ */
+ private static Set<Method> getAllUniqueMethods(Class pClass, Set<Method> methods, boolean validating) {
+ 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 (final Method declaredMethod : declaredMethods) {
+ int modifiers = declaredMethod.getModifiers();
+ if ((!Modifier.isPublic(modifiers) && !Modifier.isProtected(modifiers)) || Modifier.isStatic(modifiers)) {
+ if (validating) {
+ checkInvalidAnnotations(declaredMethod);
+ }
+ 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 superclass (i.e.
+ // the method is not overridden)
+ if (exactMethodMatch(declaredMethod, method)) {
+ matched = true;
+ break;
+ }
+ }
+ if (!matched) {
+ // Allow privileged access to set accessibility. Requires ReflectPermission
+ // in security policy.
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ declaredMethod.setAccessible(true);
+ return null;
+ }
+ });
+ temp.add(declaredMethod);
+ }
+ methods.addAll(temp);
+ temp.clear();
+ }
+ }
+ // evaluate class hierarchy - this is done last to track inherited
+ // methods
+ methods = getAllUniqueMethods(pClass.getSuperclass(), methods, validating);
+ 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;
+ }
+ }
+
+ /**
+ * 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 != types2.length) {
+ return false;
+ }
+ boolean matched = true;
+ for (int i = 0; i < types1.length; i++) {
+ if (types1[i] != types2[i]) {
+ matched = false;
+ break;
+ }
+ }
+ return matched;
+ }
+
+ public static <T> Constructor<T> getDefaultConstructor(Class<T> clazz) throws NoSuchMethodException {
+ return clazz.getConstructor((Class[])null);
+ }
+
+ /**
+ * Returns the simple name of a class - i.e. the class name devoid of its
+ * package qualifier
+ *
+ * @param implClass the implementation class
+ */
+ public static String getBaseName(Class<?> implClass) {
+ return implClass.getSimpleName();
+ }
+
+ 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 Introspector.decapitalize(name.substring(3));
+ }
+
+ public static Class<?> getErasure(Type type) {
+ if (type instanceof Class) {
+ return (Class)type;
+ } else if (type instanceof GenericArrayType) {
+ // FIXME: How to deal with the []?
+ GenericArrayType arrayType = (GenericArrayType)type;
+ return getErasure(arrayType.getGenericComponentType());
+ } else if (type instanceof ParameterizedType) {
+ ParameterizedType pType = (ParameterizedType)type;
+ return getErasure(pType.getRawType());
+ } else if (type instanceof WildcardType) {
+ WildcardType wType = (WildcardType)type;
+ Type[] types = wType.getUpperBounds();
+ return getErasure(types[0]);
+ } else if (type instanceof TypeVariable) {
+ TypeVariable var = (TypeVariable)type;
+ Type[] types = var.getBounds();
+ return getErasure(types[0]);
+ }
+ return null;
+ }
+
+ public static Class<?> getBaseType(Class<?> cls, Type genericType) {
+ if (cls.isArray()) {
+ return cls.getComponentType();
+ } else if (Collection.class.isAssignableFrom(cls)) {
+ if (genericType instanceof ParameterizedType) {
+ // Collection<BaseType>
+ ParameterizedType parameterizedType = (ParameterizedType)genericType;
+ Type baseType = parameterizedType.getActualTypeArguments()[0];
+ if (baseType instanceof GenericArrayType) {
+ // Base is array
+ return cls;
+ } else {
+ return getErasure(baseType);
+ }
+ } else {
+ return cls;
+ }
+ } else {
+ return cls;
+ }
+ }
+
+ public static Type getParameterType(Type type) {
+ if (type instanceof ParameterizedType) {
+ // Collection<BaseType>
+ ParameterizedType parameterizedType = (ParameterizedType)type;
+ Type baseType = parameterizedType.getActualTypeArguments()[0];
+ return baseType;
+ } else {
+ return Object.class;
+ }
+ }
+
+ public static Class<?> getBusinessInterface(Class<?> cls, Type callableReferenceType) {
+ if (CallableReference.class.isAssignableFrom(cls) && callableReferenceType instanceof ParameterizedType) {
+ // Collection<BaseType>
+ ParameterizedType parameterizedType = (ParameterizedType)callableReferenceType;
+ Type baseType = parameterizedType.getActualTypeArguments()[0];
+ if (baseType instanceof GenericArrayType) {
+ // Base is array
+ return cls;
+ } else {
+ return getErasure(baseType);
+ }
+ }
+ return Object.class;
+ }
+
+ /**
+ * 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);
+ }
+ }
+
+ public static boolean isSetter(Method method) {
+ return (void.class == method.getReturnType() && method.getParameterTypes().length == 1 && method.getName()
+ .startsWith("set"));
+ }
+
+ public static boolean isGetter(Method method) {
+ return (void.class != method.getReturnType() && method.getParameterTypes().length == 0 && method.getName()
+ .startsWith("get"));
+ }
+
+ private final static Map<Class, String> signatures = new HashMap<Class, String>();
+ static {
+ signatures.put(boolean.class, "Z");
+ signatures.put(byte.class, "B");
+ signatures.put(char.class, "C");
+ signatures.put(short.class, "S");
+ signatures.put(int.class, "I");
+ signatures.put(long.class, "J");
+ signatures.put(float.class, "F");
+ signatures.put(double.class, "D");
+ };
+
+ public static String getSignature(Class<?> cls) {
+ if (cls.isPrimitive()) {
+ return signatures.get(cls);
+ }
+ if (cls.isArray()) {
+ return "[" + getSignature(cls.getComponentType());
+ }
+ return "L" + cls.getName().replace('.', '/') + ";";
+ }
+
+ public static Class<?> getArrayType(Class<?> componentType, int dims) throws ClassNotFoundException {
+ StringBuffer buf = new StringBuffer();
+ for (int i = 0; i < dims; i++) {
+ buf.append('[');
+ }
+ buf.append(getSignature(componentType));
+ return Class.forName(buf.toString(), false, componentType.getClassLoader());
+ }
+
+ public static Set<Method> getPrivateMethods(Class clazz) {
+ Set<Method> methods = new HashSet<Method>();
+ Method[] declaredMethods = clazz.getDeclaredMethods();
+ for (final Method declaredMethod : declaredMethods) {
+ int modifiers = declaredMethod.getModifiers();
+ if(Modifier.isPrivate(modifiers)) {
+ methods.add(declaredMethod);
+ }
+ }
+
+ return methods;
+ }
+
+ public static Set<Field> getPrivateFields(Class clazz) {
+ Set<Field> fields = new HashSet<Field>();
+ Field[] declaredFields = clazz.getDeclaredFields();
+ for (final Field declaredField : declaredFields) {
+ int modifiers = declaredField.getModifiers();
+ if(Modifier.isPrivate(modifiers)) {
+ fields.add(declaredField);
+ }
+ }
+
+ return fields;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/NoConstructorException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/NoConstructorException.java
new file mode 100644
index 0000000000..453cfa35fe
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/NoConstructorException.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.implementation.java.introspect.impl;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+
+/**
+ * Thrown when a suitable constructor for a component implementation cannot be found
+ *
+ * @version $Rev$ $Date$
+ */
+public class NoConstructorException extends IntrospectionException {
+ private static final long serialVersionUID = 3086706387280694424L;
+
+ public NoConstructorException() {
+ }
+
+ public NoConstructorException(String message) {
+ super(message);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java
new file mode 100644
index 0000000000..954a3abbc8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessor.java
@@ -0,0 +1,292 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Callback;
+import org.apache.tuscany.sca.assembly.ConfiguredOperation;
+import org.apache.tuscany.sca.assembly.OperationsConfigurator;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+import org.osoa.sca.annotations.PolicySets;
+import org.osoa.sca.annotations.Requires;
+
+/**
+ * Processes an {@link org.osoa.sca.annotations.Requires} annotation
+ *
+ * @version $Rev$ $Date$
+ */
+public class PolicyProcessor extends BaseJavaClassVisitor {
+
+ private PolicyFactory policyFactory;
+
+ public PolicyProcessor(AssemblyFactory assemblyFactory, PolicyFactory policyFactory) {
+ super(assemblyFactory);
+ this.policyFactory = policyFactory;
+ }
+
+ private QName getQName(String intentName) {
+ QName qname;
+ if (intentName.startsWith("{")) {
+ int i = intentName.indexOf('}');
+ if (i != -1) {
+ qname = new QName(intentName.substring(1, i), intentName.substring(i + 1));
+ } else {
+ qname = new QName("", intentName);
+ }
+ } else {
+ qname = new QName("", intentName);
+ }
+ return qname;
+ }
+
+ /**
+ * Read policy intents on the given interface or class
+ * @param clazz
+ * @param requiredIntents
+ */
+ private void readIntentsAndPolicySets(Class<?> clazz,
+ List<Intent> requiredIntents,
+ List<PolicySet> policySets) {
+ Requires intentAnnotation = clazz.getAnnotation(Requires.class);
+ if (intentAnnotation != null) {
+ String[] intentNames = intentAnnotation.value();
+ if (intentNames.length != 0) {
+ for (String intentName : intentNames) {
+
+ // Add each intent to the list
+ Intent intent = policyFactory.createIntent();
+ intent.setName(getQName(intentName));
+ requiredIntents.add(intent);
+ }
+ }
+ }
+
+ PolicySets policySetAnnotation = clazz.getAnnotation(PolicySets.class);
+ if (policySetAnnotation != null) {
+ String[] policySetNames = policySetAnnotation.value();
+ if (policySetNames.length != 0) {
+ for (String policySetName : policySetNames) {
+
+ // Add each intent to the list
+ PolicySet policySet = policyFactory.createPolicySet();
+ policySet.setName(getQName(policySetName));
+ policySets.add(policySet);
+ }
+ }
+ }
+ }
+
+ private void readIntents(Requires intentAnnotation, List<Intent> requiredIntents) {
+ //Requires intentAnnotation = method.getAnnotation(Requires.class);
+ if (intentAnnotation != null) {
+ String[] intentNames = intentAnnotation.value();
+ if (intentNames.length != 0) {
+ //Operation operation = assemblyFactory.createOperation();
+ //operation.setName(method.getName());
+ //operation.setUnresolved(true);
+ for (String intentName : intentNames) {
+
+ // Add each intent to the list, associated with the
+ // operation corresponding to the annotated method
+ Intent intent = policyFactory.createIntent();
+ intent.setName(getQName(intentName));
+ //intent.getOperations().add(operation);
+ requiredIntents.add(intent);
+ }
+ }
+ }
+ }
+
+ private void readPolicySets(PolicySets policySetAnnotation, List<PolicySet> policySets) {
+ if (policySetAnnotation != null) {
+ String[] policySetNames = policySetAnnotation.value();
+ if (policySetNames.length != 0) {
+ //Operation operation = assemblyFactory.createOperation();
+ //operation.setName(method.getName());
+ //operation.setUnresolved(true);
+ for (String policySetName : policySetNames) {
+ // Add each intent to the list, associated with the
+ // operation corresponding to the annotated method
+ PolicySet policySet = policyFactory.createPolicySet();
+ policySet.setName(getQName(policySetName));
+ //intent.getOperations().add(operation);
+ policySets.add(policySet);
+ }
+ }
+ }
+ }
+
+ @Override
+ public <T> void visitClass(Class<T> clazz, JavaImplementation type) throws IntrospectionException {
+
+ // Read intents on the Java implementation class
+ if ( type instanceof PolicySetAttachPoint ) {
+ readIntentsAndPolicySets(clazz,
+ ((PolicySetAttachPoint)type).getRequiredIntents(),
+ ((PolicySetAttachPoint)type).getPolicySets());
+ }
+
+ // Process annotations on the service interfaces
+ //TODO This will have to move to a JavaInterface introspector later
+ for (Service service: type.getServices()) {
+ InterfaceContract interfaceContract = service.getInterfaceContract();
+ if (interfaceContract instanceof JavaInterfaceContract) {
+ JavaInterfaceContract javaInterfaceContract = (JavaInterfaceContract)interfaceContract;
+
+ // Read intents on the service interface
+ if (javaInterfaceContract.getInterface() != null) {
+ JavaInterface javaInterface = (JavaInterface)javaInterfaceContract.getInterface();
+ if (javaInterface.getJavaClass() != null) {
+ readIntentsAndPolicySets(javaInterface.getJavaClass(),
+ service.getRequiredIntents(),
+ service.getPolicySets());
+
+ // Read intents on the service interface methods
+ Method[] methods = javaInterface.getJavaClass().getMethods();
+ ConfiguredOperation confOp = null;
+ for (Method method: methods) {
+ if ( method.getAnnotation(Requires.class) != null ||
+ method.getAnnotation(PolicySets.class) != null ) {
+ confOp = assemblyFactory.createConfiguredOperation();
+ confOp.setName(method.getName());
+ confOp.setContractName(service.getName());
+
+ service.getConfiguredOperations().add(confOp);
+ readIntents(method.getAnnotation(Requires.class), confOp.getRequiredIntents());
+ readPolicySets(method.getAnnotation(PolicySets.class), confOp.getPolicySets());
+ }
+ }
+ }
+
+ }
+
+ // Read intents on the callback interface
+ if (javaInterfaceContract.getCallbackInterface() != null) {
+ JavaInterface javaCallbackInterface = (JavaInterface)javaInterfaceContract.getCallbackInterface();
+ if (javaCallbackInterface.getJavaClass() != null) {
+ Callback callback = service.getCallback();
+ if (callback == null) {
+ callback = assemblyFactory.createCallback();
+ service.setCallback(callback);
+ }
+ readIntentsAndPolicySets(javaCallbackInterface.getJavaClass(),
+ callback.getRequiredIntents(),
+ callback.getPolicySets());
+
+ // Read intents on the callback interface methods
+ Method[] methods = javaCallbackInterface.getJavaClass().getMethods();
+ ConfiguredOperation confOp = null;
+ for (Method method: methods) {
+ confOp = assemblyFactory.createConfiguredOperation();
+ confOp.setName(method.getName());
+ callback.getConfiguredOperations().add(confOp);
+ readIntents(method.getAnnotation(Requires.class), confOp.getRequiredIntents());
+ readPolicySets(method.getAnnotation(PolicySets.class), confOp.getPolicySets());
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private Reference getReference(Method method, JavaImplementation type) {
+ //since the ReferenceProcessor is called ahead of the PolicyProcessor the type should have
+ //picked up the reference setter method
+ org.osoa.sca.annotations.Reference annotation =
+ method.getAnnotation(org.osoa.sca.annotations.Reference.class);
+ if (annotation != null) {
+ if (JavaIntrospectionHelper.isSetter(method)) {
+ String name = annotation.name();
+ if ("".equals(name)) {
+ name = JavaIntrospectionHelper.toPropertyName(method.getName());
+ }
+ return getReferenceByName(name, type);
+ }
+ }
+ return null;
+ }
+
+ private Reference getReferenceByName(String name, JavaImplementation type) {
+ for ( Reference reference : type.getReferences() ) {
+ if ( reference.getName().equals(name) ) {
+ return reference;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public void visitField(Field field, JavaImplementation type) throws IntrospectionException {
+ org.osoa.sca.annotations.Reference annotation =
+ field.getAnnotation( org.osoa.sca.annotations.Reference.class);
+ if (annotation == null) {
+ return;
+ }
+ String name = annotation.name();
+ if ("".equals(name)) {
+ name = field.getName();
+ }
+
+ Reference reference = null;
+ if ( (reference = getReferenceByName(name, type)) != null ) {
+ readIntents(field.getAnnotation(Requires.class), reference.getRequiredIntents());
+ readPolicySets(field.getAnnotation(PolicySets.class), reference.getPolicySets());
+ }
+ }
+
+ @Override
+ public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException {
+ Reference reference = null;
+ if ( (reference = getReference(method, type)) != null ) {
+ readIntents(method.getAnnotation(Requires.class), reference.getRequiredIntents());
+ readPolicySets(method.getAnnotation(PolicySets.class), reference.getPolicySets());
+ } else {
+ if ( type instanceof OperationsConfigurator ) {
+ //Read the intents specified on the given implementation method
+ if ( (method.getAnnotation(Requires.class) != null ||
+ method.getAnnotation(PolicySets.class) != null ) &&
+ (type instanceof PolicySetAttachPoint )) {
+ ConfiguredOperation confOp = assemblyFactory.createConfiguredOperation();
+ confOp.setName(method.getName());
+ ((OperationsConfigurator)type).getConfiguredOperations().add(confOp);
+
+
+ readIntents(method.getAnnotation(Requires.class), confOp.getRequiredIntents());
+ readPolicySets(method.getAnnotation(PolicySets.class), confOp.getPolicySets());
+ }
+ }
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessor.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessor.java
new file mode 100644
index 0000000000..cf1b4a9830
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessor.java
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.osoa.sca.annotations.Property;
+
+/**
+ * Processes an {@link @Property} annotation, updating the component type with
+ * corresponding {@link JavaMappedProperty}
+ *
+ * @version $Rev$ $Date$
+ */
+public class PropertyProcessor extends AbstractPropertyProcessor<Property> {
+
+ public PropertyProcessor(AssemblyFactory assemblyFactory) {
+ super(assemblyFactory, Property.class);
+ }
+
+ @Override
+ protected String getName(Property annotation) {
+ return annotation.name();
+ }
+
+ @Override
+ protected void initProperty(org.apache.tuscany.sca.assembly.Property property, Property annotation) {
+ property.setMustSupply(annotation.required());
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessor.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessor.java
new file mode 100644
index 0000000000..a1f8a766ae
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessor.java
@@ -0,0 +1,208 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.JavaIntrospectionHelper.getBaseType;
+
+import java.lang.annotation.ElementType;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Multiplicity;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaParameterImpl;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * 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 BaseJavaClassVisitor {
+ private JavaInterfaceFactory javaFactory;
+
+ public ReferenceProcessor(AssemblyFactory assemblyFactory, JavaInterfaceFactory javaFactory) {
+ super(assemblyFactory);
+ this.javaFactory = javaFactory;
+ }
+
+ @Override
+ public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException {
+ Reference annotation = method.getAnnotation(Reference.class);
+ if (annotation == null) {
+ return; // Not a reference annotation.
+ }
+ if (!JavaIntrospectionHelper.isSetter(method)) {
+ throw new IllegalReferenceException("Annotated method is not a setter: " + method, method);
+ }
+ String name = annotation.name();
+ if ("".equals(name)) {
+ name = JavaIntrospectionHelper.toPropertyName(method.getName());
+ }
+ JavaElementImpl ref = type.getReferenceMembers().get(name);
+ // Setter override field
+ if (ref != null && ref.getElementType() != ElementType.FIELD) {
+ throw new DuplicateReferenceException(name);
+ }
+ removeReference(ref, type);
+
+ JavaElementImpl element = new JavaElementImpl(method, 0);
+ org.apache.tuscany.sca.assembly.Reference reference = createReference(element, name);
+ type.getReferences().add(reference);
+ type.getReferenceMembers().put(name, element);
+ }
+
+ private boolean removeReference(JavaElementImpl ref, JavaImplementation type) {
+ if (ref == null) {
+ return false;
+ }
+ List<org.apache.tuscany.sca.assembly.Reference> refs = type.getReferences();
+ for (int i = 0; i < refs.size(); i++) {
+ if (refs.get(i).getName().equals(ref.getName())) {
+ refs.remove(i);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ @Override
+ public void visitField(Field field, JavaImplementation type) throws IntrospectionException {
+ Reference annotation = field.getAnnotation(Reference.class);
+ if (annotation == null) {
+ return;
+ }
+ String name = annotation.name();
+ if ("".equals(name)) {
+ name = field.getName();
+ }
+ JavaElementImpl ref = type.getReferenceMembers().get(name);
+ if (ref != null && ref.getElementType() == ElementType.FIELD) {
+ throw new DuplicateReferenceException(name);
+ }
+
+ // Setter method override field
+ if (ref == null) {
+ JavaElementImpl element = new JavaElementImpl(field);
+ org.apache.tuscany.sca.assembly.Reference reference = createReference(element, name);
+ type.getReferences().add(reference);
+ type.getReferenceMembers().put(name, element);
+ }
+ }
+
+ @Override
+ public void visitConstructorParameter(JavaParameterImpl parameter, JavaImplementation type)
+ throws IntrospectionException {
+ Reference refAnnotation = parameter.getAnnotation(Reference.class);
+ if (refAnnotation == null) {
+ return;
+ }
+ String paramName = parameter.getName();
+ String name = getReferenceName(paramName, parameter.getIndex(), refAnnotation.name());
+ JavaElementImpl ref = type.getReferenceMembers().get(name);
+
+ // Setter override field
+ if (ref != null && ref.getElementType() != ElementType.FIELD) {
+ throw new DuplicateReferenceException(name);
+ }
+
+ removeReference(ref, type);
+ org.apache.tuscany.sca.assembly.Reference reference = createReference(parameter, name);
+ type.getReferences().add(reference);
+ type.getReferenceMembers().put(name, parameter);
+ parameter.setClassifer(Reference.class);
+ parameter.setName(name);
+ }
+
+ private String getReferenceName(String paramName, int pos, String name) throws InvalidConstructorException {
+ if ("".equals(name)) {
+ name = paramName;
+ }
+ if ("".equals(name)) {
+ return "_ref" + pos;
+ }
+ if (!"".equals(paramName) && !name.equals(paramName)) {
+ throw new InvalidConstructorException("Mismatching names specified for reference parameter " + pos);
+ } else {
+ return name;
+ }
+ }
+
+ private org.apache.tuscany.sca.assembly.Reference createReference(JavaElementImpl element, String name)
+ throws IntrospectionException {
+ org.apache.tuscany.sca.assembly.Reference reference = assemblyFactory.createReference();
+ JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract();
+ reference.setInterfaceContract(interfaceContract);
+
+ // reference.setMember((Member)element.getAnchor());
+ boolean required = true;
+ Reference ref = element.getAnnotation(Reference.class);
+ if (ref != null) {
+ required = ref.required();
+ }
+ // reference.setRequired(required);
+ reference.setName(name);
+ Class<?> rawType = element.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);
+ }
+ }
+ Type genericType = element.getGenericType();
+ Class<?> baseType = getBaseType(rawType, genericType);
+ if (CallableReference.class.isAssignableFrom(baseType)) {
+ if (Collection.class.isAssignableFrom(rawType)) {
+ genericType = JavaIntrospectionHelper.getParameterType(genericType);
+ }
+ baseType = JavaIntrospectionHelper.getBusinessInterface(baseType, genericType);
+ }
+ try {
+ JavaInterface callInterface = javaFactory.createJavaInterface(baseType);
+ reference.getInterfaceContract().setInterface(callInterface);
+ if (callInterface.getCallbackClass() != null) {
+ JavaInterface callbackInterface = javaFactory.createJavaInterface(callInterface.getCallbackClass());
+ reference.getInterfaceContract().setCallbackInterface(callbackInterface);
+ }
+ } catch (InvalidInterfaceException e) {
+ throw new IntrospectionException(e);
+ }
+ return reference;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/Resource.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/Resource.java
new file mode 100644
index 0000000000..3d43e39ce8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/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.sca.implementation.java.introspect.impl;
+
+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/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessor.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessor.java
new file mode 100644
index 0000000000..e15f9a0d6a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessor.java
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Member;
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaParameterImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaResourceImpl;
+
+/**
+ * Processes an {@link @Resource} annotation, updating the component type with
+ * corresponding {@link org.apache.tuscany.spi.implementation.java.JavaResourceImpl}
+ *
+ * @version $Rev$ $Date$
+ */
+public class ResourceProcessor extends BaseJavaClassVisitor {
+
+ public ResourceProcessor(AssemblyFactory factory) {
+ super(factory);
+ }
+
+ @Override
+ public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException {
+ org.apache.tuscany.sca.implementation.java.introspect.impl.Resource annotation = method
+ .getAnnotation(org.apache.tuscany.sca.implementation.java.introspect.impl.Resource.class);
+ if (annotation == null) {
+ return;
+ }
+ if (method.getParameterTypes().length != 1) {
+ throw new IllegalResourceException("Resource setter must have one parameter", method);
+ }
+ String name = annotation.name();
+ if (name.length() < 1) {
+ name = JavaIntrospectionHelper.toPropertyName(method.getName());
+ }
+ if (type.getResources().get(name) != null) {
+ throw new DuplicateResourceException(name);
+ }
+
+ String mappedName = annotation.mappedName();
+ JavaResourceImpl resource = createResource(name, new JavaElementImpl(method, 0));
+ resource.setOptional(annotation.optional());
+ if (mappedName.length() > 0) {
+ resource.setMappedName(mappedName);
+ }
+ type.getResources().put(resource.getName(), resource);
+ }
+
+ @Override
+ public void visitField(Field field, JavaImplementation type) throws IntrospectionException {
+
+ org.apache.tuscany.sca.implementation.java.introspect.impl.Resource annotation = field
+ .getAnnotation(org.apache.tuscany.sca.implementation.java.introspect.impl.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);
+ }
+
+ String mappedName = annotation.mappedName();
+
+ JavaResourceImpl resource = createResource(name, new JavaElementImpl(field));
+ resource.setOptional(annotation.optional());
+ if (mappedName.length() > 0) {
+ resource.setMappedName(mappedName);
+ }
+ type.getResources().put(resource.getName(), resource);
+ }
+
+ @SuppressWarnings("unchecked")
+ public JavaResourceImpl createResource(String name, JavaElementImpl element) {
+ element.setClassifer(org.apache.tuscany.sca.implementation.java.introspect.impl.Resource.class);
+ element.setName(name);
+ return new JavaResourceImpl(element);
+ }
+
+ @Override
+ public void visitConstructorParameter(JavaParameterImpl parameter, JavaImplementation type)
+ throws IntrospectionException {
+ org.apache.tuscany.sca.implementation.java.introspect.impl.Resource resourceAnnotation = parameter
+ .getAnnotation(org.apache.tuscany.sca.implementation.java.introspect.impl.Resource.class);
+ if (resourceAnnotation != null) {
+ String name = resourceAnnotation.name();
+ if ("".equals(name)) {
+ name = parameter.getName();
+ }
+ if ("".equals(name)) {
+ throw new InvalidResourceException("Missing resource name", (Member)parameter.getAnchor());
+ }
+
+ if (!"".equals(parameter.getName()) && !name.equals(parameter.getName())) {
+ throw new InvalidConstructorException("Mismatched resource name: " + parameter);
+ }
+
+ if (type.getResources().get(name) != null) {
+ throw new DuplicateResourceException(name);
+ }
+
+ String mappedName = resourceAnnotation.mappedName();
+
+ JavaResourceImpl resource = createResource(name, parameter);
+ resource.setOptional(resourceAnnotation.optional());
+ if (mappedName.length() > 0) {
+ resource.setMappedName(mappedName);
+ }
+ type.getResources().put(resource.getName(), resource);
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ScopeProcessor.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ScopeProcessor.java
new file mode 100644
index 0000000000..a3d3889d30
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ScopeProcessor.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.impl.JavaScopeImpl;
+
+/**
+ * Processes the {@link JavaScopeImpl} annotation and updates the component type with the corresponding implmentation scope
+ *
+ * @version $Rev$ $Date$
+ */
+public class ScopeProcessor extends BaseJavaClassVisitor {
+
+ public ScopeProcessor(AssemblyFactory factory) {
+ super(factory);
+ }
+
+ @Override
+ public <T> void visitClass(Class<T> clazz,
+ JavaImplementation type)
+ throws IntrospectionException {
+ org.osoa.sca.annotations.Scope annotation = clazz.getAnnotation(org.osoa.sca.annotations.Scope.class);
+ if (annotation == null) {
+ type.setJavaScope(JavaScopeImpl.STATELESS);
+ return;
+ }
+ String name = annotation.value();
+ JavaScopeImpl scope;
+ if ("COMPOSITE".equals(name)) {
+ scope = JavaScopeImpl.COMPOSITE;
+ } else if ("SESSION".equals(name)) {
+ scope = JavaScopeImpl.SESSION;
+ } else if ("CONVERSATION".equals(name)) {
+ scope = JavaScopeImpl.CONVERSATION;
+ } else if ("REQUEST".equals(name)) {
+ scope = JavaScopeImpl.REQUEST;
+ } else {
+ scope = new JavaScopeImpl(name);
+ }
+ type.setJavaScope(scope);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java
new file mode 100644
index 0000000000..6854acdc2a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessor.java
@@ -0,0 +1,184 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.JavaIntrospectionHelper.getAllInterfaces;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Set;
+import java.util.logging.Logger;
+
+import javax.jws.WebService;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.Remotable;
+
+/**
+ * Processes an {@link org.osoa.sca.annotations.Service} annotation and updates
+ * the component type with corresponding {@link Service}s. Also processes
+ * related {@link org.osoa.sca.annotations.Callback} annotations.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ServiceProcessor extends BaseJavaClassVisitor {
+ private static final Logger logger = Logger.getLogger(ServiceProcessor.class.getName());
+ private JavaInterfaceFactory javaFactory;
+
+ public ServiceProcessor(AssemblyFactory assemblyFactory, JavaInterfaceFactory javaFactory) {
+ super(assemblyFactory);
+ this.javaFactory = javaFactory;
+ }
+
+ @Override
+ public <T> void visitClass(Class<T> clazz, JavaImplementation type) throws IntrospectionException {
+ org.osoa.sca.annotations.Service annotation = clazz.getAnnotation(org.osoa.sca.annotations.Service.class);
+ if (annotation == null) {
+ // scan interfaces for remotable
+ Set<Class> interfaces = getAllInterfaces(clazz);
+ for (Class<?> interfaze : interfaces) {
+ if (interfaze.isAnnotationPresent(Remotable.class)
+ || interfaze.isAnnotationPresent(WebService.class)
+ || interfaze.isAnnotationPresent(Callback.class)
+ ) {
+ Service service;
+ try {
+ service = createService(interfaze);
+ } catch (InvalidInterfaceException e) {
+ throw new IntrospectionException(e);
+ }
+ type.getServices().add(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");
+ logger.warning("Ignoring @Service annotation. No interfaces specified. class = "+clazz.getName());
+ } else {
+ interfaces = new Class<?>[1];
+ interfaces[0] = interfaze;
+ }
+ }
+ for (Class<?> interfaze : interfaces) {
+ try {
+ Service service = createService(interfaze);
+ type.getServices().add(service);
+ } catch (InvalidInterfaceException e) {
+ throw new IntrospectionException(e);
+ }
+ }
+ }
+
+ @Override
+ public void visitMethod(Method method, JavaImplementation type) throws IntrospectionException {
+
+ Callback annotation = method.getAnnotation(Callback.class);
+ if (annotation == null) {
+ return;
+ }
+ if(Modifier.isPrivate(method.getModifiers())) {
+ throw new IllegalCallbackReferenceException("Illegal annotation @Callback found on "+method, method);
+ }
+ if (method.getParameterTypes().length != 1) {
+ throw new IllegalCallbackReferenceException("Setter must have one parameter", method);
+ }
+ JavaElementImpl element = new JavaElementImpl(method, 0);
+ createCallback(type, element);
+ }
+
+ @Override
+ public void visitField(Field field, JavaImplementation type) throws IntrospectionException {
+
+ Callback annotation = field.getAnnotation(Callback.class);
+ if (annotation == null) {
+ return;
+ }
+ if(Modifier.isPrivate(field.getModifiers())) {
+ throw new IllegalCallbackReferenceException("Illegal annotation @Callback found on "+field, field);
+ }
+ JavaElementImpl element = new JavaElementImpl(field);
+ createCallback(type, element);
+ }
+
+ /**
+ * @param type
+ * @param element
+ * @throws IllegalCallbackReferenceException
+ */
+ private void createCallback(JavaImplementation type, JavaElementImpl element)
+ throws IllegalCallbackReferenceException {
+ Service callbackService = null;
+ Class<?> callbackClass = element.getType();
+ Type genericType = element.getGenericType();
+ Class<?> baseType = callbackClass;
+ if(CallableReference.class.isAssignableFrom(baseType)) {
+ // @Callback protected CallableReference<MyCallback> callback;
+ // The base type will be MyCallback
+ baseType = JavaIntrospectionHelper.getBusinessInterface(baseType, genericType);
+ }
+ for (Service service : type.getServices()) {
+ JavaInterface javaInterface = (JavaInterface)service.getInterfaceContract().getCallbackInterface();
+ if (javaInterface != null && baseType == javaInterface.getJavaClass()) {
+ callbackService = service;
+ }
+ }
+ if (callbackService == null) {
+ throw new IllegalCallbackReferenceException("Callback type does not match a service callback interface: " + type.getName() );
+ }
+ if(type.getCallbackMembers().get(baseType.getName()) == null) {
+ type.getCallbackMembers().put(baseType.getName(), new ArrayList<JavaElementImpl>());
+ }
+ type.getCallbackMembers().get(baseType.getName()).add(element);
+ }
+
+ public Service createService(Class<?> interfaze) throws InvalidInterfaceException {
+ Service service = assemblyFactory.createService();
+ JavaInterfaceContract interfaceContract = javaFactory.createJavaInterfaceContract();
+ service.setInterfaceContract(interfaceContract);
+
+ // create a relative URI
+ service.setName(interfaze.getSimpleName());
+
+ JavaInterface callInterface = javaFactory.createJavaInterface(interfaze);
+ service.getInterfaceContract().setInterface(callInterface);
+ if (callInterface.getCallbackClass() != null) {
+ JavaInterface callbackInterface = javaFactory.createJavaInterface(callInterface.getCallbackClass());
+ service.getInterfaceContract().setCallbackInterface(callbackInterface);
+ }
+ return service;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceTypeNotFoundException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceTypeNotFoundException.java
new file mode 100644
index 0000000000..e1ca3ea565
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceTypeNotFoundException.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.implementation.java.introspect.impl;
+
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+
+/**
+ * Thrown when a service interface cannot be determined based on a heuristic evaluation of an implementation
+ *
+ * @version $Rev$ $Date$
+ */
+public class ServiceTypeNotFoundException extends IntrospectionException {
+ private static final long serialVersionUID = -5124437274726947007L;
+
+ public ServiceTypeNotFoundException(String message) {
+ super(message);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/UnknownContextTypeException.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/UnknownContextTypeException.java
new file mode 100644
index 0000000000..57d224b2bf
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/java/org/apache/tuscany/sca/implementation/java/introspect/impl/UnknownContextTypeException.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.implementation.java.introspect.impl;
+
+/**
+ * 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 {
+ private static final long serialVersionUID = 8125863714365422419L;
+
+ public UnknownContextTypeException(String message) {
+ super(message);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator
new file mode 100644
index 0000000000..df60d57cf9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.core.ModuleActivator
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.implementation.java.impl.JavaImplementationActivator
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.java.JavaImplementationFactory b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.java.JavaImplementationFactory
new file mode 100644
index 0000000000..dc9de12632
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.java.JavaImplementationFactory
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractProcessorTest.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractProcessorTest.java
new file mode 100644
index 0000000000..fe93424d28
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractProcessorTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Constructor;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.impl.JavaConstructorImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaParameterImpl;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+
+
+/**
+ * Base class to simulate the processor sequences
+ *
+ * @version $Rev$ $Date$
+ */
+public class AbstractProcessorTest extends TestCase {
+ protected AssemblyFactory factory;
+ protected JavaInterfaceFactory javaFactory;
+ protected ConstructorProcessor constructorProcessor;
+ private ReferenceProcessor referenceProcessor;
+ private PropertyProcessor propertyProcessor;
+ private ResourceProcessor resourceProcessor;
+
+
+ protected AbstractProcessorTest() {
+ factory = new DefaultAssemblyFactory();
+ javaFactory = new DefaultJavaInterfaceFactory();
+ referenceProcessor = new ReferenceProcessor(factory, javaFactory);
+ propertyProcessor = new PropertyProcessor(factory);
+ resourceProcessor = new ResourceProcessor(factory);
+ constructorProcessor = new ConstructorProcessor(factory);
+ referenceProcessor = new ReferenceProcessor(factory, javaFactory);
+ propertyProcessor = new PropertyProcessor(factory);
+ }
+
+ protected <T> void visitConstructor(Constructor<T> constructor,
+ JavaImplementation type) throws IntrospectionException {
+ constructorProcessor.visitConstructor(constructor, type);
+ JavaConstructorImpl<?> definition = type.getConstructor();
+ if (definition == null) {
+ definition = new JavaConstructorImpl<T>(constructor);
+ type.getConstructors().put(constructor, definition);
+ }
+ JavaParameterImpl[] parameters = definition.getParameters();
+ for (int i = 0; i < parameters.length; i++) {
+ referenceProcessor.visitConstructorParameter(parameters[i], type);
+ propertyProcessor.visitConstructorParameter(parameters[i], type);
+ resourceProcessor.visitConstructorParameter(parameters[i], type);
+ // monitorProcessor.visitConstructorParameter(parameters[i], type);
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessorTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessorTestCase.java
new file mode 100644
index 0000000000..5beb31f0f9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AbstractPropertyProcessorTestCase.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.sca.implementation.java.introspect.impl;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.ModelHelper.getProperty;
+
+import java.lang.annotation.Retention;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.impl.JavaConstructorImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaParameterImpl;
+import org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor;
+
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AbstractPropertyProcessorTestCase extends TestCase {
+
+ private JavaClassVisitor extension;
+ private JavaImplementationFactory javaImplementationFactory;
+
+ public void testVisitMethod() throws Exception {
+ Method method = Foo.class.getMethod("setBar", String.class);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ extension.visitMethod(method, type);
+ Property prop = getProperty(type, "test");
+ assertNotNull(prop);
+ }
+
+ public void testVisitNoParamsMethod() throws Exception {
+ Method method = Foo.class.getMethod("setNoParamsBar");
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ try {
+ extension.visitMethod(method, type);
+ fail();
+ } catch (IllegalPropertyException e) {
+ // expected
+ }
+ }
+
+ public void testVisitNonVoidMethod() throws Exception {
+ Method method = Foo.class.getMethod("setBadBar", String.class);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ try {
+ extension.visitMethod(method, type);
+ fail();
+ } catch (IllegalPropertyException e) {
+ // expected
+ }
+ }
+
+ public void testDuplicateMethod() throws Exception {
+ Method method = Foo.class.getMethod("setBar", String.class);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ extension.visitMethod(method, type);
+ try {
+ extension.visitMethod(method, type);
+ fail();
+ } catch (DuplicatePropertyException e) {
+ // expected
+ }
+ }
+
+ public void testVisitField() throws Exception {
+ Field field = Foo.class.getDeclaredField("d");
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ extension.visitField(field, type);
+ Property prop = getProperty(type, "test");
+ assertNotNull(prop);
+ }
+
+ public void testVisitConstructor() throws Exception {
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ JavaConstructorImpl<Foo> def = new JavaConstructorImpl<Foo>(ctor);
+ JavaParameterImpl parameter = def.getParameters()[0];
+ extension.visitConstructorParameter(parameter, type);
+ assertEquals("test", def.getParameters()[0].getName());
+ assertNotNull(getProperty(type, "test"));
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected void setUp() throws Exception {
+ super.setUp();
+ extension = new TestProcessor();
+ javaImplementationFactory = new DefaultJavaImplementationFactory();
+ }
+
+ @Retention(RUNTIME)
+ private @interface Bar {
+
+ }
+
+ private class TestProcessor extends AbstractPropertyProcessor<Bar> {
+
+ public TestProcessor() {
+ super(new DefaultAssemblyFactory(), Bar.class);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected void initProperty(Property property, Bar annotation) {
+ // property.setDefaultValueFactory(EasyMock.createMock(ObjectFactory.class));
+ property.setName("test");
+ }
+
+ @Override
+ 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/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AllowsPassByReferenceProcessorTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AllowsPassByReferenceProcessorTestCase.java
new file mode 100644
index 0000000000..e5abb07760
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/AllowsPassByReferenceProcessorTestCase.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.osoa.sca.annotations.AllowsPassByReference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class AllowsPassByReferenceProcessorTestCase extends TestCase {
+
+ JavaImplementation type;
+ AllowsPassByReferenceProcessor processor;
+ private JavaImplementationFactory javaImplementationFactory;
+
+ public void testClassAnnotation() throws Exception {
+ processor.visitClass(Foo.class, type);
+ assertEquals(true, type.isAllowsPassByReference());
+
+ processor.visitClass(Bar.class, type);
+ assertEquals(false, type.isAllowsPassByReference());
+
+ Method m1 = Bar.class.getMethod("m1", new Class[] {});
+ processor.visitMethod(m1, type);
+ assertTrue(type.isAllowsPassByReference(m1));
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ javaImplementationFactory = new DefaultJavaImplementationFactory();
+ type = javaImplementationFactory.createJavaImplementation();
+ processor = new AllowsPassByReferenceProcessor(new DefaultAssemblyFactory());
+ }
+
+ @AllowsPassByReference
+ private class Foo {
+ }
+
+ // no annotation
+ private class Bar {
+ @AllowsPassByReference
+ public void m1() {
+
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessorTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessorTestCase.java
new file mode 100644
index 0000000000..fa1527fbe5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorProcessorTestCase.java
@@ -0,0 +1,192 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.ModelHelper.getProperty;
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.ModelHelper.getReference;
+
+import java.lang.reflect.Constructor;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.assembly.Multiplicity;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.impl.JavaParameterImpl;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorProcessorTestCase extends TestCase {
+ private ConstructorProcessor processor = new ConstructorProcessor(new DefaultAssemblyFactory());
+
+ private JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+
+ public void testDuplicateConstructor() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ try {
+ processor.visitClass(BadFoo.class, type);
+ fail();
+ } catch (DuplicateConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testConstructorAnnotation() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo> ctor1 = Foo.class.getConstructor(String.class);
+ processor.visitConstructor(ctor1, type);
+ assertEquals("foo", type.getConstructor().getParameters()[0].getName());
+ }
+
+ public void testNoAnnotation() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<NoAnnotation> ctor1 = NoAnnotation.class.getConstructor();
+ processor.visitConstructor(ctor1, type);
+ assertNull(type.getConstructor());
+ }
+
+ public void testBadAnnotation() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<BadAnnotation> ctor1 = BadAnnotation.class.getConstructor(String.class, Foo.class);
+ try {
+ processor.visitConstructor(ctor1, type);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testMixedParameters() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Mixed> ctor1 = Mixed.class.getConstructor(String.class, String.class, String.class);
+ processor.visitConstructor(ctor1, type);
+
+ AssemblyFactory assemblyFactory = new DefaultAssemblyFactory();
+ JavaInterfaceFactory javaFactory = new DefaultJavaInterfaceFactory();
+ ReferenceProcessor referenceProcessor = new ReferenceProcessor(assemblyFactory, javaFactory);
+ PropertyProcessor propertyProcessor = new PropertyProcessor(assemblyFactory);
+ JavaParameterImpl[] parameters = type.getConstructor().getParameters();
+ for (int i = 0; i < parameters.length; i++) {
+ referenceProcessor.visitConstructorParameter(parameters[i], type);
+ propertyProcessor.visitConstructorParameter(parameters[i], type);
+ }
+
+ assertEquals("_ref0", parameters[0].getName());
+ assertEquals("foo", parameters[1].getName());
+ assertEquals("bar", parameters[2].getName());
+ }
+
+ 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 {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Multiple> ctor1 = Multiple.class.getConstructor(Collection.class,
+ String[].class,
+ List.class,
+ Set.class,
+ String[].class);
+ processor.visitConstructor(ctor1, type);
+ AssemblyFactory assemblyFactory = new DefaultAssemblyFactory();
+ JavaInterfaceFactory javaFactory = new DefaultJavaInterfaceFactory();
+ ReferenceProcessor referenceProcessor = new ReferenceProcessor(assemblyFactory, javaFactory);
+ PropertyProcessor propertyProcessor = new PropertyProcessor(assemblyFactory);
+ JavaParameterImpl[] parameters = type.getConstructor().getParameters();
+ for (int i = 0; i < parameters.length; i++) {
+ referenceProcessor.visitConstructorParameter(parameters[i], type);
+ propertyProcessor.visitConstructorParameter(parameters[i], type);
+ }
+
+ org.apache.tuscany.sca.assembly.Reference ref0 = getReference(type, "_ref0");
+ assertNotNull(ref0);
+ assertEquals(Multiplicity.ONE_N, ref0.getMultiplicity());
+ org.apache.tuscany.sca.assembly.Reference ref1 = getReference(type, "bar");
+ assertNotNull(ref1);
+ assertEquals(Multiplicity.ONE_N, ref1.getMultiplicity());
+ org.apache.tuscany.sca.assembly.Reference ref2 = getReference(type, "xyz");
+ assertNotNull(ref2);
+ assertEquals(Multiplicity.ONE_N, ref2.getMultiplicity());
+ org.apache.tuscany.sca.assembly.Property prop1 = getProperty(type, "foo");
+ assertNotNull(prop1);
+ assertTrue(prop1.isMany());
+ org.apache.tuscany.sca.assembly.Property prop2 = getProperty(type, "abc");
+ assertNotNull(prop2);
+ assertTrue(prop2.isMany());
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorPropertyTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorPropertyTestCase.java
new file mode 100644
index 0000000000..690869ccb8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorPropertyTestCase.java
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.ModelHelper.getProperty;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.osoa.sca.annotations.Property;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorPropertyTestCase extends AbstractProcessorTest {
+
+ private JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+
+ public void testProperty() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
+ visitConstructor(ctor, type);
+ org.apache.tuscany.sca.assembly.Property property = getProperty(type, "myProp");
+ assertTrue(property.isMustSupply());
+ assertEquals("myProp", property.getName());
+ }
+
+ public void testTwoPropertiesSameType() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+ visitConstructor(ctor, type);
+ assertNotNull(getProperty(type, "myProp1"));
+ assertNotNull(getProperty(type, "myProp2"));
+ }
+
+ public void testDuplicateProperty() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class, String.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (DuplicatePropertyException e) {
+ // expected
+ }
+ }
+
+ public void testNoName() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (InvalidPropertyException e) {
+ // expected
+ }
+ }
+
+ public void testNamesOnConstructor() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo> ctor = Foo.class.getConstructor(Integer.class);
+ visitConstructor(ctor, type);
+ assertNotNull(getProperty(type, "myProp"));
+ }
+
+ public void testInvalidNumberOfNames() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(Integer.class, Integer.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testNoMatchingNames() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(List.class, List.class);
+ try {
+ visitConstructor(ctor, type);
+ 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/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorReferenceTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorReferenceTestCase.java
new file mode 100644
index 0000000000..8c10df2146
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorReferenceTestCase.java
@@ -0,0 +1,167 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.ModelHelper.getReference;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Multiplicity;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorReferenceTestCase extends AbstractProcessorTest {
+
+ private JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+
+ public void testReference() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
+ visitConstructor(ctor, type);
+ org.apache.tuscany.sca.assembly.Reference reference = getReference(type, "myRef");
+ assertEquals(Multiplicity.ONE_ONE, reference.getMultiplicity());
+ assertEquals("myRef", reference.getName());
+ }
+
+ public void testTwoReferencesSameType() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+ visitConstructor(ctor, type);
+ assertNotNull(getReference(type, "myRef1"));
+ assertNotNull(getReference(type, "myRef2"));
+ }
+
+ public void testDuplicateProperty() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class, String.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (DuplicateReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testNoName() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<NoNameFoo> ctor = NoNameFoo.class.getConstructor(String.class);
+ visitConstructor(ctor, type);
+ assertNotNull(getReference(type, "_ref0"));
+ }
+
+ public void testNamesOnConstructor() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo> ctor = Foo.class.getConstructor(Integer.class);
+ visitConstructor(ctor, type);
+ assertNotNull(getReference(type, "myRef"));
+ }
+
+ public void testInvalidNumberOfNames() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(Integer.class, Integer.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testNoMatchingNames() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(List.class, List.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+// 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/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorResourceTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorResourceTestCase.java
new file mode 100644
index 0000000000..365fb12afe
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConstructorResourceTestCase.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Constructor;
+import java.util.List;
+
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConstructorResourceTestCase extends AbstractProcessorTest {
+
+ private JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+
+ public void testResource() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class);
+ visitConstructor(ctor, type);
+ org.apache.tuscany.sca.implementation.java.impl.JavaResourceImpl resource = type.getResources().get("myResource");
+ assertFalse(resource.isOptional());
+ }
+
+ public void testTwoResourcesSameType() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+ visitConstructor(ctor, type);
+ assertNotNull(type.getResources().get("myResource1"));
+ assertNotNull(type.getResources().get("myResource2"));
+ }
+
+ public void testDuplicateResource() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<BadFoo> ctor = BadFoo.class.getConstructor(String.class, String.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (DuplicateResourceException e) {
+ // expected
+ }
+ }
+
+ public void testNoName() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<ConstructorResourceTestCase.BadFoo> ctor =
+ ConstructorResourceTestCase.BadFoo.class.getConstructor(String.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (InvalidResourceException e) {
+ // expected
+ }
+ }
+
+ public void testNamesOnConstructor() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo> ctor = Foo.class.getConstructor(Integer.class);
+ visitConstructor(ctor, type);
+ assertNotNull(type.getResources().get("myResource"));
+ }
+
+ public void testInvalidNumberOfNames() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<ConstructorResourceTestCase.BadFoo> ctor =
+ ConstructorResourceTestCase.BadFoo.class.getConstructor(Integer.class, Integer.class);
+ try {
+ visitConstructor(ctor, type);
+ fail();
+ } catch (InvalidConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testNoMatchingNames() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<ConstructorResourceTestCase.BadFoo> ctor =
+ ConstructorResourceTestCase.BadFoo.class.getConstructor(List.class, List.class);
+ try {
+ visitConstructor(ctor, type);
+ 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/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ContextProcessorTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ContextProcessorTestCase.java
new file mode 100644
index 0000000000..f77c9abad9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ContextProcessorTestCase.java
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.osoa.sca.ComponentContext;
+import org.osoa.sca.RequestContext;
+import org.osoa.sca.annotations.ComponentName;
+import org.osoa.sca.annotations.Context;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ContextProcessorTestCase extends TestCase {
+ private ContextProcessor processor;
+ private ComponentNameProcessor nameProcessor;
+ private JavaImplementationFactory javaImplementationFactory;
+
+ public void testComponentContextMethod() throws Exception {
+ Method method = Foo.class.getMethod("setContext", ComponentContext.class);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitMethod(method, type);
+ assertNotNull(type.getResources().get("context"));
+ }
+
+ public void testComponentContextField() throws Exception {
+ Field field = Foo.class.getDeclaredField("context");
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitField(field, type);
+ assertNotNull(type.getResources().get("context"));
+ }
+
+ public void testRequestContextMethod() throws Exception {
+ Method method = Foo.class.getMethod("setRequestContext", RequestContext.class);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitMethod(method, type);
+ assertNotNull(type.getResources().get("requestContext"));
+ }
+
+ public void testRequestContextField() throws Exception {
+ Field field = Foo.class.getDeclaredField("requestContext");
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitField(field, type);
+ assertNotNull(type.getResources().get("requestContext"));
+ }
+
+ public void testComponentNameMethod() throws Exception {
+ Method method = Foo.class.getMethod("setName", String.class);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ nameProcessor.visitMethod(method, type);
+ assertNotNull(type.getResources().get("name"));
+ }
+
+ public void testComponentNameField() throws Exception {
+ Field field = Foo.class.getDeclaredField("name");
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ nameProcessor.visitField(field, type);
+ assertNotNull(type.getResources().get("name"));
+ }
+
+ public void testInvalidParamType() throws Exception {
+ Method method = Foo.class.getMethod("setContext", String.class);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (UnknownContextTypeException e) {
+ // expected
+ }
+ }
+
+ public void testInvalidParamTypeField() throws Exception {
+ Field field = Foo.class.getDeclaredField("badContext");
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ try {
+ processor.visitField(field, type);
+ fail();
+ } catch (UnknownContextTypeException e) {
+ // expected
+ }
+ }
+
+
+ public void testInvalidParamNum() throws Exception {
+ Method method = Foo.class.getMethod("setContext", ComponentContext.class, String.class);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (IllegalContextException e) {
+ // expected
+ }
+ }
+
+ public void testInvalidNoParams() throws Exception {
+ Method method = Foo.class.getMethod("setContext");
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (IllegalContextException e) {
+ // expected
+ }
+ }
+
+ public void testNoContext() throws Exception {
+ Method method = Foo.class.getMethod("noContext", ComponentContext.class);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitMethod(method, type);
+ assertEquals(0, type.getResources().size());
+ }
+
+ public void testNoContextField() throws Exception {
+ Field field = Foo.class.getDeclaredField("noContext");
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitField(field, type);
+ assertEquals(0, type.getResources().size());
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ javaImplementationFactory = new DefaultJavaImplementationFactory();
+ processor = new ContextProcessor(new DefaultAssemblyFactory());
+ nameProcessor = new ComponentNameProcessor(new DefaultAssemblyFactory());
+ }
+
+ private class Foo {
+ @Context
+ protected ComponentContext context;
+
+ @ComponentName
+ protected String name;
+
+ @Context
+ protected Object badContext;
+
+ protected ComponentContext noContext;
+
+ @Context
+ protected RequestContext requestContext;
+
+ @Context
+ public void setContext(ComponentContext context) {
+
+ }
+
+ @ComponentName
+ public void setName(String name) {
+
+ }
+
+ @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/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessorTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessorTestCase.java
new file mode 100644
index 0000000000..c6b2626e9c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationIDProcessorTestCase.java
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.osoa.sca.annotations.ConversationID;
+
+/**
+ * Test the ConversationIDProcessor
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConversationIDProcessorTestCase extends TestCase {
+ private ConversationIDProcessor processor;
+ private JavaImplementationFactory javaImplementationFactory;
+
+ public void testConversationIDMethod() throws Exception {
+ Method method = Foo.class.getMethod("setConversationID", String.class);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitMethod(method, type);
+ assertNotNull(type.getResources().get("conversationID"));
+ }
+
+ public void testConversationIDField() throws Exception {
+ Field field = Foo.class.getDeclaredField("cid");
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitField(field, type);
+ assertNotNull(type.getResources().get("cid"));
+ }
+
+ public void testConversationIDMethodNotString() throws Exception {
+ Method method = Foo.class.getMethod("setConversationID", Long.class);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitMethod(method, type);
+ assertNotNull(type.getResources().get("conversationID"));
+ }
+
+ public void testConversationIDFieldNotString() throws Exception {
+ Field field = Foo.class.getDeclaredField("longCID");
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitField(field, type);
+ assertNotNull(type.getResources().get("longCID"));
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ javaImplementationFactory = new DefaultJavaImplementationFactory();
+ processor = new ConversationIDProcessor(new DefaultAssemblyFactory());
+ }
+
+ private class Foo {
+
+ @ConversationID
+ protected String cid;
+
+ @ConversationID
+ public void setConversationID(String cid) {
+
+ }
+
+ @ConversationID
+ protected Long longCID;
+
+ @ConversationID
+ public void setConversationID(Long cid) {
+
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationProcessorTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationProcessorTestCase.java
new file mode 100644
index 0000000000..4555736813
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConversationProcessorTestCase.java
@@ -0,0 +1,144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.osoa.sca.annotations.ConversationAttributes;
+import org.osoa.sca.annotations.ConversationID;
+import org.osoa.sca.annotations.Scope;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConversationProcessorTestCase extends TestCase {
+ private ConversationProcessor processor = new ConversationProcessor(new DefaultAssemblyFactory());
+ private JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+
+ public void testMaxIdleTime() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(FooMaxIdle.class, type);
+ assertEquals(10000L, type.getMaxIdleTime());
+ assertEquals(-1, type.getMaxAge());
+ }
+
+ public void testMaxAge() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(FooMaxAge.class, type);
+ assertEquals(10000L, type.getMaxAge());
+ assertEquals(-1, type.getMaxIdleTime());
+ }
+
+ public void testImplicitScope() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(ImplicitFooScope.class, type);
+ assertEquals(org.apache.tuscany.sca.implementation.java.impl.JavaScopeImpl.CONVERSATION, type.getJavaScope());
+ }
+
+ /* TUSCANY-1999 - apply conversation properties to all scopes
+ public void testBadFooScope() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ try {
+ processor.visitClass(BadFooScope.class, type);
+ fail();
+ } catch (InvalidConversationalImplementation e) {
+ // expected
+ }
+ }
+ */
+
+ public void testBadFooBoth() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(BadFooBoth.class, type);
+ assertEquals(10000L, type.getMaxAge());
+ assertEquals(10000L, type.getMaxIdleTime());
+ }
+
+ public void testJustConversation() throws Exception {
+ // TODO do we want these semantics
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(FooJustConversation.class, type);
+ assertEquals(org.apache.tuscany.sca.implementation.java.impl.JavaScopeImpl.CONVERSATION, type.getJavaScope());
+ assertEquals(-1, type.getMaxAge());
+ assertEquals(-1, type.getMaxIdleTime());
+ }
+
+ public void testSetConversationIDField() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Field field = FooWithConversationIDField.class.getDeclaredField("conversationID");
+ processor.visitField(field, type);
+ assertNotNull(type.getConversationIDMembers());
+ assertEquals(field, type.getConversationIDMembers().get(0));
+ }
+
+ public void testSetConversationIDMethod() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Method method = FooWithConversationIDMethod.class.getDeclaredMethods()[0];
+ processor.visitMethod(method, type);
+ assertNotNull(type.getConversationIDMembers());
+ assertEquals(method, type.getConversationIDMembers().get(0));
+ }
+
+ @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
+ String conversationID;
+ }
+
+ private class FooWithConversationIDMethod {
+ @ConversationID
+ void setConversationID(String conversationID) {
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConvertTimeMillisTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConvertTimeMillisTestCase.java
new file mode 100644
index 0000000000..aa2671071c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ConvertTimeMillisTestCase.java
@@ -0,0 +1,117 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+
+/**
+ * @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
+ }
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ registy = new MockProcessor();
+ }
+
+ private class MockProcessor extends ConversationProcessor {
+
+ public MockProcessor() {
+ super(new DefaultAssemblyFactory());
+ }
+
+ @Override
+ protected long convertTimeMillis(String expr) throws NumberFormatException {
+ return super.convertTimeMillis(expr);
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DestroyProcessorTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DestroyProcessorTestCase.java
new file mode 100644
index 0000000000..ffc67325fa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/DestroyProcessorTestCase.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.osoa.sca.annotations.Destroy;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class DestroyProcessorTestCase extends TestCase {
+
+ private AssemblyFactory assemblyFactory = new DefaultAssemblyFactory();
+ private JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+
+ public void testDestroy() throws Exception {
+ DestroyProcessor processor = new DestroyProcessor(assemblyFactory);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Method method = Foo.class.getMethod("destroy");
+ processor.visitMethod(method, type);
+ assertNotNull(type.getDestroyMethod());
+ }
+
+ public void testBadDestroy() throws Exception {
+ DestroyProcessor processor = new DestroyProcessor(assemblyFactory);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Method method = Bar.class.getMethod("badDestroy", String.class);
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (IllegalDestructorException e) {
+ // expected
+ }
+ }
+
+ public void testTwoDestroy() throws Exception {
+ DestroyProcessor processor = new DestroyProcessor(assemblyFactory);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Method method = Bar.class.getMethod("destroy");
+ Method method2 = Bar.class.getMethod("destroy2");
+ processor.visitMethod(method, type);
+ try {
+ processor.visitMethod(method2, type);
+ fail();
+ } catch (DuplicateDestructorException e) {
+ // expected
+ }
+ }
+
+ public void testProtectedDestroy() throws Exception {
+ DestroyProcessor processor = new DestroyProcessor(assemblyFactory);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Method method = Bar.class.getDeclaredMethod("protectedDestroy");
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (IllegalDestructorException e) {
+ // expected
+ }
+ }
+
+ public void testPrivateDestroy() throws Exception {
+ DestroyProcessor processor = new DestroyProcessor(assemblyFactory);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Method method = Bar.class.getDeclaredMethod("privateDestroy");
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (IllegalDestructorException 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) {
+ }
+
+ @Destroy
+ protected void protectedDestroy(){
+ }
+
+ @Destroy
+ private void privateDestroy(){
+ }
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/EagerInitProcessorTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/EagerInitProcessorTestCase.java
new file mode 100644
index 0000000000..09bcc7ab6c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/EagerInitProcessorTestCase.java
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.osoa.sca.annotations.EagerInit;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class EagerInitProcessorTestCase extends TestCase {
+
+ private AssemblyFactory assemblyFactory = new DefaultAssemblyFactory();
+ private JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+
+ public void testNoLevel() throws IntrospectionException {
+ EagerInitProcessor processor = new EagerInitProcessor(assemblyFactory);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(Level.class, type);
+ }
+
+ public void testSubclass() throws IntrospectionException {
+ EagerInitProcessor processor = new EagerInitProcessor(assemblyFactory);
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(SubClass.class, type);
+ }
+
+ @EagerInit
+ private class Level {
+ }
+
+ private class SubClass extends Level {
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicAndPropertyTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicAndPropertyTestCase.java
new file mode 100644
index 0000000000..c7f340bd46
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicAndPropertyTestCase.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Constructor;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.impl.JavaConstructorImpl;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.osoa.sca.annotations.Property;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class HeuristicAndPropertyTestCase extends TestCase {
+
+ private PropertyProcessor propertyProcessor;
+ private HeuristicPojoProcessor heuristicProcessor;
+ private AssemblyFactory assemblyFactory = new DefaultAssemblyFactory();
+ private JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+
+ /**
+ * Verifies the property and heuristic processors don't collide
+ */
+ @SuppressWarnings("unchecked")
+ public void testPropertyProcessorWithHeuristicProcessor() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor ctor = Foo.class.getConstructor(String.class);
+ type.setConstructor(new JavaConstructorImpl(ctor));
+ propertyProcessor.visitConstructorParameter(type.getConstructor().getParameters()[0], type);
+ heuristicProcessor.visitEnd(Foo.class, type);
+ assertEquals(1, type.getProperties().size());
+ assertEquals("foo", type.getProperties().get(0).getName());
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ propertyProcessor = new PropertyProcessor(assemblyFactory);
+ heuristicProcessor = new HeuristicPojoProcessor(assemblyFactory, new DefaultJavaInterfaceFactory());
+ }
+
+ public static class Foo {
+ public Foo(@Property(name = "foo")
+ String prop) {
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicConstructorTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicConstructorTestCase.java
new file mode 100644
index 0000000000..e98a8fec1f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicConstructorTestCase.java
@@ -0,0 +1,310 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.ModelHelper.getProperty;
+
+import java.lang.reflect.Constructor;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Remotable;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class HeuristicConstructorTestCase extends AbstractProcessorTest {
+
+ private AssemblyFactory factory;
+ private JavaInterfaceFactory javaFactory;
+ private HeuristicPojoProcessor processor;
+ private JavaImplementationFactory javaImplementationFactory;
+
+ public HeuristicConstructorTestCase() {
+ factory = new DefaultAssemblyFactory();
+ javaFactory = new DefaultJavaInterfaceFactory();
+ javaImplementationFactory = new DefaultJavaImplementationFactory();
+ processor = new HeuristicPojoProcessor(factory, javaFactory);
+ }
+
+ private <T> void visitEnd(Class<T> clazz, JavaImplementation type) throws IntrospectionException {
+ for (Constructor<?> constructor : clazz.getConstructors()) {
+ visitConstructor(constructor, type);
+ }
+ processor.visitEnd(clazz, type);
+ }
+
+ /**
+ * Verifies a single constructor is chosen with a parameter as the type
+ */
+ public void testSingleConstructorWithParam() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ org.apache.tuscany.sca.assembly.Property prop = factory.createProperty();
+ prop.setName("foo");
+ type.getProperties().add(prop);
+ // Hack to add a property member
+ JavaElementImpl element = new JavaElementImpl("foo", String.class, null);
+ type.getPropertyMembers().put("foo", element);
+ visitEnd(Foo1.class, type);
+ assertNotNull(type.getConstructor().getConstructor());
+ assertEquals("foo", type.getConstructor().getParameters()[0].getName());
+ }
+
+ /**
+ * Verifies a single constructor is chosen with a reference as the type
+ */
+ public void testSingleConstructorWithRef() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ org.apache.tuscany.sca.assembly.Reference ref = factory.createReference();
+ ref.setName("foo");
+ type.getReferences().add(ref);
+ type.getReferenceMembers().put("foo", new JavaElementImpl("foo", String.class, null));
+ visitEnd(Foo1.class, type);
+ assertNotNull(type.getConstructor().getConstructor());
+ assertEquals("foo", type.getConstructor().getParameters()[0].getName());
+ }
+
+ /**
+ * Verifies a single constructor is chosen with a property and a reference
+ * as the type
+ */
+ public void testSingleConstructorWithPropRef() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+
+ org.apache.tuscany.sca.assembly.Property prop = factory.createProperty();
+ prop.setName("foo");
+ type.getProperties().add(prop);
+ // Hack to add a property member
+ JavaElementImpl element = new JavaElementImpl("foo", String.class, null);
+ type.getPropertyMembers().put("foo", element);
+
+ org.apache.tuscany.sca.assembly.Reference ref = ModelHelper.createReference(factory, javaFactory, "ref", Foo1.class);
+ type.getReferences().add(ref);
+ type.getReferenceMembers().put("ref", new JavaElementImpl("ref", Foo1.class, null));
+ visitEnd(Foo2.class, type);
+ assertNotNull(type.getConstructor().getConstructor());
+ assertEquals(2, type.getConstructor().getParameters().length);
+ }
+
+ public void testSingleConstructorResolvableParam() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ visitEnd(Foo5.class, type);
+ assertEquals(String.class, type.getPropertyMembers().get("string").getType());
+ }
+
+ public void testSingleConstructorResolvableRef() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ visitEnd(Foo6.class, type);
+ assertTrue(ModelHelper.matches(ModelHelper.getReference(type, "ref"), Ref.class));
+ }
+
+ public void testSingleConstructorAmbiguousRef() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ org.apache.tuscany.sca.assembly.Reference ref = ModelHelper.createReference(factory, javaFactory, "ref", Foo1.class);
+ type.getReferences().add(ref);
+ type.getReferenceMembers().put("ref", new JavaElementImpl("ref", Foo1.class, null));
+ org.apache.tuscany.sca.assembly.Reference ref2 = ModelHelper.createReference(factory, javaFactory, "ref2", Foo1.class);
+ type.getReferences().add(ref2);
+ type.getReferenceMembers().put("ref2", new JavaElementImpl("ref2", Foo1.class, null));
+ try {
+ visitEnd(Foo4.class, type);
+ fail();
+ } catch (AmbiguousConstructorException e) {
+ // expected
+ }
+ }
+
+ public void testConstructorPropertyAnnotatedParamsOnly() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ visitEnd(Foo7.class, type);
+ assertNotNull(getProperty(type, "myProp"));
+ }
+
+ public void testConstructorReferenceAnnotatedParamsOnly() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ visitEnd(Foo8.class, type);
+ assertNotNull(ModelHelper.getReference(type, "myRef"));
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testDefaultConstructor() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ visitEnd(Foo3.class, type);
+ assertNotNull(type.getConstructor().getConstructor());
+ }
+
+ public void testSameTypesButAnnotated() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ visitEnd(Foo12.class, type);
+ assertEquals(2, type.getProperties().size());
+ assertNotNull(getProperty(type, "prop1"));
+ assertNotNull(getProperty(type, "prop2"));
+ }
+
+ /**
+ * Verifies processing executes with additional extension annotations
+ */
+ public void testRandomAnnotation() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ visitEnd(Foo11.class, type);
+ assertEquals(1, type.getProperties().size());
+ assertNotNull(getProperty(type, "prop1"));
+ }
+
+ public void testPrivateConstructor() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ try {
+ visitEnd(Foo14.class, type);
+ 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/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessorTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessorTestCase.java
new file mode 100644
index 0000000000..ff267cd938
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeuristicPojoProcessorTestCase.java
@@ -0,0 +1,562 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Constructor;
+import java.util.Collection;
+import java.util.List;
+
+import javax.jws.WebService;
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.impl.JavaConstructorImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper;
+import org.osoa.sca.annotations.Property;
+import org.osoa.sca.annotations.Reference;
+import org.osoa.sca.annotations.Remotable;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * Verifies 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 AbstractProcessorTest {
+
+ private org.apache.tuscany.sca.implementation.java.introspect.impl.HeuristicPojoProcessor processor;
+ private JavaImplementationFactory javaImplementationFactory;
+
+ public HeuristicPojoProcessorTestCase() {
+ processor = new HeuristicPojoProcessor(new DefaultAssemblyFactory(), new DefaultJavaInterfaceFactory());
+ javaImplementationFactory = new DefaultJavaImplementationFactory();
+ }
+
+ private <T> void visitEnd(Class<T> clazz, JavaImplementation type) throws IntrospectionException {
+ for (Constructor<?> constructor : clazz.getConstructors()) {
+ visitConstructor(constructor, type);
+ }
+ processor.visitEnd(clazz, type);
+ }
+
+ /**
+ * Verifies a single service interface is computed when only one interface
+ * is implemented
+ */
+ public void testSingleInterface() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<SingleInterfaceImpl> ctor = SingleInterfaceImpl.class.getConstructor();
+ type.setConstructor(new JavaConstructorImpl<SingleInterfaceImpl>(ctor));
+ processor.visitEnd(SingleInterfaceImpl.class, type);
+ assertEquals(1, type.getServices().size());
+ assertTrue(ModelHelper.matches(ModelHelper.getService(type, PropertyInterface.class.getSimpleName()),
+ PropertyInterface.class));
+ assertTrue(type.getProperties().isEmpty());
+ assertTrue(type.getReferences().isEmpty());
+ }
+
+ /**
+ * Verifies property and reference setters are computed
+ */
+ public void testPropertyReference() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<SingleInterfaceWithPropertyReferenceImpl> ctor = SingleInterfaceWithPropertyReferenceImpl.class
+ .getConstructor();
+ type.setConstructor(new JavaConstructorImpl<SingleInterfaceWithPropertyReferenceImpl>(ctor));
+ processor.visitEnd(SingleInterfaceWithPropertyReferenceImpl.class, type);
+ assertEquals(1, type.getServices().size());
+ assertTrue(ModelHelper
+ .matches(ModelHelper.getService(type, Interface1.class.getSimpleName()), Interface1.class));
+ assertEquals(1, type.getProperties().size());
+ org.apache.tuscany.sca.assembly.Property prop = ModelHelper.getProperty(type, "property");
+ assertNotNull(prop);
+ assertEquals(ComplexProperty.class, type.getPropertyMembers().get("property").getType());
+ assertEquals(1, type.getReferences().size());
+ assertTrue(ModelHelper.matches(ModelHelper.getReference(type, "reference"), Ref.class));
+ }
+
+ /**
+ * Verifies that a property setter is not introspected if an analogous
+ * operation is in the service interface
+ */
+ public void testPropertySetterInInterface() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<SingleInterfaceImpl> ctor = SingleInterfaceImpl.class.getConstructor();
+ type.setConstructor(new JavaConstructorImpl<SingleInterfaceImpl>(ctor));
+ processor.visitEnd(SingleInterfaceImpl.class, type);
+ 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 {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<RefInterfaceImpl> ctor = RefInterfaceImpl.class.getConstructor();
+ type.setConstructor(new JavaConstructorImpl<RefInterfaceImpl>(ctor));
+ processor.visitEnd(RefInterfaceImpl.class, type);
+ assertEquals(0, type.getReferences().size());
+ }
+
+ /**
+ * Verifies collection generic types or array types are introspected as
+ * references according to specification rules
+ */
+ public void testReferenceCollectionType() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<ReferenceCollectionImpl> ctor = ReferenceCollectionImpl.class.getConstructor();
+ type.setConstructor(new JavaConstructorImpl<ReferenceCollectionImpl>(ctor));
+ processor.visitEnd(ReferenceCollectionImpl.class, type);
+ assertEquals(1, type.getProperties().size());
+ assertEquals(3, type.getReferences().size());
+ }
+
+ /**
+ * Verifies collection generic types or array types are introspected as
+ * properties according to specification rules
+ */
+ public void testPropertyCollectionType() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<PropertyCollectionImpl> ctor = PropertyCollectionImpl.class.getConstructor();
+ type.setConstructor(new JavaConstructorImpl<PropertyCollectionImpl>(ctor));
+ processor.visitEnd(PropertyCollectionImpl.class, type);
+ 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 {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<RemotableRefImpl> ctor = RemotableRefImpl.class.getConstructor();
+ type.setConstructor(new JavaConstructorImpl<RemotableRefImpl>(ctor));
+ processor.visitEnd(RemotableRefImpl.class, type);
+ assertEquals(2, type.getReferences().size());
+ assertEquals(0, type.getProperties().size());
+ }
+
+ public void testParentInterface() throws IntrospectionException, NoSuchMethodException {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Child> ctor = Child.class.getConstructor();
+ type.setConstructor(new JavaConstructorImpl<Child>(ctor));
+ processor.visitEnd(Child.class, type);
+ assertNotNull(ModelHelper.getService(type, Interface1.class.getSimpleName()));
+ }
+
+ /**
+ * Verifies a service interface is calculated when only props and refs are
+ * given
+ */
+ public void testExcludedPropertyAndReference() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ org.apache.tuscany.sca.assembly.Reference ref = factory.createReference();
+ ref.setName("reference");
+ type.getReferences().add(ref);
+ type.getReferenceMembers().put("reference", new JavaElementImpl("reference", Ref.class, null));
+ org.apache.tuscany.sca.assembly.Reference ref2 = factory.createReference();
+ ref2.setName("reference2");
+ type.getReferences().add(ref2);
+ type.getReferenceMembers().put("reference2", new JavaElementImpl("reference2", Ref.class, null));
+ org.apache.tuscany.sca.assembly.Property prop1 = factory.createProperty();
+ prop1.setName("string1");
+ type.getProperties().add(prop1);
+ type.getPropertyMembers().put("string1", new JavaElementImpl("string1", String.class, null));
+ org.apache.tuscany.sca.assembly.Property prop2 = factory.createProperty();
+ prop2.setName("string2");
+ type.getProperties().add(prop2);
+ type.getPropertyMembers().put("string2", new JavaElementImpl("string2", String.class, null));
+ visitEnd(MockService.class, type);
+ assertEquals(1, type.getServices().size());
+ }
+
+ public void testProtectedRemotableRefField() throws IntrospectionException, NoSuchMethodException {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<ProtectedRemotableRefFieldImpl> ctor = ProtectedRemotableRefFieldImpl.class.getConstructor();
+ type.setConstructor(new JavaConstructorImpl<ProtectedRemotableRefFieldImpl>(ctor));
+ processor.visitEnd(ProtectedRemotableRefFieldImpl.class, type);
+ assertNotNull(ModelHelper.getReference(type, "otherRef"));
+ }
+
+ public void testProtectedRemotableRefMethod() throws IntrospectionException, NoSuchMethodException {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<ProtectedRemotableRefMethodImpl> ctor = ProtectedRemotableRefMethodImpl.class.getConstructor();
+ type.setConstructor(new JavaConstructorImpl<ProtectedRemotableRefMethodImpl>(ctor));
+ processor.visitEnd(ProtectedRemotableRefMethodImpl.class, type);
+ assertNotNull(ModelHelper.getReference(type, "otherRef"));
+ }
+
+ public void testSetDataTypes() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<PropertyIntTypeOnConstructor> ctor = PropertyIntTypeOnConstructor.class.getConstructor();
+ type.setConstructor(new JavaConstructorImpl<PropertyIntTypeOnConstructor>(ctor));
+ processor.visitEnd(PropertyIntTypeOnConstructor.class, type);
+ org.apache.tuscany.sca.assembly.Property foo = ModelHelper.getProperty(type, "foo");
+ assertEquals(int.class, type.getPropertyMembers().get("foo").getType());
+ assertEquals(new QName(JavaXMLMapper.URI_2001_SCHEMA_XSD, "int"), foo.getXSDType());
+ }
+
+ /**
+ * Errata for Java Component Implementation Specification v1.0 corrects the algorithm for determining
+ * references of an unannotated POJO (section 1.2.7). This test makes sure that the earlier implementation
+ * is corrected as per the errata. A notable difference is that the interfaces annotated with @Service
+ * no longer result in references.
+ */
+ public void testUpdatedRule() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ visitEnd(SomeServiceImpl.class, type);
+ assertEquals(12, type.getReferenceMembers().size());
+ assertTrue(type.getReferenceMembers().containsKey("rri1"));
+ assertTrue(type.getReferenceMembers().containsKey("rri2"));
+ assertTrue(type.getReferenceMembers().containsKey("rri3"));
+ assertTrue(type.getReferenceMembers().containsKey("rri4"));
+
+ assertTrue(type.getReferenceMembers().containsKey("rria1"));
+ assertTrue(type.getReferenceMembers().containsKey("rria2"));
+ assertTrue(type.getReferenceMembers().containsKey("rria3"));
+ assertTrue(type.getReferenceMembers().containsKey("rria4"));
+
+ assertTrue(type.getReferenceMembers().containsKey("rric1"));
+ assertTrue(type.getReferenceMembers().containsKey("rric2"));
+ assertTrue(type.getReferenceMembers().containsKey("rric3"));
+ assertTrue(type.getReferenceMembers().containsKey("rric4"));
+
+ assertEquals(16, type.getPropertyMembers().size());
+ assertTrue(type.getPropertyMembers().containsKey("pnri1"));
+ assertTrue(type.getPropertyMembers().containsKey("pnri2"));
+ assertTrue(type.getPropertyMembers().containsKey("pnri3"));
+ assertTrue(type.getPropertyMembers().containsKey("pnri4"));
+
+ assertTrue(type.getPropertyMembers().containsKey("pnria1"));
+ assertTrue(type.getPropertyMembers().containsKey("pnria2"));
+ assertTrue(type.getPropertyMembers().containsKey("pnria3"));
+ assertTrue(type.getPropertyMembers().containsKey("pnria4"));
+
+ assertTrue(type.getPropertyMembers().containsKey("pnric1"));
+ assertTrue(type.getPropertyMembers().containsKey("pnric2"));
+ assertTrue(type.getPropertyMembers().containsKey("pnric3"));
+ assertTrue(type.getPropertyMembers().containsKey("pnric4"));
+
+ assertTrue(type.getPropertyMembers().containsKey("gen1"));
+ assertTrue(type.getPropertyMembers().containsKey("gen2"));
+ assertTrue(type.getPropertyMembers().containsKey("gen3"));
+ assertTrue(type.getPropertyMembers().containsKey("gen4"));
+ }
+
+ /**
+ * Interfaces with "@WebService" annotation implemented by the class should result
+ * in a Service in the same manner as an "@Remotable" annotation would.
+ */
+ public void testInterfaceWithWebServiceAnnotation() throws Exception{
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ visitEnd(SomeWebServiceImpl.class, type);
+ assertEquals(1, type.getServices().size());
+ assertEquals("SomeWebService", type.getServices().get(0).getName());
+ }
+
+ @Remotable
+ private interface ReferenceRemotableInterface {
+ void operation1(String param1);
+ }
+
+ @Service
+ private interface PropertyNonRemotableInterface {
+ void operation1(String param1);
+ }
+
+ @Remotable
+ private interface SomeService {
+ void serviceOperation1();
+ }
+
+ private static class SomeServiceImpl implements SomeService {
+
+ public SomeServiceImpl() {
+ }
+
+ // References - interface with @Remotable
+ public void setRri1(ReferenceRemotableInterface rri) {
+ }
+ protected void setRri2(ReferenceRemotableInterface rri) {
+ }
+ public ReferenceRemotableInterface rri3;
+ protected ReferenceRemotableInterface rri4;
+
+ // References - array of interface with @Remotable
+ public void setRria1(ReferenceRemotableInterface[] rri) {
+ }
+ protected void setRria2(ReferenceRemotableInterface[] rri) {
+ }
+ public ReferenceRemotableInterface[] rria3;
+ protected ReferenceRemotableInterface[] rria4;
+
+ // References - parametrized Collection of interface with @Remotable
+ public void setRric1(Collection<ReferenceRemotableInterface> rri) {
+ }
+ protected void setRric2(Collection<ReferenceRemotableInterface> rri) {
+ }
+ public Collection<ReferenceRemotableInterface> rric3;
+ protected Collection<ReferenceRemotableInterface> rric4;
+
+ // Properties - interface with @Service and without @Remotable
+ public void setPnri1(PropertyNonRemotableInterface arg) {
+ }
+ protected void setPnri2(PropertyNonRemotableInterface arg) {
+ }
+ public PropertyNonRemotableInterface pnri3;
+ protected PropertyNonRemotableInterface pnri4;
+
+ // Properties - array of interface with @Service and without @Remotable
+ public void setPnria1(PropertyNonRemotableInterface[] arg) {
+ }
+ protected void setPnria2(PropertyNonRemotableInterface[] arg) {
+ }
+ public PropertyNonRemotableInterface[] pnria3;
+ protected PropertyNonRemotableInterface[] pnria4;
+
+ // Properties - parametrized Collection of interface with @Service and without @Remotable
+ public void setPnric1(Collection<PropertyNonRemotableInterface> arg) {
+ }
+ protected void setPnric2(Collection<PropertyNonRemotableInterface> arg) {
+ }
+ public Collection<PropertyNonRemotableInterface> pnric3;
+ protected Collection<PropertyNonRemotableInterface> pnric4;
+
+ // Properties - Non-parametrized Collection
+ public void setGen1(Collection arg) {
+ }
+ protected void setGen2(Collection arg) {
+ }
+ public Collection gen3;
+ protected Collection gen4;
+
+ public void serviceOperation1() {
+ }
+ }
+
+ private static class PropertyIntTypeOnConstructor {
+ protected int foo;
+
+ public PropertyIntTypeOnConstructor() {
+ }
+
+ public int getFoo() {
+ return foo;
+ }
+ }
+
+ @Remotable
+ private interface PropertyInterface {
+ void setString1(String val);
+ }
+
+ @Remotable
+ 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;
+ }
+
+ }
+
+ @Remotable
+ 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) {
+ // [rfeng] By the SCA specification, this should be classified as property
+ }
+
+ 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) {
+ }
+
+ }
+
+ @WebService
+ private interface SomeWebService {
+ void serviceOperation1();
+ }
+
+ @Service
+ private static class SomeWebServiceImpl implements SomeWebService {
+ public SomeWebServiceImpl() {
+
+ }
+
+ public void serviceOperation1() {
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeutisticExtensibleConstructorTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeutisticExtensibleConstructorTestCase.java
new file mode 100644
index 0000000000..ed0527d3d7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/HeutisticExtensibleConstructorTestCase.java
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Constructor;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.impl.JavaConstructorImpl;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+
+/**
+ * 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 AbstractProcessorTest {
+
+ private org.apache.tuscany.sca.implementation.java.introspect.impl.HeuristicPojoProcessor processor;
+ private JavaImplementationFactory javaImplementationFactory;
+
+ public HeutisticExtensibleConstructorTestCase() {
+ processor = new HeuristicPojoProcessor(new DefaultAssemblyFactory(), new DefaultJavaInterfaceFactory());
+ javaImplementationFactory = new DefaultJavaImplementationFactory();
+ }
+
+ private <T> void visitEnd(Class<T> clazz, JavaImplementation type) throws IntrospectionException {
+ for (Constructor<?> constructor : clazz.getConstructors()) {
+ visitConstructor(constructor, type);
+ }
+ processor.visitEnd(clazz, type);
+ }
+
+ /**
+ * Verifies heuristic processing can be called prior to an extension
+ * annotation processors being called.
+ */
+ public void testBarAnnotationProcessedFirst() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
+ JavaConstructorImpl<Foo> definition = new JavaConstructorImpl<Foo>(ctor);
+ type.setConstructor(definition);
+ Property property = factory.createProperty();
+ property.setName("myBar");
+ definition.getParameters()[0].setName("myBar");
+ type.getProperties().add(property);
+ visitEnd(Foo.class, type);
+ 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 = &quot;foo&quot;) String prop2)
+ * </pre>
+ *
+ * <p/> Heuristic evaluation of
+ * @Property can occur prior to another implementation processor evaluating
+ * @Bar
+ * @throws Exception
+ */
+ public void testBarAnnotationProcessedLast() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ visitEnd(Foo.class, type);
+
+ // now simulate process the bar impl
+ JavaConstructorImpl<?> definition = type.getConstructor();
+ definition.getParameters()[0].setName("myBar");
+ Property property = factory.createProperty();
+ property.setName("myBar");
+ type.getProperties().add(property);
+
+ assertEquals(2, type.getProperties().size());
+ assertEquals("foo", definition.getParameters()[1].getName());
+ }
+
+ /**
+ * 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 {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Constructor<Foo2> ctor = Foo2.class.getConstructor(String.class, String.class, String.class);
+ JavaConstructorImpl<Foo2> definition = new JavaConstructorImpl<Foo2>(ctor);
+ type.setConstructor(definition);
+ // insert placeholder for first param, which would be done by a
+ // processor
+ definition.getParameters()[0].setName("");
+ Property property = factory.createProperty();
+ // Hack to add a property member
+ JavaElementImpl element = new JavaElementImpl("myBar", String.class, null);
+ type.getPropertyMembers().put("myBar", element);
+ property.setName("myBar");
+ definition.getParameters()[1].setName("myBar");
+ type.getProperties().add(property);
+ visitEnd(Foo2.class, type);
+ assertEquals("baz", definition.getParameters()[0].getName());
+ 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/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InitProcessorTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InitProcessorTestCase.java
new file mode 100644
index 0000000000..70c615ca24
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/InitProcessorTestCase.java
@@ -0,0 +1,145 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.osoa.sca.annotations.Init;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InitProcessorTestCase extends TestCase {
+
+ private JavaImplementationFactory javaImplementationFactory;
+
+ public InitProcessorTestCase() {
+ javaImplementationFactory = new DefaultJavaImplementationFactory();
+ }
+
+ public void testInit() throws Exception {
+ InitProcessor processor = new InitProcessor(new DefaultAssemblyFactory());
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Method method = InitProcessorTestCase.Foo.class.getMethod("init");
+ processor.visitMethod(method, type);
+ assertNotNull(type.getInitMethod());
+ }
+
+ public void testBadInit() throws Exception {
+ InitProcessor processor = new InitProcessor(new DefaultAssemblyFactory());
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Method method = InitProcessorTestCase.Bar.class.getMethod("badInit", String.class);
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (IllegalInitException e) {
+ // expected
+ }
+ }
+
+ public void testTwoInit() throws Exception {
+ InitProcessor processor = new InitProcessor(new DefaultAssemblyFactory());
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Method method = InitProcessorTestCase.Bar.class.getMethod("init");
+ Method method2 = InitProcessorTestCase.Bar.class.getMethod("init2");
+ processor.visitMethod(method, type);
+ try {
+ processor.visitMethod(method2, type);
+ fail();
+ } catch (DuplicateInitException e) {
+ // expected
+ }
+ }
+
+ public void testProtectedInit() throws Exception {
+ InitProcessor processor = new InitProcessor(new DefaultAssemblyFactory());
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Method method = InitProcessorTestCase.Bar.class.getDeclaredMethod("protectedInit");
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (IllegalInitException e) {
+ // expected
+ }
+ }
+
+ public void testPrivateInit() throws Exception {
+ InitProcessor processor = new InitProcessor(new DefaultAssemblyFactory());
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Method method = InitProcessorTestCase.Bar.class.getDeclaredMethod("privateInit");
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (IllegalInitException e) {
+ // expected
+ }
+ }
+
+ public void testBadInit2() throws Exception {
+ InitProcessor processor = new InitProcessor(new DefaultAssemblyFactory());
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ Method method = InitProcessorTestCase.Bar.class.getDeclaredMethod("badInit2");
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (IllegalInitException 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) {
+ }
+
+ @Init
+ public String badInit2() {
+ return null;
+ }
+
+ @Init
+ protected void protectedInit() {
+ }
+
+ @Init
+ private void privateInit() {
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JavaClassIntrospectorImplTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JavaClassIntrospectorImplTestCase.java
new file mode 100644
index 0000000000..388a1aae8b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/JavaClassIntrospectorImplTestCase.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.introspect.JavaClassVisitor;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaClassIntrospectorImplTestCase extends TestCase {
+
+ public void testRegister() throws Exception {
+ JavaImplementationFactory factory = new DefaultJavaImplementationFactory();
+ JavaClassVisitor extension = EasyMock.createNiceMock(JavaClassVisitor.class);
+ factory.addClassVisitor(extension);
+ }
+
+ public void testUnegister() throws Exception {
+ JavaImplementationFactory factory = new DefaultJavaImplementationFactory();
+ JavaClassVisitor extension = EasyMock.createNiceMock(JavaClassVisitor.class);
+ factory.addClassVisitor(extension);
+ factory.removeClassVisitor(extension);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testWalk() throws Exception {
+ JavaImplementationFactory factory = new DefaultJavaImplementationFactory();
+ JavaClassVisitor extension = EasyMock.createMock(JavaClassVisitor.class);
+ extension.visitClass(EasyMock.eq(Bar.class), EasyMock.isA(JavaImplementation.class));
+ extension.visitConstructor(EasyMock.isA(Constructor.class), EasyMock.isA(JavaImplementation.class));
+ extension.visitMethod(EasyMock.isA(Method.class), EasyMock.isA(JavaImplementation.class));
+ extension.visitField(EasyMock.isA(Field.class), EasyMock.isA(JavaImplementation.class));
+ extension.visitSuperClass(EasyMock.isA(Class.class), EasyMock.isA(JavaImplementation.class));
+ extension.visitEnd(EasyMock.isA(Class.class), EasyMock.isA(JavaImplementation.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(extension);
+ factory.addClassVisitor(extension);
+ factory.createJavaImplementation(Bar.class);
+ EasyMock.verify(extension);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ private class Baz {
+
+ }
+
+ private class Bar extends Baz {
+
+ protected String bar;
+
+ public Bar() {
+ }
+
+ public void bar() {
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ModelHelper.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ModelHelper.java
new file mode 100644
index 0000000000..aad6b96cf9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ModelHelper.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Contract;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ModelHelper {
+
+ public static Property getProperty(JavaImplementation type, String name) {
+ for (Property prop : type.getProperties()) {
+ if (prop.getName().equals(name)) {
+ return prop;
+ }
+ }
+ return null;
+ }
+
+ public static Reference getReference(JavaImplementation type, String name) {
+ for (Reference ref : type.getReferences()) {
+ if (ref.getName().equals(name)) {
+ return ref;
+ }
+ }
+ return null;
+ }
+
+ public static Service getService(JavaImplementation type, String name) {
+ for (Service svc : type.getServices()) {
+ if (svc.getName().equals(name)) {
+ return svc;
+ }
+ }
+ return null;
+ }
+
+ public static boolean matches(Contract contract, Class<?> type) {
+ Interface interface1 = contract.getInterfaceContract().getInterface();
+ if (interface1 instanceof JavaInterface) {
+ return type == ((JavaInterface)interface1).getJavaClass();
+ } else {
+ return false;
+ }
+ }
+
+ public static ComponentService createService(AssemblyFactory factory,
+ JavaInterfaceFactory javaFactory, Class<?> type) {
+ org.apache.tuscany.sca.assembly.ComponentService ref = factory.createComponentService();
+ ref.setName(type.getSimpleName());
+ JavaInterface i = javaFactory.createJavaInterface();
+ i.setJavaClass(type);
+ JavaInterfaceContract ic = javaFactory.createJavaInterfaceContract();
+ ic.setInterface(i);
+ ref.setInterfaceContract(ic);
+ return ref;
+ }
+
+ public static Reference createReference(AssemblyFactory factory,
+ JavaInterfaceFactory javaFactory, String name, Class<?> type) {
+ org.apache.tuscany.sca.assembly.Reference ref = factory.createReference();
+ ref.setName(name);
+ JavaInterface i = javaFactory.createJavaInterface();
+ i.setJavaClass(type);
+ JavaInterfaceContract ic = javaFactory.createJavaInterfaceContract();
+ ic.setInterface(i);
+ ref.setInterfaceContract(ic);
+ return ref;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java
new file mode 100644
index 0000000000..4a625982b0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PolicyProcessorTestCase.java
@@ -0,0 +1,418 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.ConfiguredOperation;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.assembly.OperationsConfigurator;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.impl.PolicyJavaInterfaceVisitor;
+import org.apache.tuscany.sca.policy.DefaultPolicyFactory;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+import org.osoa.sca.annotations.Requires;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PolicyProcessorTestCase extends TestCase {
+ private ServiceProcessor serviceProcessor;
+ private PolicyProcessor policyProcessor;
+ private PolicyJavaInterfaceVisitor visitor;
+ private JavaImplementation type;
+
+ // This actually is a test for PolicyJavaInterfaceProcessor. It will get
+ // invoked via the call to ImplementationProcessorServiceImpl.createService in
+ // ServiceProcessor. Of course ServiceProcessor class has to be working.
+ public void stestSingleInterfaceWithIntentsOnInterfaceAtInterfaceLevel() throws Exception {
+ serviceProcessor.visitClass(Service1.class, type);
+ visitor.visitInterface((JavaInterface)type.getServices().get(0).getInterfaceContract().getInterface());
+ policyProcessor.visitClass(Service1.class, type);
+ verifyIntents(Service1.class, type);
+ }
+
+ public void stestMultipleInterfacesWithIntentsOnInterfaceAtInterfaceLevel() throws Exception {
+ serviceProcessor.visitClass(Service2.class, type);
+ visitor.visitInterface((JavaInterface)type.getServices().get(0).getInterfaceContract().getInterface());
+ policyProcessor.visitClass(Service2.class, type);
+ verifyIntents(Service2.class, type);
+ }
+
+ public void stestSingleInterfaceWithIntentsOnImplAtClassLevel() throws Exception {
+ serviceProcessor.visitClass(Service3.class, type);
+ visitor.visitInterface((JavaInterface)type.getServices().get(0).getInterfaceContract().getInterface());
+ policyProcessor.visitClass(Service3.class, type);
+ verifyIntents(Service3.class, type);
+ }
+
+ public void stestMultipleInterfacesWithIntentsOnImplAtClassLevel() throws Exception {
+ serviceProcessor.visitClass(Service4.class, type);
+ visitor.visitInterface((JavaInterface)type.getServices().get(0).getInterfaceContract().getInterface());
+ policyProcessor.visitClass(Service4.class, type);
+ verifyIntents(Service4.class, type);
+ }
+
+ public void stestSingleInterfaceWithIntentsOnInterfaceAtMethodLevel() throws Exception {
+ serviceProcessor.visitClass(Service5.class, type);
+ visitor.visitInterface((JavaInterface)type.getServices().get(0).getInterfaceContract().getInterface());
+ policyProcessor.visitClass(Service5.class, type);
+ verifyIntents(Service5.class, type);
+ }
+
+ public void testSingleInterfaceWithIntentsOnServiceAndInterfaceAtImplAndInertfaceAndMethodLevel() throws Exception {
+ serviceProcessor.visitClass(Service6.class, type);
+ visitor.visitInterface((JavaInterface)type.getServices().get(0).getInterfaceContract().getInterface());
+ policyProcessor.visitClass(Service6.class, type);
+ for (Method method : Service6.class.getDeclaredMethods()) {
+ policyProcessor.visitMethod(method, type);
+ }
+ verifyIntents(Service6.class, type);
+ }
+
+ private void verifyIntents(Class serviceImplClass, JavaImplementation type) {
+ if ( !(type instanceof PolicySetAttachPoint) ) {
+ fail("No Intents on the service ");
+ }
+ Requires serviceImplIntentAnnotation = (Requires)serviceImplClass.getAnnotation(Requires.class);
+ if (serviceImplIntentAnnotation != null) {
+ String[] serviceImplIntents = serviceImplIntentAnnotation.value();
+ List<Intent> requiredIntents = ((PolicySetAttachPoint)type).getRequiredIntents();
+ if (serviceImplIntents.length > 0) {
+ if (requiredIntents == null || requiredIntents.size() == 0) {
+ fail("No Intents on the service ");
+ }
+ Map<String, Intent> intentMap = new HashMap<String, Intent>();
+ for (Intent intent : requiredIntents) {
+ intentMap.put(intent.getName().getLocalPart(), intent);
+ }
+ for (String intent : serviceImplIntents) {
+ assertTrue("ComponentType for Service class " + serviceImplClass.getName()
+ + " did not contain Service Implementation intent "
+ + intent, intentMap.containsKey(intent));
+ }
+ }
+ }
+
+ // This should match what was specified on @Service for a Service Implementation
+ // If we use these to get the Service names and we get a null Service
+ // name then it would seem that wrong values were put on the @Service annotation
+ // or the wrong interfaces were specified on the implements list of the class
+ // statement?
+ Map<String, org.apache.tuscany.sca.assembly.Service> serviceMap = new HashMap<String, org.apache.tuscany.sca.assembly.Service>();
+ for (org.apache.tuscany.sca.assembly.Service service: type.getServices()) {
+ serviceMap.put(service.getName(), service);
+ }
+ for (Class interfaceClass : serviceImplClass.getInterfaces()) {
+ Requires interfaceIntentAnnotation = (Requires)interfaceClass.getAnnotation(Requires.class);
+ org.apache.tuscany.sca.assembly.Service service = serviceMap.get(interfaceClass.getSimpleName());
+ if (service == null) {
+ fail("No service defined for interface " + interfaceClass.getSimpleName()
+ + " on Service Implementation "
+ + serviceImplClass.getName());
+ }
+
+ if (interfaceIntentAnnotation != null) {
+ String[] interfaceIntents = interfaceIntentAnnotation.value();
+ List<Intent> requiredIntents = service.getInterfaceContract().getInterface().getRequiredIntents();
+ if (interfaceIntents.length > 0) {
+ if (requiredIntents == null || requiredIntents.size() == 0) {
+ fail("No Intents on the service " + service.getName());
+ }
+ Map<String, Intent> intentMap = new HashMap<String, Intent>();
+ for (Intent intent : requiredIntents) {
+ intentMap.put(intent.getName().getLocalPart(), intent);
+ }
+ for (String intent : interfaceIntents) {
+ assertTrue("Interface " + service.getName()
+ + " did not contain Service Interface intent "
+ + intent, intentMap.containsKey(intent));
+ }
+ }
+ }
+
+ for (Method method : interfaceClass.getDeclaredMethods()) {
+ Requires methodIntentAnnotation = method.getAnnotation(Requires.class);
+
+ // Verify that each of the Intents on each of the Service
+ // Interface Methods exist on their associated operation.
+ if (methodIntentAnnotation != null) {
+ String[] methodIntents = methodIntentAnnotation.value();
+ if (methodIntents.length > 0) {
+ List<Intent> requiredIntents = null;
+ for ( ConfiguredOperation confOp : service.getConfiguredOperations() ) {
+ if ( confOp.getName().equals(method.getName()) &&
+ confOp.getContractName().equals(service.getName()) ) {
+ requiredIntents = confOp.getRequiredIntents();
+ }
+ }
+
+ if (requiredIntents == null || requiredIntents.size() == 0) {
+ fail("No Intents on operation " + method.getName());
+ }
+ for (String intent : methodIntents) {
+ boolean found = false;
+ for (Intent requiredIntent: requiredIntents) {
+ if (requiredIntent.getName().getLocalPart().equals(intent)) {
+ found = true;
+ break;
+ }
+ }
+ assertTrue("Operation " + method.getName()
+ + " did not contain Service Interface method intent "
+ + intent, found);
+ }
+ }
+ }
+ }
+
+ for (Method method : serviceImplClass.getDeclaredMethods()) {
+ Requires methodIntentAnnotation = method.getAnnotation(Requires.class);
+
+ // Verify that each of the Intents on each of the Service
+ // Implementation Methods exist on their associated
+ // operation.
+ if (methodIntentAnnotation != null) {
+ String[] methodIntents = methodIntentAnnotation.value();
+ if (methodIntents.length > 0) {
+ List<Intent> requiredIntents = null;
+ for ( ConfiguredOperation confOp : ((OperationsConfigurator)type).getConfiguredOperations() ) {
+ if ( confOp.getName().equals(method.getName()) ) {
+ requiredIntents = confOp.getRequiredIntents();
+ }
+ }
+
+ if (requiredIntents == null || requiredIntents.size() == 0) {
+ fail("No Intents on operation " + method.getName());
+ }
+
+ for (String intent : methodIntents) {
+ boolean found = false;
+ for (Intent requiredIntent: requiredIntents) {
+ if (requiredIntent.getName().getLocalPart().equals(intent)) {
+ found = true;
+ break;
+ }
+ }
+ assertTrue("Operation " + method.getName()
+ + " did not contain Implementation method intent "
+ + intent, found);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ serviceProcessor = new ServiceProcessor(new DefaultAssemblyFactory(), new DefaultJavaInterfaceFactory());
+ policyProcessor = new PolicyProcessor(new DefaultAssemblyFactory(), new DefaultPolicyFactory());
+ visitor = new PolicyJavaInterfaceVisitor(new DefaultPolicyFactory());
+ JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+ type = javaImplementationFactory.createJavaImplementation();
+ }
+
+ // @Remotable
+ @Requires( {"transaction.global"})
+ private interface Interface1 {
+ int method1();
+
+ int method2();
+
+ int method3();
+
+ int method4();
+ }
+
+ @Service(Interface1.class)
+ private class Service1 implements Interface1 {
+ public int method1() {
+ return 0;
+ }
+
+ public int method2() {
+ return 0;
+ }
+
+ public int method3() {
+ return 0;
+ }
+
+ public int method4() {
+ return 0;
+ }
+ }
+
+ // @Remotable
+ @Requires( {"transaction.local"})
+ private interface Interface2 {
+ int method5();
+
+ int method6();
+ }
+
+ @Service(interfaces = {Interface1.class, Interface2.class})
+ private class Service2 implements Interface1, Interface2 {
+ public int method1() {
+ return 0;
+ }
+
+ public int method2() {
+ return 0;
+ }
+
+ public int method3() {
+ return 0;
+ }
+
+ public int method4() {
+ return 0;
+ }
+
+ public int method5() {
+ return 0;
+ }
+
+ public int method6() {
+ return 0;
+ }
+ }
+
+ // @Remotable
+ private interface Interface3 {
+ int method1();
+
+ int method2();
+
+ int method3();
+
+ int method4();
+ }
+
+ @Service(Interface3.class)
+ @Requires( {"transaction.global"})
+ private class Service3 implements Interface3 {
+ public int method1() {
+ return 0;
+ }
+
+ public int method2() {
+ return 0;
+ }
+
+ public int method3() {
+ return 0;
+ }
+
+ public int method4() {
+ return 0;
+ }
+ }
+
+ // @Remotable
+ private interface Interface4 {
+ int method5();
+
+ int method6();
+ }
+
+ @Service(interfaces = {Interface3.class, Interface4.class})
+ @Requires( {"transaction.local"})
+ private class Service4 implements Interface3, Interface4 {
+ public int method1() {
+ return 0;
+ }
+
+ public int method2() {
+ return 0;
+ }
+
+ public int method3() {
+ return 0;
+ }
+
+ public int method4() {
+ return 0;
+ }
+
+ public int method5() {
+ return 0;
+ }
+
+ public int method6() {
+ return 0;
+ }
+ }
+
+ private interface Interface5 {
+ @Requires( {"transaction.global"})
+ int method1();
+
+ @Requires( {"transaction.local"})
+ int method2();
+ }
+
+ @Service(Interface5.class)
+ private class Service5 implements Interface5 {
+ public int method1() {
+ return 0;
+ }
+
+ public int method2() {
+ return 0;
+ }
+ }
+
+ @Requires( {"transaction.global.Interface6"})
+ private interface Interface6 {
+ @Requires( {"transaction.global.Interface6.method1"})
+ int method1();
+
+ @Requires( {"transaction.local.Interface6.method2"})
+ int method2();
+ }
+
+ @Service(Interface6.class)
+ @Requires( {"transaction.global.Service6"})
+ private class Service6 implements Interface6 {
+ @Requires( {"transaction.global.Service6.method1"})
+ public int method1() {
+ return 0;
+ }
+
+ @Requires( {"transaction.global.Service6.method1"})
+ public int method2() {
+ return 0;
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessorTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessorTestCase.java
new file mode 100644
index 0000000000..8d5e816a08
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/PropertyProcessorTestCase.java
@@ -0,0 +1,212 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.ModelHelper.getProperty;
+
+import java.util.Collection;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.impl.JavaElementImpl;
+import org.osoa.sca.annotations.Property;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PropertyProcessorTestCase extends TestCase {
+
+ JavaImplementation type;
+ PropertyProcessor processor;
+
+ public void testMethodAnnotation() throws Exception {
+ processor.visitMethod(Foo.class.getMethod("setFoo", String.class), type);
+ assertNotNull(getProperty(type, "foo"));
+ }
+
+ public void testMethodRequired() throws Exception {
+ processor.visitMethod(Foo.class.getMethod("setFooRequired", String.class), type);
+ org.apache.tuscany.sca.assembly.Property prop = getProperty(type, "fooRequired");
+ assertNotNull(prop);
+ assertTrue(prop.isMustSupply());
+ }
+
+ public void testMethodName() throws Exception {
+ processor.visitMethod(Foo.class.getMethod("setBarMethod", String.class), type);
+ assertNotNull(getProperty(type, "bar"));
+ }
+
+ public void testFieldAnnotation() throws Exception {
+ processor.visitField(Foo.class.getDeclaredField("baz"), type);
+ assertNotNull(getProperty(type, "baz"));
+ }
+
+ public void testFieldRequired() throws Exception {
+ processor.visitField(Foo.class.getDeclaredField("bazRequired"), type);
+ org.apache.tuscany.sca.assembly.Property prop = getProperty(type, "bazRequired");
+ assertNotNull(prop);
+ assertTrue(prop.isMustSupply());
+ }
+
+ public void testFieldName() throws Exception {
+ processor.visitField(Foo.class.getDeclaredField("bazField"), type);
+ assertNotNull(getProperty(type, "theBaz"));
+ }
+
+ public void testDuplicateFields() throws Exception {
+ processor.visitField(Bar.class.getDeclaredField("dup"), type);
+ try {
+ processor.visitField(Bar.class.getDeclaredField("baz"), type);
+ fail();
+ } catch (DuplicatePropertyException e) {
+ // expected
+ }
+ }
+
+ public void testDuplicateMethods() throws Exception {
+ processor.visitMethod(Bar.class.getMethod("setDupMethod", String.class), type);
+ try {
+ processor.visitMethod(Bar.class.getMethod("setDupSomeMethod", String.class), type);
+ fail();
+ } catch (DuplicatePropertyException e) {
+ // expected
+ }
+ }
+
+ public void testInvalidProperty() throws Exception {
+ try {
+ processor.visitMethod(Bar.class.getMethod("badMethod"), type);
+ fail();
+ } catch (IllegalPropertyException e) {
+ // expected
+ }
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+ type = javaImplementationFactory.createJavaImplementation();
+ processor = new PropertyProcessor(new DefaultAssemblyFactory());
+ }
+
+ 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 setDupMethod(String s) {
+ }
+
+ @Property(name = "dupMethod")
+ public void setDupSomeMethod(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) {
+ }
+
+ }
+
+ private Class<?> getBaseType(JavaElementImpl element) {
+ return JavaIntrospectionHelper.getBaseType(element.getType(), element.getGenericType());
+ }
+
+ public void testMultiplicityCollection() throws Exception {
+ processor.visitField(Multiple.class.getDeclaredField("refs1"), type);
+ org.apache.tuscany.sca.assembly.Property prop = getProperty(type, "refs1");
+ assertNotNull(prop);
+ assertSame(String.class, getBaseType(type.getPropertyMembers().get(prop.getName())));
+ assertTrue(prop.isMany());
+ }
+
+ public void testMultiplicityArray() throws Exception {
+ processor.visitField(Multiple.class.getDeclaredField("refs2"), type);
+ org.apache.tuscany.sca.assembly.Property prop = getProperty(type, "refs2");
+ assertNotNull(prop);
+ assertSame(String.class, getBaseType(type.getPropertyMembers().get(prop.getName())));
+ assertTrue(prop.isMany());
+ }
+
+ public void testMultiplicityArrayMethod() throws Exception {
+ processor.visitMethod(Multiple.class.getMethod("setRefs3", String[].class), type);
+ org.apache.tuscany.sca.assembly.Property prop = getProperty(type, "refs3");
+ assertNotNull(prop);
+ assertSame(String.class, getBaseType(type.getPropertyMembers().get(prop.getName())));
+ assertTrue(prop.isMany());
+ }
+
+ public void testMultiplicityCollectionMethod() throws Exception {
+ processor.visitMethod(Multiple.class.getMethod("setRefs4", Collection.class), type);
+ org.apache.tuscany.sca.assembly.Property prop = getProperty(type, "refs4");
+ assertNotNull(prop);
+ assertSame(String.class, getBaseType(type.getPropertyMembers().get(prop.getName())));
+ assertTrue(prop.isMany());
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessorTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessorTestCase.java
new file mode 100644
index 0000000000..d68b1530f0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ReferenceProcessorTestCase.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.sca.implementation.java.introspect.impl;
+
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.ModelHelper.getReference;
+
+import java.util.Collection;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.assembly.Multiplicity;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.osoa.sca.annotations.Reference;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ReferenceProcessorTestCase extends TestCase {
+
+ private JavaImplementation type;
+ private ReferenceProcessor processor;
+
+ public void testMethodAnnotation() throws Exception {
+ processor.visitMethod(ReferenceProcessorTestCase.Foo.class.getMethod("setFoo", Ref.class), type);
+ org.apache.tuscany.sca.assembly.Reference reference = getReference(type, "foo");
+ assertNotNull(reference);
+ assertEquals(Ref.class, ((JavaInterface)reference.getInterfaceContract().getInterface()).getJavaClass());
+ }
+
+ public void testMethodRequired() throws Exception {
+ processor.visitMethod(ReferenceProcessorTestCase.Foo.class.getMethod("setFooRequired", Ref.class), type);
+ org.apache.tuscany.sca.assembly.Reference ref = getReference(type, "fooRequired");
+ assertNotNull(ref);
+ assertEquals(Multiplicity.ONE_ONE, ref.getMultiplicity());
+ }
+
+ public void testMethodName() throws Exception {
+ processor.visitMethod(ReferenceProcessorTestCase.Foo.class.getMethod("setBarMethod", Ref.class), type);
+ assertNotNull(getReference(type, "bar"));
+ }
+
+ public void testFieldAnnotation() throws Exception {
+ processor.visitField(ReferenceProcessorTestCase.Foo.class.getDeclaredField("baz"), type);
+ org.apache.tuscany.sca.assembly.Reference reference = getReference(type, "baz");
+ assertNotNull(reference);
+ assertEquals(Ref.class, ((JavaInterface)reference.getInterfaceContract().getInterface()).getJavaClass());
+ }
+
+ public void testFieldRequired() throws Exception {
+ processor.visitField(ReferenceProcessorTestCase.Foo.class.getDeclaredField("bazRequired"), type);
+ org.apache.tuscany.sca.assembly.Reference ref = getReference(type, "bazRequired");
+ assertNotNull(ref);
+ assertEquals(Multiplicity.ONE_ONE, ref.getMultiplicity());
+ }
+
+ public void testFieldName() throws Exception {
+ processor.visitField(ReferenceProcessorTestCase.Foo.class.getDeclaredField("bazField"), type);
+ assertNotNull(getReference(type, "theBaz"));
+ }
+
+ public void testDuplicateFields() throws Exception {
+ processor.visitField(ReferenceProcessorTestCase.Bar.class.getDeclaredField("dup"), type);
+ try {
+ processor.visitField(ReferenceProcessorTestCase.Bar.class.getDeclaredField("baz"), type);
+ fail();
+ } catch (DuplicateReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testDuplicateMethods() throws Exception {
+ processor.visitMethod(ReferenceProcessorTestCase.Bar.class.getMethod("setDupMethod", Ref.class), type);
+ try {
+ processor.visitMethod(ReferenceProcessorTestCase.Bar.class.getMethod("setDupSomeMethod", Ref.class), type);
+ fail();
+ } catch (DuplicateReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testInvalidProperty() throws Exception {
+ try {
+ processor.visitMethod(ReferenceProcessorTestCase.Bar.class.getMethod("badMethod"), type);
+ fail();
+ } catch (IllegalReferenceException e) {
+ // expected
+ }
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+ type = javaImplementationFactory.createJavaImplementation();
+ processor = new ReferenceProcessor(new DefaultAssemblyFactory(), new DefaultJavaInterfaceFactory());
+ }
+
+ 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 setDupMethod(Ref s) {
+ }
+
+ @Reference(name = "dupMethod")
+ public void setDupSomeMethod(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);
+ org.apache.tuscany.sca.assembly.Reference ref = getReference(type, "refs1");
+ assertNotNull(ref);
+ assertSame(Ref.class, ((JavaInterface)ref.getInterfaceContract().getInterface()).getJavaClass());
+ assertEquals(Multiplicity.ONE_N, ref.getMultiplicity());
+ // assertEquals(Multiplicity.ONE_ONE, ref.getMultiplicity());
+ }
+
+ public void testMultiplicityTo0ToN() throws Exception {
+ processor.visitField(Multiple.class.getDeclaredField("refs2"), type);
+ org.apache.tuscany.sca.assembly.Reference ref = getReference(type, "refs2");
+ assertNotNull(ref);
+ assertSame(Ref.class, ((JavaInterface)ref.getInterfaceContract().getInterface()).getJavaClass());
+ assertEquals(Multiplicity.ZERO_N, ref.getMultiplicity());
+ // assertFalse(ref.isMustSupply());
+ }
+
+ public void testMultiplicity1ToNMethod() throws Exception {
+ processor.visitMethod(Multiple.class.getMethod("setRefs3", Ref[].class), type);
+ org.apache.tuscany.sca.assembly.Reference ref = getReference(type, "refs3");
+ assertNotNull(ref);
+ assertSame(Ref.class, ((JavaInterface)ref.getInterfaceContract().getInterface()).getJavaClass());
+ assertEquals(Multiplicity.ONE_N, ref.getMultiplicity());
+ // assertEquals(Multiplicity.ONE_ONE, ref.getMultiplicity());
+ }
+
+ public void testMultiplicity0ToNMethod() throws Exception {
+ processor.visitMethod(Multiple.class.getMethod("setRefs4", Collection.class), type);
+ org.apache.tuscany.sca.assembly.Reference ref = getReference(type, "refs4");
+ assertNotNull(ref);
+ assertSame(Ref.class, ((JavaInterface)ref.getInterfaceContract().getInterface()).getJavaClass());
+ assertEquals(Multiplicity.ZERO_N, ref.getMultiplicity());
+ // assertFalse(ref.isMustSupply());
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessorTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessorTestCase.java
new file mode 100644
index 0000000000..7bb8e15696
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ResourceProcessorTestCase.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.impl.JavaResourceImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ResourceProcessorTestCase extends TestCase {
+
+ JavaImplementation type;
+ ResourceProcessor processor = new ResourceProcessor(new DefaultAssemblyFactory());
+
+ public void testVisitField() throws Exception {
+ Field field = Foo.class.getDeclaredField("bar");
+ processor.visitField(field, type);
+ JavaResourceImpl resource = type.getResources().get("bar");
+ assertFalse(resource.isOptional());
+ assertNull(resource.getMappedName());
+ assertEquals(field.getType(), resource.getElement().getType());
+ }
+
+ public void testVisitMethod() throws Exception {
+ Method method = Foo.class.getMethod("setBar", Bar.class);
+ processor.visitMethod(method, type);
+ JavaResourceImpl resource = type.getResources().get("bar");
+ assertFalse(resource.isOptional());
+ assertNull(resource.getMappedName());
+ assertEquals(method.getParameterTypes()[0], resource.getElement().getType());
+ }
+
+ public void testVisitNamedMethod() throws Exception {
+ Method method = Foo.class.getMethod("setBar2", Bar.class);
+ processor.visitMethod(method, type);
+ JavaResourceImpl 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);
+ fail();
+ } catch (IllegalResourceException e) {
+ // expected
+ }
+ }
+
+ public void testDuplicateResources() throws Exception {
+ Field field = Foo.class.getDeclaredField("bar");
+ processor.visitField(field, type);
+ try {
+ processor.visitField(field, type);
+ fail();
+ } catch (DuplicateResourceException e) {
+ //expected
+ }
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+ type = javaImplementationFactory.createJavaImplementation();
+ }
+
+ private class Foo {
+
+ @org.apache.tuscany.sca.implementation.java.introspect.impl.Resource
+ protected Bar bar;
+
+ @org.apache.tuscany.sca.implementation.java.introspect.impl.Resource(optional = true)
+ protected Bar barNotRequired;
+
+ @org.apache.tuscany.sca.implementation.java.introspect.impl.Resource
+ public void setBar(Bar bar) {
+ }
+
+ @org.apache.tuscany.sca.implementation.java.introspect.impl.Resource(name = "someName", mappedName = "mapped")
+ public void setBar2(Bar bar) {
+ }
+
+ @org.apache.tuscany.sca.implementation.java.introspect.impl.Resource
+ public void setBad() {
+ }
+
+ }
+
+ private interface Bar {
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ScopeProcessorTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ScopeProcessorTestCase.java
new file mode 100644
index 0000000000..d7de4e522e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ScopeProcessorTestCase.java
@@ -0,0 +1,113 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.impl.JavaScopeImpl;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ScopeProcessorTestCase extends TestCase {
+
+ Component parent;
+ private JavaImplementationFactory javaImplementationFactory;
+
+ public void testCompositeScope() throws IntrospectionException {
+ ScopeProcessor processor = new ScopeProcessor(new DefaultAssemblyFactory());
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+
+ processor.visitClass(Composite.class, type);
+ assertEquals(JavaScopeImpl.COMPOSITE, type.getJavaScope());
+ }
+
+ public void testSessionScope() throws IntrospectionException {
+ ScopeProcessor processor = new ScopeProcessor(new DefaultAssemblyFactory());
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(Session.class, type);
+ assertEquals(JavaScopeImpl.SESSION, type.getJavaScope());
+ }
+
+ public void testConversationalScope() throws IntrospectionException {
+ ScopeProcessor processor = new ScopeProcessor(new DefaultAssemblyFactory());
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(Conversation.class, type);
+ assertEquals(JavaScopeImpl.CONVERSATION, type.getJavaScope());
+ }
+
+ public void testRequestScope() throws IntrospectionException {
+ ScopeProcessor processor = new ScopeProcessor(new DefaultAssemblyFactory());
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(Request.class, type);
+ assertEquals(JavaScopeImpl.REQUEST, type.getJavaScope());
+ }
+
+ public void testStatelessScope() throws IntrospectionException {
+ ScopeProcessor processor = new ScopeProcessor(new DefaultAssemblyFactory());
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(Stateless.class, type);
+ assertEquals(JavaScopeImpl.STATELESS, type.getJavaScope());
+ }
+
+ public void testNoScope() throws IntrospectionException {
+ ScopeProcessor processor = new ScopeProcessor(new DefaultAssemblyFactory());
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(None.class, type);
+ assertEquals(JavaScopeImpl.STATELESS, type.getJavaScope());
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ javaImplementationFactory = new DefaultJavaImplementationFactory();
+ 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("STATELESS")
+ private class Stateless {
+ }
+
+ private class None {
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceCallbackTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceCallbackTestCase.java
new file mode 100644
index 0000000000..10f0500e4d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceCallbackTestCase.java
@@ -0,0 +1,183 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import static org.apache.tuscany.sca.implementation.java.introspect.impl.ModelHelper.getService;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.IntrospectionException;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.interfacedef.InvalidCallbackException;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ServiceCallbackTestCase extends TestCase {
+ private ServiceProcessor processor;
+ private JavaImplementationFactory javaImplementationFactory;
+
+ @Override
+ protected void setUp() throws Exception {
+ processor = new ServiceProcessor(new DefaultAssemblyFactory(), new DefaultJavaInterfaceFactory());
+ javaImplementationFactory = new DefaultJavaImplementationFactory();
+ }
+
+ public void testMethodCallbackInterface() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(FooImpl.class, type);
+ org.apache.tuscany.sca.assembly.Service service = getService(type, Foo.class.getSimpleName());
+ assertNotNull(service);
+ Method method = FooImpl.class.getMethod("setCallback", FooCallback.class);
+ processor.visitMethod(method, type);
+ assertEquals(method, type.getCallbackMembers().get(FooCallback.class.getName()).iterator().next().getAnchor());
+ }
+
+ public void testFieldCallbackInterface() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(FooImpl.class, type);
+ org.apache.tuscany.sca.assembly.Service service = getService(type, Foo.class.getSimpleName());
+ assertNotNull(service);
+ Field field = FooImpl.class.getDeclaredField("callback");
+ processor.visitField(field, type);
+ assertEquals(field, type.getCallbackMembers().get(FooCallback.class.getName()).iterator().next().getAnchor());
+ }
+
+ public void testFieldCallbackInterface1() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(FooImpl1.class, type);
+ org.apache.tuscany.sca.assembly.Service service = getService(type, Foo.class.getSimpleName());
+ assertNotNull(service);
+ Field field1 = FooImpl1.class.getDeclaredField("callbackRef");
+ processor.visitField(field1, type);
+ assertEquals(field1, type.getCallbackMembers().get(FooCallback.class.getName()).iterator().next().getAnchor());
+
+ }
+
+ public void testMethodDoesNotMatchCallback() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(BadBarImpl.class, type);
+ Method method = BadBarImpl.class.getMethod("setWrongInterfaceCallback", String.class);
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (IllegalCallbackReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testNoParamCallback() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(BadBarImpl.class, type);
+ Method method = BadBarImpl.class.getMethod("setNoParamCallback");
+ try {
+ processor.visitMethod(method, type);
+ fail();
+ } catch (IllegalCallbackReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testFieldDoesNotMatchCallback() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ processor.visitClass(BadBarImpl.class, type);
+ Field field = BadBarImpl.class.getDeclaredField("wrongInterfaceCallback");
+ try {
+ processor.visitField(field, type);
+ fail();
+ } catch (IllegalCallbackReferenceException e) {
+ // expected
+ }
+ }
+
+ public void testBadCallbackInterfaceAnnotation() throws Exception {
+ JavaImplementation type = javaImplementationFactory.createJavaImplementation();
+ try {
+ processor.visitClass(BadFooImpl.class, type);
+ fail();
+ } catch (IntrospectionException e) {
+ // expected
+ assertTrue(e.getCause() instanceof InvalidCallbackException);
+ }
+ }
+
+ @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) {
+
+ }
+ }
+
+ @Service(Foo.class)
+ private static class FooImpl1 implements Foo {
+ @Callback
+ protected CallableReference<FooCallback> callbackRef;
+ }
+
+ 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/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessorTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessorTestCase.java
new file mode 100644
index 0000000000..aea90aa6eb
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-java/src/test/java/org/apache/tuscany/sca/implementation/java/introspect/impl/ServiceProcessorTestCase.java
@@ -0,0 +1,158 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.java.introspect.impl;
+
+import javax.jws.WebService;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.implementation.java.DefaultJavaImplementationFactory;
+import org.apache.tuscany.sca.implementation.java.JavaImplementation;
+import org.apache.tuscany.sca.implementation.java.JavaImplementationFactory;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.osoa.sca.annotations.Callback;
+import org.osoa.sca.annotations.Remotable;
+import org.osoa.sca.annotations.Service;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ServiceProcessorTestCase extends TestCase {
+ private ServiceProcessor processor;
+ private JavaImplementation type;
+
+ public void testMultipleInterfaces() throws Exception {
+ processor.visitClass(FooMultiple.class, type);
+ assertEquals(2, type.getServices().size());
+ org.apache.tuscany.sca.assembly.Service service = ModelHelper.getService(type, Baz.class.getSimpleName());
+ assertEquals(Baz.class, ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass());
+ assertEquals(Bar.class, ((JavaInterface)service.getInterfaceContract().getCallbackInterface()).getJavaClass());
+ assertNotNull(ModelHelper.getService(type, Bar.class.getSimpleName()));
+ }
+
+ public void testSingleInterfaces() throws Exception {
+ processor.visitClass(FooSingle.class, type);
+ assertEquals(1, type.getServices().size());
+ assertNotNull(ModelHelper.getService(type, Baz.class.getSimpleName()));
+ }
+
+ public void testMultipleNoService() throws Exception {
+ processor.visitClass(FooMultipleNoService.class, type);
+ assertEquals(0, type.getServices().size());
+ }
+
+ /**
+ * Verifies a service with a callback annotation is recognized
+ */
+ public void testMultipleWithCallbackAnnotation() throws Exception {
+ processor.visitClass(FooMultipleWithCalback.class, type);
+ assertEquals(1, type.getServices().size());
+ }
+
+
+ public void testMultipleWithWebServiceAnnotation() throws Exception {
+ processor.visitClass(FooMultipleWithWebService.class, type);
+ assertEquals(2, type.getServices().size());
+ }
+
+ public void testRemotableNoService() throws Exception {
+ processor.visitClass(FooRemotableNoService.class, type);
+ assertEquals(1, type.getServices().size());
+ org.apache.tuscany.sca.assembly.Service service = ModelHelper.getService(type, BazRemotable.class.getSimpleName());
+ assertEquals(BazRemotable.class, ((JavaInterface)service.getInterfaceContract().getInterface()).getJavaClass());
+ }
+
+ public void testNonInterface() throws Exception {
+ processor.visitClass(FooServiceUsingClassImpl.class, type);
+ }
+
+ public void testNoInterfaces() throws Exception {
+ try {
+ processor.visitClass(BadDefinition.class, type);
+ } catch (IllegalServiceDefinitionException e) {
+ //not expected
+ fail();
+ }
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ processor = new ServiceProcessor(new DefaultAssemblyFactory(), new DefaultJavaInterfaceFactory());
+ JavaImplementationFactory javaImplementationFactory = new DefaultJavaImplementationFactory();
+ type = javaImplementationFactory.createJavaImplementation();
+ }
+
+ @Callback(Bar.class)
+ private interface Baz {
+ }
+
+ private interface Bar {
+ }
+
+ private interface Bar2 {
+ }
+
+ @WebService
+ private interface Bar3 {
+ }
+
+ @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 FooMultipleWithWebService implements BazRemotable, Bar3 {
+ }
+
+ private class FooRemotableNoService implements BazRemotable, Bar {
+
+ }
+
+ @Service(FooSingle.class)
+ private class FooServiceUsingClassImpl extends FooSingle {
+
+ }
+
+
+ @Service()
+ private class BadDefinition extends FooSingle {
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/LICENSE b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/META-INF/README b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/NOTICE b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/NOTICE
new file mode 100644
index 0000000000..94481d6cfa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2007 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/pom.xml b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/pom.xml
new file mode 100644
index 0000000000..bc4f0ae7bf
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/pom.xml
@@ -0,0 +1,103 @@
+<?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.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>tuscany-implementation-node-runtime</artifactId>
+ <name>Apache Tuscany SCA Node Implementation Extension</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-implementation-node</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core-spi</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-node-api</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-node-launcher</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-host-http</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-node-impl</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version> <!-- to keep compatible with older servlet containers -->
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.implementation.node.runtime</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.implementation.node*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationDaemonBootstrap.java b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationDaemonBootstrap.java
new file mode 100644
index 0000000000..8de2a3a3f9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationDaemonBootstrap.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.node.launcher;
+
+import org.apache.tuscany.sca.node.SCANode;
+import org.apache.tuscany.sca.node.SCANodeFactory;
+
+/**
+ * Bootstrap class for the SCA node daemon.
+ *
+ * @version $Rev$ $Date$
+ */
+public class NodeImplementationDaemonBootstrap {
+ private SCANode node;
+
+ /**
+ * A node wrappering an instance of a node daemon.
+ */
+ public static class NodeFacade implements SCANode {
+ private ClassLoader threadContextClassLoader;
+ private ClassLoader runtimeClassLoader;
+ private SCANode daemon;
+
+ private NodeFacade() {
+ runtimeClassLoader = Thread.currentThread().getContextClassLoader();
+ }
+
+ public void start() {
+ threadContextClassLoader = Thread.currentThread().getContextClassLoader();
+ boolean started = false;
+ try {
+ Thread.currentThread().setContextClassLoader(runtimeClassLoader);
+ SCANodeFactory factory = SCANodeFactory.newInstance();
+ daemon = factory.createSCANodeFromClassLoader("NodeDaemon.composite", threadContextClassLoader);
+ started = true;
+ } finally {
+ if (!started) {
+ Thread.currentThread().setContextClassLoader(threadContextClassLoader);
+ }
+ }
+ }
+
+ public void stop() {
+ try {
+ Thread.currentThread().setContextClassLoader(runtimeClassLoader);
+ daemon.stop();
+ } finally {
+ Thread.currentThread().setContextClassLoader(threadContextClassLoader);
+ }
+ }
+ }
+
+ /**
+ * Constructs a new daemon bootstrap.
+ */
+ public NodeImplementationDaemonBootstrap() throws Exception {
+ node = new NodeFacade();
+ }
+
+ /**
+ * Returns the node representing the daemon.
+ * @return
+ */
+ public SCANode getNode() {
+ return node;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncherBootstrap.java b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncherBootstrap.java
new file mode 100644
index 0000000000..0264574fb9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncherBootstrap.java
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.node.launcher;
+
+import org.apache.tuscany.sca.node.SCAClient;
+import org.apache.tuscany.sca.node.SCAContribution;
+import org.apache.tuscany.sca.node.SCANode;
+import org.apache.tuscany.sca.node.SCANodeFactory;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ServiceReference;
+
+/**
+ * Bootstrap class for standalone SCA nodes.
+ *
+ * @version $Rev$ $Date$
+ */
+public class NodeImplementationLauncherBootstrap {
+
+ private SCANode node;
+
+ /**
+ * A node facade.
+ */
+ public static class NodeFacade implements SCANode, SCAClient {
+ private ClassLoader threadContextClassLoader;
+ private ClassLoader runtimeClassLoader;
+ private SCANode delegate;
+
+ private NodeFacade(SCANode delegate) {
+ runtimeClassLoader = Thread.currentThread().getContextClassLoader();
+ this.delegate = delegate;
+ }
+
+ public void start() {
+ threadContextClassLoader = Thread.currentThread().getContextClassLoader();
+ boolean started = false;
+ try {
+ Thread.currentThread().setContextClassLoader(runtimeClassLoader);
+ delegate.start();
+ started = true;
+ } finally {
+ if (!started) {
+ Thread.currentThread().setContextClassLoader(threadContextClassLoader);
+ }
+ }
+ }
+
+ public void stop() {
+ try {
+ Thread.currentThread().setContextClassLoader(runtimeClassLoader);
+ delegate.stop();
+ } finally {
+ Thread.currentThread().setContextClassLoader(threadContextClassLoader);
+ }
+ }
+
+ public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+ return (R)((SCAClient)delegate).cast(target);
+ }
+
+ public <B> B getService(Class<B> businessInterface, String serviceName) {
+ return (B)((SCAClient)delegate).getService(businessInterface, serviceName);
+ }
+
+ public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String referenceName) {
+ return (ServiceReference<B>)((SCAClient)delegate).getServiceReference(businessInterface, referenceName);
+ }
+ }
+
+ /**
+ * Bootstrap a new SCA node.
+ *
+ * @param configurationURI
+ */
+ public NodeImplementationLauncherBootstrap(String configurationURI) throws Exception {
+ SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
+ node = new NodeFacade(nodeFactory.createSCANodeFromURL(configurationURI));
+ }
+
+ /**
+ * Bootstrap a new SCA node.
+ *
+ * @param configurationURI
+ * @param contributionClassLoader
+ */
+ public NodeImplementationLauncherBootstrap(String compositeURI, ClassLoader contributionClassLoader) throws Exception {
+ SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
+ node = new NodeFacade(nodeFactory.createSCANodeFromClassLoader(compositeURI, contributionClassLoader));
+ }
+
+ /**
+ * Bootstrap a new SCA node.
+ *
+ * @param compositeURI
+ * @param uris
+ * @param locations
+ */
+ public NodeImplementationLauncherBootstrap(String compositeURI, String[] uris, String[] locations) throws Exception {
+ SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
+ SCAContribution[] contributions = new SCAContribution[uris.length];
+ for (int i = 0; i < uris.length; i++) {
+ contributions[i] = new SCAContribution(uris[i], locations[i]);
+ }
+ node = new NodeFacade(nodeFactory.createSCANode(compositeURI, contributions));
+ }
+
+ /**
+ * Bootstrap a new SCA node.
+ *
+ * @param compositeURI
+ * @param uris
+ * @param locations
+ */
+ public NodeImplementationLauncherBootstrap(String compositeURI, String compositeContent, String[] uris, String[] locations) throws Exception {
+ SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
+ SCAContribution[] contributions = new SCAContribution[uris.length];
+ for (int i = 0; i < uris.length; i++) {
+ contributions[i] = new SCAContribution(uris[i], locations[i]);
+ }
+ node = new NodeFacade(nodeFactory.createSCANode(compositeURI, compositeContent, contributions));
+ }
+
+ /**
+ * Returns the SCA node.
+ *
+ * @return
+ */
+ public SCANode getNode() {
+ return node;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncherUtil.java b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncherUtil.java
new file mode 100644
index 0000000000..62a822a85e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/launcher/NodeImplementationLauncherUtil.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.node.launcher;
+
+/**
+ * Utility methods for node implementation launchers.
+ *
+ * @version $Rev$ $Date$
+ */
+public class NodeImplementationLauncherUtil {
+
+ private static final String TUSCANY_DOMAIN = "TUSCANY_DOMAIN";
+ private static final String DEFAULT_DOMAIN = "http://localhost:9990";
+
+ /**
+ * Determine the URI of a node configuration. The domain URI can be configured
+ * using a TUSCANY_DOMAIN system property or environment variable.
+ *
+ * @param nodeName
+ * @return
+ */
+ public static String nodeConfigurationURI(String nodeName) {
+ String domain = System.getProperty(TUSCANY_DOMAIN);
+ if (domain == null || domain.length() == 0) {
+ domain = System.getenv(TUSCANY_DOMAIN);
+ }
+ if (domain == null || domain.length() ==0) {
+ domain = DEFAULT_DOMAIN;
+ }
+ String nodeConfiguration = domain + "/node-config/" + nodeName;
+ return nodeConfiguration;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/provider/NodeImplementationInvoker.java b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/provider/NodeImplementationInvoker.java
new file mode 100644
index 0000000000..5895a8614d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/provider/NodeImplementationInvoker.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.node.provider;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+
+/**
+ * Implements an invoker for node component implementations.
+ *
+ * @version $Rev$ $Date$
+ */
+class NodeImplementationInvoker implements Invoker {
+ private Composite composite;
+
+ NodeImplementationInvoker(Composite composite) {
+ this.composite = composite;
+ }
+
+ public Message invoke(Message msg) {
+ //FIXME Implement later
+ msg.setBody(composite);
+ return msg;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/provider/NodeImplementationProvider.java b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/provider/NodeImplementationProvider.java
new file mode 100644
index 0000000000..6cdb18938e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/provider/NodeImplementationProvider.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.node.provider;
+
+import org.apache.tuscany.sca.implementation.node.NodeImplementation;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+/**
+ * An implementation provider for node component implementations.
+ *
+ * @version $Rev$ $Date$
+ */
+class NodeImplementationProvider implements ImplementationProvider {
+
+ private NodeImplementation implementation;
+
+ /**
+ * Constructs a new node implementation provider.
+ *
+ * @param component
+ * @param implementation
+ */
+ NodeImplementationProvider(RuntimeComponent component, NodeImplementation implementation) {
+ this.implementation = implementation;
+ }
+
+ public Invoker createInvoker(RuntimeComponentService service, Operation operation) {
+ NodeImplementationInvoker invoker = new NodeImplementationInvoker(implementation.getComposite());
+ return invoker;
+ }
+
+ public boolean supportsOneWayInvocation() {
+ return false;
+ }
+
+ public void start() {
+ }
+
+ public void stop() {
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/provider/NodeImplementationProviderFactory.java b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/provider/NodeImplementationProviderFactory.java
new file mode 100644
index 0000000000..e2a3e4df92
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/provider/NodeImplementationProviderFactory.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.node.provider;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.implementation.node.NodeImplementation;
+import org.apache.tuscany.sca.provider.ImplementationProvider;
+import org.apache.tuscany.sca.provider.ImplementationProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+
+/**
+ * Factory for node component implementation providers.
+ *
+ * @version $Rev$ $Date$
+ */
+public class NodeImplementationProviderFactory implements ImplementationProviderFactory<NodeImplementation> {
+
+ /**
+ * Constructs a new factory.
+ *
+ * @param extensionPoints
+ */
+ public NodeImplementationProviderFactory(ExtensionPointRegistry extensionPoints) {
+ }
+
+ public ImplementationProvider createImplementationProvider(RuntimeComponent component, NodeImplementation implementation) {
+ return new NodeImplementationProvider(component, implementation);
+ }
+
+ public Class<NodeImplementation> getModelType() {
+ return NodeImplementation.class;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppRequestDispatcher.java b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppRequestDispatcher.java
new file mode 100644
index 0000000000..f6a601a3cd
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppRequestDispatcher.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.node.webapp;
+
+import java.io.IOException;
+import java.util.StringTokenizer;
+
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
+
+/**
+ * A Servlet request dispatcher that can be used to delegate requests to a
+ * Serlvet registered with the Webapp Servlet host.
+ *
+ * @version $Rev$ $Date$
+ */
+class NodeWebAppRequestDispatcher implements RequestDispatcher {
+ private String servletPath;
+ private Servlet servlet;
+
+ /**
+ * Constructs a new request dispatcher.
+ *
+ * @param mapping
+ * @param servlet
+ */
+ public NodeWebAppRequestDispatcher(String mapping, Servlet servlet) {
+ if (mapping.endsWith("*")) {
+ mapping = mapping.substring(0, mapping.length()-1);
+ }
+ if (mapping.endsWith("/")) {
+ mapping = mapping.substring(0, mapping.length()-1);
+ }
+ this.servletPath = mapping;
+ this.servlet = servlet;
+ }
+
+ /**
+ * Returns a request wrapper which will return the correct Servlet path
+ * and path info.
+ *
+ * @param request
+ * @return
+ */
+ private HttpServletRequest createRequestWrapper(ServletRequest request) {
+ HttpServletRequest requestWrapper = new HttpServletRequestWrapper((HttpServletRequest)request) {
+
+ @Override
+ public String getServletPath() {
+ return servletPath;
+ }
+
+ @Override
+ public String getPathInfo() {
+ String path = super.getServletPath();
+ if (path.length() == 0) {
+ path = super.getPathInfo();
+ }
+
+ // TODO: another context path hack, revisit when context path is sorted out
+ path = fiddlePath(path, servletPath);
+
+ return path;
+ }
+ };
+ return requestWrapper;
+ }
+
+ /**
+ * Remove any path suffix thats part of the Servlet context path.
+ *
+ * @param path
+ * @param servletPath
+ */
+ private static String fiddlePath(String path, String servletPath) {
+ StringTokenizer st = new StringTokenizer(path, "/");
+ String root = "";
+ while (st.hasMoreTokens()){
+ String s = st.nextToken();
+ if (servletPath.endsWith((root + "/" + s))) {
+ root += "/" + s;
+ } else {
+ break;
+ }
+ }
+ String fiddlePath = path.substring(root.length());
+ return fiddlePath;
+ }
+
+ public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException {
+ servlet.service(createRequestWrapper(request), response);
+ }
+
+ public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException {
+ servlet.service(createRequestWrapper(request), response);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppServletHost.java b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppServletHost.java
new file mode 100644
index 0000000000..5a50f87d4c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/java/org/apache/tuscany/sca/implementation/node/webapp/NodeWebAppServletHost.java
@@ -0,0 +1,392 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.node.webapp;
+
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.net.InetAddress;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.net.UnknownHostException;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Logger;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterConfig;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.host.http.ServletHost;
+import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint;
+import org.apache.tuscany.sca.host.http.ServletMappingException;
+import org.apache.tuscany.sca.implementation.node.launcher.NodeImplementationLauncherUtil;
+import org.apache.tuscany.sca.node.SCAClient;
+import org.apache.tuscany.sca.node.SCANode;
+import org.apache.tuscany.sca.node.SCANodeFactory;
+
+/**
+ * ServletHost implementation for use in a Webapp Node environment.
+ *
+ * @version $Rev$ $Date$
+ */
+public class NodeWebAppServletHost implements ServletHost, Filter {
+ private static final Logger logger = Logger.getLogger(NodeWebAppServletHost.class.getName());
+
+ private static final NodeWebAppServletHost servletHost = new NodeWebAppServletHost();
+
+ private Map<String, Servlet> servlets = new HashMap<String, Servlet>();
+ private SCANode node;
+
+ private String contextPath = "/";
+ private int defaultPort = 8080;
+
+ /**
+ * Constructs a new NodeWebAppServletHost.
+ */
+ private NodeWebAppServletHost() {
+ }
+
+ /**
+ * Returns the Servlet host for the current Web app.
+ *
+ * @return
+ */
+ public static NodeWebAppServletHost servletHost() {
+ return servletHost;
+ }
+
+ /**
+ * Initialize the Servlet host.
+ *
+ * @param filterConfig
+ * @throws ServletException
+ */
+ public void init(final FilterConfig filterConfig) throws ServletException {
+
+ // Create a Servlet config wrapping the given filter config
+ ServletConfig servletConfig = servletConfig(filterConfig);
+
+ // Get the Servlet context
+ ServletContext servletContext = servletConfig.getServletContext();
+
+ // Initialize the context path
+ contextPath = contextPath(servletContext);
+
+ // Derive the node name from the Webapp context path
+ String nodeName = contextPath;
+ if (nodeName.startsWith("/")) {
+ nodeName = nodeName.substring(1);
+ }
+ if (nodeName.endsWith("/")) {
+ nodeName = nodeName.substring(0, nodeName.length() - 1);
+ }
+
+ // Determine the node configuration URI
+ String nodeConfiguration = NodeImplementationLauncherUtil.nodeConfigurationURI(nodeName);
+
+ // Create the SCA node
+ SCANodeFactory nodeFactory = SCANodeFactory.newInstance();
+ node = nodeFactory.createSCANodeFromURL(nodeConfiguration);
+
+ // Register the Servlet host
+ ServletHostExtensionPoint servletHosts = servletHosts(node);
+ servletHosts.getServletHosts().clear();
+ servletHosts.addServletHost(servletHost);
+
+ // Save the node in the Servlet context
+ servletContext.setAttribute(SCAClient.class.getName(), node);
+
+ // Start the node
+ node.start();
+
+ // Initialize the registered Servlets
+ for (Servlet servlet : servlets.values()) {
+ servlet.init(servletConfig);
+ }
+ }
+
+ public void addServletMapping(String suri, Servlet servlet) throws ServletMappingException {
+ URI pathURI = URI.create(suri);
+
+ // Make sure that the path starts with a /
+ suri = pathURI.getPath();
+ if (!suri.startsWith("/")) {
+ suri = '/' + suri;
+ }
+
+ if (!suri.startsWith(contextPath)) {
+ suri = contextPath + suri;
+ }
+
+ // In a webapp just use the given path and ignore the host and port
+ // as they are fixed by the Web container
+ servlets.put(suri, servlet);
+
+ logger.info("Added Servlet mapping: " + suri);
+ }
+
+ public Servlet removeServletMapping(String suri) throws ServletMappingException {
+ URI pathURI = URI.create(suri);
+
+ // Make sure that the path starts with a /
+ suri = pathURI.getPath();
+ if (!suri.startsWith("/")) {
+ suri = '/' + suri;
+ }
+
+ if (!suri.startsWith(contextPath)) {
+ suri = contextPath + suri;
+ }
+
+ // In a webapp just use the given path and ignore the host and port
+ // as they are fixed by the Web container
+ return servlets.remove(suri);
+ }
+
+ public Servlet getServletMapping(String suri) throws ServletMappingException {
+ if (!suri.startsWith("/")) {
+ suri = '/' + suri;
+ }
+
+ if (!suri.startsWith(contextPath)) {
+ suri = contextPath + suri;
+ }
+
+ // Get the Servlet mapped to the given path
+ Servlet servlet = servlets.get(suri);
+ return servlet;
+ }
+
+ public URL getURLMapping(String suri) throws ServletMappingException {
+ URI uri = URI.create(suri);
+
+ // Get the URI scheme and port
+ String scheme = uri.getScheme();
+ if (scheme == null) {
+ scheme = "http";
+ }
+ int portNumber = uri.getPort();
+ if (portNumber == -1) {
+ portNumber = defaultPort;
+ }
+
+ // Get the host
+ String host;
+ try {
+ host = InetAddress.getLocalHost().getHostName();
+ } catch (UnknownHostException e) {
+ host = "localhost";
+ }
+
+ // Construct the URL
+ String path = uri.getPath();
+ if (!path.startsWith("/")) {
+ path = '/' + path;
+ }
+
+ if (contextPath != null && !path.startsWith(contextPath)) {
+ path = contextPath + path;
+ }
+
+ URL url;
+ try {
+ url = new URL(scheme, host, portNumber, path);
+ } catch (MalformedURLException e) {
+ throw new ServletMappingException(e);
+ }
+ return url;
+ }
+
+ public RequestDispatcher getRequestDispatcher(String suri) throws ServletMappingException {
+
+ // Make sure that the path starts with a /
+ if (!suri.startsWith("/")) {
+ suri = '/' + suri;
+ }
+
+ suri = contextPath + suri;
+
+ // Get the Servlet mapped to the given path
+ Servlet servlet = servlets.get(suri);
+ if (servlet != null) {
+ return new NodeWebAppRequestDispatcher(suri, servlet);
+ }
+
+ for (Map.Entry<String, Servlet> entry : servlets.entrySet()) {
+ String servletPath = entry.getKey();
+ if (servletPath.endsWith("*")) {
+ servletPath = servletPath.substring(0, servletPath.length() - 1);
+ if (suri.startsWith(servletPath)) {
+ return new NodeWebAppRequestDispatcher(entry.getKey(), entry.getValue());
+ } else {
+ if ((suri + "/").startsWith(servletPath)) {
+ return new NodeWebAppRequestDispatcher(entry.getKey(), entry.getValue());
+ }
+ }
+ }
+ }
+
+ // No Servlet found
+ return null;
+ }
+
+ /**
+ * Destroy the Servlet host.
+ *
+ * @throws ServletException
+ */
+ public void destroy() {
+
+ // Destroy the registered Servlets
+ for (Servlet servlet : servlets.values()) {
+ servlet.destroy();
+ }
+
+ // Stop the node
+ if (node != null) {
+ node.stop();
+ }
+ }
+
+ public void doFilter(ServletRequest request, ServletResponse response, javax.servlet.FilterChain chain)
+ throws IOException, ServletException {
+
+ // Get the Servlet path
+ HttpServletRequest httpRequest = (HttpServletRequest)request;
+ String path = httpRequest.getPathInfo();
+ if (path == null) {
+ path = httpRequest.getServletPath();
+ }
+ if (path == null) {
+ path = "/";
+ }
+
+ // Get a request dispatcher for the Servlet mapped to that path
+ RequestDispatcher dispatcher = getRequestDispatcher(path);
+ if (dispatcher != null) {
+
+ // Let the dispatcher forward the request to the Servlet
+ dispatcher.forward(request, response);
+
+ } else {
+
+ // Proceed down the filter chain
+ chain.doFilter(request, response);
+ }
+ }
+
+ public void setDefaultPort(int port) {
+ defaultPort = port;
+ }
+
+ public int getDefaultPort() {
+ return defaultPort;
+ }
+
+ public String getContextPath() {
+ return contextPath;
+ }
+
+ public void setContextPath(String path) {
+ //this.contextPath = path;
+ }
+
+ /**
+ * Initializes the contextPath
+ * The 2.5 Servlet API has a getter for this, for pre 2.5 Servlet
+ * containers use an init parameter.
+ */
+ private static String contextPath(ServletContext context) {
+ String contextPath = "/";
+
+ // The getContextPath() is introduced since Servlet 2.5
+ Method m;
+ try {
+ // Try to get the method anyway since some ServletContext impl has this method even before 2.5
+ m = context.getClass().getMethod("getContextPath", new Class[] {});
+ contextPath = (String)m.invoke(context, new Object[] {});
+ } catch (Exception e) {
+ contextPath = context.getInitParameter("contextPath");
+ if (contextPath == null) {
+ logger.warning("Servlet level is: " + context.getMajorVersion() + "." + context.getMinorVersion());
+ throw new IllegalStateException(
+ "'contextPath' init parameter must be set for pre-2.5 servlet container");
+ }
+ }
+
+ logger.info("ContextPath: " + contextPath);
+ return contextPath;
+ }
+
+ /**
+ * Returns the Servlet host extension point used by the given node.
+ *
+ * @return
+ */
+ private static ServletHostExtensionPoint servletHosts(SCANode node) {
+ //FIXME Need a clean way to get the extension point registry
+ // from the node
+ ExtensionPointRegistry registry;
+ try {
+ registry = (ExtensionPointRegistry)node.getClass().getMethod("getExtensionPointRegistry").invoke(node);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ ServletHostExtensionPoint servletHosts = registry.getExtensionPoint(ServletHostExtensionPoint.class);
+ return servletHosts;
+ }
+
+ /**
+ * Returns a Servlet config wrapping a filter config.
+ *
+ * @param filterConfig
+ * @return
+ */
+ private static ServletConfig servletConfig(final FilterConfig filterConfig) {
+ ServletConfig servletConfig = new ServletConfig() {
+ public String getInitParameter(String name) {
+ return filterConfig.getInitParameter(name);
+ }
+
+ public Enumeration getInitParameterNames() {
+ return filterConfig.getInitParameterNames();
+ }
+
+ public ServletContext getServletContext() {
+ return filterConfig.getServletContext();
+ }
+
+ public String getServletName() {
+ return filterConfig.getFilterName();
+ }
+ };
+ return servletConfig;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory
new file mode 100644
index 0000000000..306b53be5b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.ImplementationProviderFactory
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for the implementation extension
+org.apache.tuscany.sca.implementation.node.provider.NodeImplementationProviderFactory;model=org.apache.tuscany.sca.implementation.node.NodeImplementation
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/test/java/org/apache/tuscany/sca/implementation/node/NodeImplementationTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/test/java/org/apache/tuscany/sca/implementation/node/NodeImplementationTestCase.java
new file mode 100644
index 0000000000..73475f49fe
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/test/java/org/apache/tuscany/sca/implementation/node/NodeImplementationTestCase.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.node;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.node.SCANode;
+import org.apache.tuscany.sca.node.SCANodeFactory;
+
+/**
+ * Test case for node component implementations.
+ *
+ * @version $Rev$ $Date$
+ */
+public class NodeImplementationTestCase extends TestCase {
+
+ private SCANode node;
+
+ @Override
+ protected void setUp() throws Exception {
+ node = SCANodeFactory.newInstance().createSCANodeFromClassLoader("TestNode.composite", null);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ node.stop();
+ }
+
+ public void testNode() {
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/test/resources/TestComposite.composite b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/test/resources/TestComposite.composite
new file mode 100644
index 0000000000..55644c27e5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/test/resources/TestComposite.composite
@@ -0,0 +1,29 @@
+<?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/1.0"
+ targetNamespace="http://sample/composite"
+ xmlns:sc="http://sample/composite"
+ name="TestComposite">
+
+ <component name="TestComponent">
+ </component>
+
+</composite>
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/test/resources/TestNode.composite b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/test/resources/TestNode.composite
new file mode 100644
index 0000000000..d4dc62a42d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node-runtime/src/test/resources/TestNode.composite
@@ -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/1.0"
+ targetNamespace="http://sample/node"
+ xmlns:sc="http://sample/composite"
+ name="TestNode">
+
+ <component name="TestNode">
+ <tuscany:implementation.node uri="TestNode" composite="sc:TestComposite"/>
+ </component>
+
+</composite>
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node/LICENSE b/sca-java-1.x/branches/sca-android/modules/implementation-node/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node/META-INF/README b/sca-java-1.x/branches/sca-android/modules/implementation-node/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node/NOTICE b/sca-java-1.x/branches/sca-android/modules/implementation-node/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node/pom.xml b/sca-java-1.x/branches/sca-android/modules/implementation-node/pom.xml
new file mode 100644
index 0000000000..2027eb7e30
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node/pom.xml
@@ -0,0 +1,93 @@
+<?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.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>tuscany-implementation-node</artifactId>
+ <name>Apache Tuscany SCA Node Implementation Model</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-binding-sca</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-binding-sca-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.2</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.implementation.node</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.implementation.node*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/ConfiguredNodeImplementation.java b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/ConfiguredNodeImplementation.java
new file mode 100644
index 0000000000..d4755f4071
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/ConfiguredNodeImplementation.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.implementation.node;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.contribution.Contribution;
+
+
+
+/**
+ * The model representing a resource implementation in an SCA assembly model.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ConfiguredNodeImplementation extends Implementation {
+
+ /**
+ * Returns the composite deployed to this node.
+ * @return the composite deployed to this node
+ */
+ Composite getComposite();
+
+ /**
+ * Sets the composite deployed to this node.
+ * @param composite the composite deployed to this node
+ */
+ void setComposite(Composite composite);
+
+ /**
+ * Returns the list of contributions deployed to this node.
+ * @return the list of contributions deployed to this node
+ */
+ List<Contribution> getContributions();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/NodeImplementation.java b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/NodeImplementation.java
new file mode 100644
index 0000000000..527698ea91
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/NodeImplementation.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.node;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Implementation;
+
+
+
+/**
+ * The model representing a resource implementation in an SCA assembly model.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface NodeImplementation extends Implementation {
+
+ /**
+ * Returns the composite deployed to this node.
+ * @return the composite deployed to this node
+ */
+ Composite getComposite();
+
+ /**
+ * Sets the composite deployed to this node.
+ * @param composite the composite deployed to this node
+ */
+ void setComposite(Composite composite);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/NodeImplementationFactory.java b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/NodeImplementationFactory.java
new file mode 100644
index 0000000000..9c4fed689b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/NodeImplementationFactory.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.node;
+
+
+/**
+ * Factory for the resource implementation model.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface NodeImplementationFactory {
+
+ /**
+ * Creates a new node implementation.
+ * @return a new node implementation
+ */
+ NodeImplementation createNodeImplementation();
+
+ /**
+ * Creates a new configured node implementation.
+ * @return a new configured node implementation
+ */
+ ConfiguredNodeImplementation createConfiguredNodeImplementation();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/builder/impl/NodeCompositeBuilderImpl.java b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/builder/impl/NodeCompositeBuilderImpl.java
new file mode 100644
index 0000000000..736afc13f0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/builder/impl/NodeCompositeBuilderImpl.java
@@ -0,0 +1,109 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.node.builder.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.TransformerFactory;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.assembly.builder.impl.BaseConfigurationBuilderImpl;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.implementation.node.NodeImplementation;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+/**
+ * A composite builder that handles the configuration of composites assigned to
+ * node components, from the default configuration from the node components.
+ *
+ * @version $Rev$ $Date$
+ */
+public class NodeCompositeBuilderImpl extends BaseConfigurationBuilderImpl implements CompositeBuilder {
+
+ @Deprecated
+ public NodeCompositeBuilderImpl(AssemblyFactory assemblyFactory,
+ SCABindingFactory scaBindingFactory,
+ InterfaceContractMapper interfaceContractMapper,
+ SCADefinitions policyDefinitions,
+ Monitor monitor) {
+ super(assemblyFactory, scaBindingFactory,
+ null, null,
+ interfaceContractMapper, policyDefinitions, monitor);
+ }
+
+ public NodeCompositeBuilderImpl(AssemblyFactory assemblyFactory,
+ SCABindingFactory scaBindingFactory,
+ DocumentBuilderFactory documentBuilderFactory,
+ TransformerFactory transformerFactory,
+ InterfaceContractMapper interfaceContractMapper,
+ SCADefinitions policyDefinitions,
+ Monitor monitor) {
+ super(assemblyFactory, scaBindingFactory,
+ documentBuilderFactory, transformerFactory,
+ interfaceContractMapper, policyDefinitions, monitor);
+ }
+
+ public void build(Composite composite) throws CompositeBuilderException {
+ configureNodeComponents(composite);
+ }
+
+ /**
+ * Configure the node components in the given composite.
+ *
+ * @param composite
+ * @throws CompositeBuilderException
+ */
+ private void configureNodeComponents(Composite composite) throws CompositeBuilderException {
+
+ // Process each node component in the given composite
+ for (Component component: composite.getComponents()) {
+ Implementation implementation = component.getImplementation();
+ if (implementation instanceof NodeImplementation) {
+
+ // Get the application composite assigned to the node
+ NodeImplementation nodeImplementation = (NodeImplementation)implementation;
+ Composite applicationComposite = nodeImplementation.getComposite();
+
+ // Get the default bindings configured on the node
+ List<Binding> defaultBindings = new ArrayList<Binding>();
+ for (ComponentService componentService: component.getServices()) {
+ defaultBindings.addAll(componentService.getBindings());
+ }
+
+ // Configure services in the application composite assigned to
+ // the node using the default bindings.
+ configureBindingURIs(applicationComposite, defaultBindings);
+ }
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/impl/ConfiguredNodeImplementationImpl.java b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/impl/ConfiguredNodeImplementationImpl.java
new file mode 100644
index 0000000000..1d183513b4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/impl/ConfiguredNodeImplementationImpl.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.node.impl;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.implementation.node.ConfiguredNodeImplementation;
+
+
+/**
+ * The model representing a configured node implementation in an SCA assembly model.
+ *
+ * @version $Rev$ $Date$
+ */
+class ConfiguredNodeImplementationImpl implements ConfiguredNodeImplementation {
+
+ private String uri;
+ private boolean unresolved;
+ private Composite composite;
+ private List<Contribution> contributions = new ArrayList<Contribution>();
+
+ /**
+ * Constructs a new node implementation.
+ */
+ ConfiguredNodeImplementationImpl() {
+ }
+
+ public ConstrainingType getConstrainingType() {
+ // The node implementation does not support constrainingTypes
+ return null;
+ }
+
+ public List<Property> getProperties() {
+ // The node implementation does not support properties
+ return Collections.emptyList();
+ }
+
+ public List<Service> getServices() {
+ // The node implementation does not support services
+ return Collections.emptyList();
+ }
+
+ public List<Reference> getReferences() {
+ // The node implementation does not support properties
+ return Collections.emptyList();
+ }
+
+ public String getURI() {
+ return uri;
+ }
+
+ public Composite getComposite() {
+ return composite;
+ }
+
+ public List<Contribution> getContributions() {
+ return contributions;
+ }
+
+ public void setConstrainingType(ConstrainingType constrainingType) {
+ // The node implementation does not support constrainingTypes
+ }
+
+ public void setURI(String uri) {
+ this.uri = uri;
+ }
+
+ public void setComposite(Composite composite) {
+ this.composite = composite;
+ }
+
+
+ public boolean isUnresolved() {
+ return unresolved;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ this.unresolved = unresolved;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/impl/NodeImplementationFactoryImpl.java b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/impl/NodeImplementationFactoryImpl.java
new file mode 100644
index 0000000000..94ea610314
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/impl/NodeImplementationFactoryImpl.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.node.impl;
+
+import org.apache.tuscany.sca.implementation.node.ConfiguredNodeImplementation;
+import org.apache.tuscany.sca.implementation.node.NodeImplementation;
+import org.apache.tuscany.sca.implementation.node.NodeImplementationFactory;
+
+/**
+ * Factory for the resource implementation model.
+ *
+ * @version $Rev$ $Date$
+ */
+public class NodeImplementationFactoryImpl implements NodeImplementationFactory {
+
+ public NodeImplementationFactoryImpl() {
+ }
+
+ public NodeImplementation createNodeImplementation() {
+ return new NodeImplementationImpl();
+ }
+
+ public ConfiguredNodeImplementation createConfiguredNodeImplementation() {
+ return new ConfiguredNodeImplementationImpl();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/impl/NodeImplementationImpl.java b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/impl/NodeImplementationImpl.java
new file mode 100644
index 0000000000..8f6315d969
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/impl/NodeImplementationImpl.java
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.node.impl;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.assembly.Property;
+import org.apache.tuscany.sca.assembly.Reference;
+import org.apache.tuscany.sca.assembly.Service;
+import org.apache.tuscany.sca.implementation.node.NodeImplementation;
+
+
+/**
+ * The model representing a node implementation in an SCA assembly model.
+ *
+ * @version $Rev$ $Date$
+ */
+class NodeImplementationImpl implements NodeImplementation {
+
+ private String uri;
+ private boolean unresolved;
+ private Composite composite;
+
+ /**
+ * Constructs a new node implementation.
+ */
+ NodeImplementationImpl() {
+ }
+
+ public ConstrainingType getConstrainingType() {
+ // The node implementation does not support constrainingTypes
+ return null;
+ }
+
+ public List<Property> getProperties() {
+ // The node implementation does not support properties
+ return Collections.emptyList();
+ }
+
+ public List<Service> getServices() {
+ // The node implementation does not support services
+ return Collections.emptyList();
+ }
+
+ public List<Reference> getReferences() {
+ // The node implementation does not support properties
+ return Collections.emptyList();
+ }
+
+ public String getURI() {
+ return uri;
+ }
+
+ public Composite getComposite() {
+ return composite;
+ }
+
+ public void setConstrainingType(ConstrainingType constrainingType) {
+ // The node implementation does not support constrainingTypes
+ }
+
+ public void setURI(String uri) {
+ this.uri = uri;
+ }
+
+ public void setComposite(Composite composite) {
+ this.composite = composite;
+ }
+
+
+ public boolean isUnresolved() {
+ return unresolved;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ this.unresolved = unresolved;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/xml/ConfiguredNodeImplementationProcessor.java b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/xml/ConfiguredNodeImplementationProcessor.java
new file mode 100644
index 0000000000..e695340d45
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/xml/ConfiguredNodeImplementationProcessor.java
@@ -0,0 +1,196 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.node.xml;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.implementation.node.ConfiguredNodeImplementation;
+import org.apache.tuscany.sca.implementation.node.NodeImplementationFactory;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+
+/**
+ * Implements a StAX artifact processor for configured node implementations.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConfiguredNodeImplementationProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<ConfiguredNodeImplementation> {
+
+ private static final String ATOM_NS = "http://www.w3.org/2005/Atom";
+ private static final QName FEED_QNAME = new QName(ATOM_NS, "feed");
+ private static final QName ENTRY_QNAME = new QName(ATOM_NS, "entry");
+ private static final QName ID_QNAME = new QName(ATOM_NS, "id");
+ private static final QName LINK_QNAME = new QName(ATOM_NS, "link");
+ private static final String HREF = "href";
+
+ private ContributionFactory contributionFactory;
+ private AssemblyFactory assemblyFactory;
+ private NodeImplementationFactory implementationFactory;
+
+ public ConfiguredNodeImplementationProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
+ this.contributionFactory = modelFactories.getFactory(ContributionFactory.class);
+ this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ this.implementationFactory = modelFactories.getFactory(NodeImplementationFactory.class);
+ }
+
+ public QName getArtifactType() {
+ return null;
+ }
+
+ public Class<ConfiguredNodeImplementation> getModelType() {
+ // Returns the type of model processed by this processor
+ return ConfiguredNodeImplementation.class;
+ }
+
+ public ConfiguredNodeImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+
+ ConfiguredNodeImplementation implementation = implementationFactory.createConfiguredNodeImplementation();
+ implementation.setUnresolved(true);
+
+ // Read a feed containing links to the composite and the contributions assigned to
+ // the node
+ Composite composite = null;
+ Contribution contribution = null;
+ boolean id = false;
+ QName name = null;
+
+ while (reader.hasNext()) {
+ int event = reader.getEventType();
+ switch (event) {
+
+ case START_ELEMENT:
+ name = reader.getName();
+
+ if (ENTRY_QNAME.equals(name)) {
+
+ // Read an <entry>
+ if (implementation.getComposite() == null) {
+ composite = assemblyFactory.createComposite();
+ } else {
+ contribution = contributionFactory.createContribution();
+ }
+ } else if (ID_QNAME.equals(name)) {
+
+ // Read an <id>
+ id = true;
+
+ } else if (LINK_QNAME.equals(name)) {
+
+ // Read a <link>
+ String href = getString(reader, HREF);
+
+ if (composite != null) {
+ composite.setURI(href);
+ } else if (contribution != null) {
+ contribution.setLocation(href);
+ }
+ }
+ break;
+
+ case XMLStreamConstants.CHARACTERS:
+
+ // Read characters inside an <id> element
+ if (id) {
+ if (contribution != null) {
+ contribution.setURI(reader.getText());
+ }
+ }
+ break;
+
+ case END_ELEMENT:
+ name = reader.getName();
+
+ // Clear current state when reading reaching end element
+ if (ENTRY_QNAME.equals(name)) {
+ if (composite != null) {
+ implementation.setComposite(composite);
+ } else if (contribution != null) {
+ implementation.getContributions().add(contribution);
+ }
+
+ composite = null;
+ contribution = null;
+
+ } else if (ID_QNAME.equals(name)) {
+ id = false;
+
+ } else if (FEED_QNAME.equals(name)) {
+
+ // We've reached the end of the feed
+ return implementation;
+ }
+ break;
+ }
+
+ // Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
+ }
+ return implementation;
+ }
+
+ public void resolve(ConfiguredNodeImplementation implementation, ModelResolver resolver) throws ContributionResolveException {
+
+ // Resolve the referenced composite
+ Composite composite = implementation.getComposite();
+ if (composite != null) {
+ composite = resolver.resolveModel(Composite.class, composite);
+ if (!composite.isUnresolved()) {
+ implementation.setComposite(composite);
+ }
+ }
+
+ // Resolve the referenced contributions
+ List<Contribution> contributions = implementation.getContributions();
+ for (int i = 0, n = contributions.size(); i < n; i++) {
+ Contribution contribution = contributions.get(i);
+ contribution = resolver.resolveModel(Contribution.class, contribution);
+ if (!contribution.isUnresolved()) {
+ contributions.set(i, contribution);
+ }
+ }
+
+ implementation.setUnresolved(false);
+ }
+
+ public void write(ConfiguredNodeImplementation implementation, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+ //TODO Write the feed describing the node configuration
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/xml/NodeImplementationProcessor.java b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/xml/NodeImplementationProcessor.java
new file mode 100644
index 0000000000..201354f89c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/java/org/apache/tuscany/sca/implementation/node/xml/NodeImplementationProcessor.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.implementation.node.xml;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.xml.Constants;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.implementation.node.NodeImplementation;
+import org.apache.tuscany.sca.implementation.node.NodeImplementationFactory;
+import org.apache.tuscany.sca.monitor.Monitor;
+
+
+/**
+ * Implements a StAX artifact processor for node implementations.
+ *
+ * @version $Rev$ $Date$
+ */
+public class NodeImplementationProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<NodeImplementation> {
+ private static final QName IMPLEMENTATION_NODE = new QName(Constants.SCA10_TUSCANY_NS, "implementation.node");
+
+ private AssemblyFactory assemblyFactory;
+ private NodeImplementationFactory implementationFactory;
+
+ public NodeImplementationProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
+ this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ this.implementationFactory = modelFactories.getFactory(NodeImplementationFactory.class);
+ }
+
+ public QName getArtifactType() {
+ // Returns the QName of the XML element processed by this processor
+ return IMPLEMENTATION_NODE;
+ }
+
+ public Class<NodeImplementation> getModelType() {
+ // Returns the type of model processed by this processor
+ return NodeImplementation.class;
+ }
+
+ public NodeImplementation read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+
+ // Read an <implementation.node> element
+ NodeImplementation implementation = implementationFactory.createNodeImplementation();
+ implementation.setUnresolved(false);
+
+ // Read the composite attribute
+ QName qname = getQName(reader, "composite");
+ if (qname != null) {
+ Composite composite = assemblyFactory.createComposite();
+ composite.setName(qname);
+ String uri = getString(reader, "uri");
+ composite.setURI(uri);
+ composite.setUnresolved(true);
+ implementation.setComposite(composite);
+ }
+
+ // Skip to end element
+ while (reader.hasNext()) {
+ if (reader.next() == END_ELEMENT && IMPLEMENTATION_NODE.equals(reader.getName())) {
+ break;
+ }
+ }
+
+ return implementation;
+ }
+
+ public void resolve(NodeImplementation implementation, ModelResolver resolver) throws ContributionResolveException {
+ // We do not need to resolve the referenced composites here
+ // Nodes and application composites are not in the same composition tree
+ }
+
+ public void write(NodeImplementation implementation, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+
+ // Write <implementation.node>
+ Composite composite = implementation.getComposite();
+ QName qname;
+ String uri;
+ if (composite != null) {
+ qname = composite.getName();
+ uri = composite.getURI();
+ } else {
+ qname = null;
+ uri = null;
+ }
+ writeStart(writer, IMPLEMENTATION_NODE.getNamespaceURI(), IMPLEMENTATION_NODE.getLocalPart(),
+ new XAttr("composite", qname), new XAttr("uri", uri));
+
+ writeEnd(writer);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
new file mode 100644
index 0000000000..9378db0875
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -0,0 +1,20 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for the artifact processor extension
+org.apache.tuscany.sca.implementation.node.xml.NodeImplementationProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#implementation.node,model=org.apache.tuscany.sca.implementation.node.NodeImplementation,factory=org.apache.tuscany.sca.implementation.node.NodeImplementationFactory
+org.apache.tuscany.sca.implementation.node.xml.ConfiguredNodeImplementationProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.0#implementation.node.configured,model=org.apache.tuscany.sca.implementation.node.ConfiguredNodeImplementation,factory=org.apache.tuscany.sca.implementation.node.NodeImplementationFactory \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.node.NodeImplementationFactory b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.node.NodeImplementationFactory
new file mode 100644
index 0000000000..b8a63a3b16
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/main/resources/META-INF/services/org.apache.tuscany.sca.implementation.node.NodeImplementationFactory
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for model factory
+org.apache.tuscany.sca.implementation.node.impl.NodeImplementationFactoryImpl
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node/src/test/java/org/apache/tuscany/sca/implementation/node/builder/impl/CalculateBindingURITestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/test/java/org/apache/tuscany/sca/implementation/node/builder/impl/CalculateBindingURITestCase.java
new file mode 100644
index 0000000000..1dc397659b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/test/java/org/apache/tuscany/sca/implementation/node/builder/impl/CalculateBindingURITestCase.java
@@ -0,0 +1,587 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.node.builder.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.DefaultAssemblyFactory;
+import org.apache.tuscany.sca.assembly.SCABinding;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.implementation.node.NodeImplementation;
+import org.apache.tuscany.sca.implementation.node.NodeImplementationFactory;
+import org.apache.tuscany.sca.implementation.node.impl.NodeImplementationFactoryImpl;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class CalculateBindingURITestCase extends TestCase {
+ private static final Logger logger = Logger.getLogger(CalculateBindingURITestCase.class.getName());
+ private AssemblyFactory assemblyFactory;
+ private SCABindingFactory scaBindingFactory;
+ private NodeImplementationFactory nodeImplementationFactory;
+ private Monitor monitor;
+ private CompositeBuilder configurationBuilder;
+ private List<Binding> defaultBindings = new ArrayList<Binding>();
+
+ @Override
+ protected void setUp() throws Exception {
+ assemblyFactory = new DefaultAssemblyFactory();
+ scaBindingFactory = new TestBindingFactory();
+ nodeImplementationFactory = new NodeImplementationFactoryImpl();
+ monitor = new Monitor() {
+ public void problem(Problem problem) {
+ if (problem.getSeverity() == Severity.INFO) {
+ logger.info(problem.toString());
+ } else if (problem.getSeverity() == Severity.WARNING) {
+ logger.warning(problem.toString());
+ } else if (problem.getSeverity() == Severity.ERROR) {
+ if (problem.getCause() != null) {
+ logger.log(Level.SEVERE, problem.toString(), problem.getCause());
+ } else {
+ logger.severe(problem.toString());
+ }
+ }
+ }
+ public List<Problem> getProblems() {
+ return null;
+ }
+ };
+ configurationBuilder = new NodeCompositeBuilderImpl(assemblyFactory, scaBindingFactory, null, null, monitor);
+ Binding defaultBinding = new TestBindingImpl();
+ defaultBinding.setURI("http://myhost:8080/root");
+ defaultBindings.add(defaultBinding);
+ }
+
+ /**
+ * Create a composite containing a node component pointing to the
+ * given application composite.
+ *
+ * @param composite
+ * @return
+ */
+ private Composite nodeComposite(Composite composite) {
+ Composite nodeComposite = assemblyFactory.createComposite();
+ Component nodeComponent = assemblyFactory.createComponent();
+ NodeImplementation nodeImplementation = nodeImplementationFactory.createNodeImplementation();
+ nodeImplementation.setComposite(composite);
+ nodeComponent.setImplementation(nodeImplementation);
+ ComponentService nodeService = assemblyFactory.createComponentService();
+ nodeService.getBindings().addAll(defaultBindings);
+ nodeComponent.getServices().add(nodeService);
+ nodeComposite.getComponents().add(nodeComponent);
+ return nodeComposite;
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ assemblyFactory = null;
+ }
+
+ /**
+ * Test that URI are generated in accordance with the Assembly Specification section 1.7.2.1 as
+ * follows. For the 3 parts that make up the URI;
+ *
+ * BaseURI / Component URI / Service Binding URI
+ *
+ * Test the following combinations for:
+ *
+ * NB. The short hand here, e.g. <service name="s1"> <binding.sca> <service name="s2"> means
+ * two services appear where the first has the sca binding specified.
+ *
+ * component service bindings
+ *
+ * http://myhost:8080/root / <component name="c1"> / <service name="s1"> <binding.sca>
+ * --> http://myhost:8080/root/c1
+ * http://myhost:8080/root / <component name="c1"> / <service name="s1"> <binding.sca> <service name="s2">
+ * --> http://myhost:8080/root/c1/s1
+ * http://myhost:8080/root / <component name="c1"> / <service name="s1"> <binding.sca name="n"> <service name="s2">
+ * --> http://myhost:8080/root/c1/n
+ * http://myhost:8080/root / <component name="c1"> / <service name="s1"> <binding.sca uri="b"> <service name="s2">
+ * --> http://myhost:8080/root/c1/b
+ * http://myhost:8080/root / <component name="c1"> / <service name="s1"> <binding.sca uri="http://myhost:8080/b"> <service name="s2">
+ * --> http://myhost:8080/b
+ * http://myhost:8080/root / <component name="c1"> / <service name="s1"> <binding.sca uri="../../b"> <service name="s2">
+ * --> http://myhost:8080/b
+ *
+ * top level composite service bindings
+ *
+ * http://myhost:8080/root / null / <service name="s1"> <binding.sca> <service name="s2">
+ * --> http://myhost:8080/root
+ * http://myhost:8080/root / null / <service name="s1"> <binding.sca> <service name="s2">
+ * --> http://myhost:8080/root/s1
+ * http://myhost:8080/root / null / <service name="s1"> <binding.sca name="n"> <service name="s2">
+ * --> http://myhost:8080/root/n
+ * http://myhost:8080/root / null / <service name="s1"> <binding.sca uri="b"> <service name="s2">
+ * --> http://myhost:8080/root/b
+ * http://myhost:8080/root / null / <service name="s1"> <binding.sca uri="http://myhost:8080/b"> <service name="s2">
+ * --> http://myhost:8080/b
+ *
+ * nested composite service bindings
+ *
+ * http://myhost:8080/root / <component name="c1"> implemented by composite with <component name="c2"> / <service name="s1"> <binding.sca>
+ * --> http://myhost:8080/root/c1/c2
+ * http://myhost:8080/root / <component name="c1"> implemented by composite with <component name="c2"> / <service name="s1"> <binding.sca> <service name="s2">
+ * --> http://myhost:8080/root/c1/c2/s1
+ * http://myhost:8080/root / <component name="c1"> implemented by composite with <component name="c2"> / <service name="s1"> <binding.sca name="n"> <service name="s2">
+ * --> http://myhost:8080/root/c1/c2/n
+ * http://myhost:8080/root / <component name="c1"> implemented by composite with <component name="c2"> / <service name="s1"> <binding.sca uri="b"> <service name="s2">
+ * --> http://myhost:8080/root/c1/c2/b
+ * http://myhost:8080/root / <component name="c1"> implemented by composite with <component name="c2"> / <service name="s1"> <binding.sca uri="http://myhost:8080/b"> <service name="s2">
+ * --> http://myhost:8080/b
+ *
+ * binding name duplication errors
+ *
+ * http://myhost:8080/root / <component name="c1"> implemented by composite with <component name="c2"> / <service name="s1"> <binding.sca> <binding.xyz>
+ * --> Error
+ * http://myhost:8080/root / <component name="c1"> implemented by composite with <component name="c2"> / <service name="s1"> <binding.sca name="b1"> <binding.xyz name="b1">
+ * --> Error
+ */
+
+ private Composite createComponentServiceBinding() {
+ Composite composite1 = assemblyFactory.createComposite();
+ composite1.setName(new QName("http://foo", "C1"));
+
+ Component c1 = assemblyFactory.createComponent();
+ c1.setName("c1");
+ composite1.getComponents().add(c1);
+
+ ComponentService s1 = assemblyFactory.createComponentService();
+ c1.getServices().add(s1);
+ s1.setName("s1");
+
+ ComponentService s2 = assemblyFactory.createComponentService();
+ c1.getServices().add(s2);
+ s2.setName("s2");
+
+ Binding b1 = new TestBindingImpl();
+ s1.getBindings().add(b1);
+
+ Binding b2 = new TestBindingImpl();
+ s2.getBindings().add(b2);
+
+ return composite1;
+ }
+
+ private Composite createTopLevelCompositeServiceBinding(){
+ Composite composite1 = assemblyFactory.createComposite();
+ composite1.setName(new QName("http://foo", "C1"));
+
+ CompositeService s1 = assemblyFactory.createCompositeService();
+ s1.setName("s1");
+ composite1.getServices().add(s1);
+
+ Binding b1 = new TestBindingImpl();
+ s1.getBindings().add(b1);
+
+ CompositeService s2 = assemblyFactory.createCompositeService();
+ s2.setName("s2");
+ composite1.getServices().add(s2);
+
+ Binding b2 = new TestBindingImpl();
+ s2.getBindings().add(b2);
+
+ return composite1;
+ }
+
+ private Composite createNestCompositeServiceBinding(){
+ Composite composite1 = assemblyFactory.createComposite();
+ composite1.setName(new QName("http://foo", "C1"));
+
+ Component c1 = assemblyFactory.createComponent();
+ c1.setName("c1");
+ composite1.getComponents().add(c1);
+
+ Composite composite2 = assemblyFactory.createComposite();
+ c1.setImplementation(composite2);
+ composite2.setName(new QName("http://foo", "C2"));
+
+ Component c2 = assemblyFactory.createComponent();
+ composite2.getComponents().add(c2);
+ c2.setName("c2");
+
+ ComponentService s1 = assemblyFactory.createComponentService();
+ c2.getServices().add(s1);
+ s1.setName("s1");
+
+ ComponentService s2 = assemblyFactory.createComponentService();
+ c2.getServices().add(s2);
+ s2.setName("s2");
+
+ Binding b1 = new TestBindingImpl();
+ s1.getBindings().add(b1);
+
+ Binding b2 = new TestBindingImpl();
+ s2.getBindings().add(b2);
+
+ return composite1;
+ }
+
+ // component service binding tests
+
+ public void testComponentServiceSingleService() {
+ Composite composite = createComponentServiceBinding();
+ composite.getComponents().get(0).getServices().remove(1);
+ Binding b = composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+
+ try {
+ configurationBuilder.build(nodeComposite(composite));
+
+ assertEquals("http://myhost:8080/root/c1", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testComponentServiceBindingDefault() {
+ Composite composite = createComponentServiceBinding();
+ Binding b = composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+
+ try {
+ configurationBuilder.build(nodeComposite(composite));
+
+ assertEquals("http://myhost:8080/root/c1/s1", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testComponentServiceBindingName() {
+ Composite composite = createComponentServiceBinding();
+ Binding b = composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+ b.setName("n");
+
+ try {
+ configurationBuilder.build(nodeComposite(composite));
+
+ assertEquals("http://myhost:8080/root/c1/n", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testComponentServiceBindingURIRelative() {
+ Composite composite = createComponentServiceBinding();
+ Binding b = composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+ b.setName("n");
+ b.setURI("b");
+
+ try {
+ configurationBuilder.build(nodeComposite(composite));
+
+ assertEquals("http://myhost:8080/root/c1/b", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testComponentServiceBindingURIAbsolute() {
+ Composite composite = createComponentServiceBinding();
+ Binding b = composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+ b.setName("n");
+ b.setURI("http://myhost:8080/b");
+
+ try {
+ configurationBuilder.build(nodeComposite(composite));
+
+ assertEquals("http://myhost:8080/b", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testComponentServiceBindingURIRelative2() {
+ Composite composite = createComponentServiceBinding();
+ Binding b = composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+ b.setName("n");
+ b.setURI("../../b");
+
+ try {
+ configurationBuilder.build(nodeComposite(composite));
+
+ assertEquals("http://myhost:8080/b", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ // top level composite service binding tests
+
+ public void testCompositeServiceSingleService() {
+ Composite composite = createTopLevelCompositeServiceBinding();
+ composite.getServices().remove(1);
+ Binding b = composite.getServices().get(0).getBindings().get(0);
+
+ try {
+ configurationBuilder.build(nodeComposite(composite));
+
+ assertEquals("http://myhost:8080/root", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testCompositeServiceBindingDefault() {
+ Composite composite = createTopLevelCompositeServiceBinding();
+ Binding b = composite.getServices().get(0).getBindings().get(0);
+
+ try {
+ configurationBuilder.build(nodeComposite(composite));
+
+ assertEquals("http://myhost:8080/root/s1", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testCompositeServiceBindingName() {
+ Composite composite = createTopLevelCompositeServiceBinding();
+ Binding b = composite.getServices().get(0).getBindings().get(0);
+ b.setName("n");
+
+ try {
+ configurationBuilder.build(nodeComposite(composite));
+
+ assertEquals("http://myhost:8080/root/n", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testCompositeServiceBindingURIRelative() {
+ Composite composite = createTopLevelCompositeServiceBinding();
+ Binding b = composite.getServices().get(0).getBindings().get(0);
+ b.setName("n");
+ b.setURI("b");
+
+ try {
+ configurationBuilder.build(nodeComposite(composite));
+
+ assertEquals("http://myhost:8080/root/b", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testCompositeServiceBindingURIAbsolute() {
+ Composite composite = createTopLevelCompositeServiceBinding();
+ Binding b = composite.getServices().get(0).getBindings().get(0);
+ b.setName("n");
+ b.setURI("http://myhost:8080/b");
+
+ try {
+ configurationBuilder.build(nodeComposite(composite));
+
+ assertEquals("http://myhost:8080/b", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ // nested composite service binding tests
+
+ public void testNestedCompositeServiceSingleService() {
+ Composite composite = createNestCompositeServiceBinding();
+ ((Composite)composite.getComponents().get(0).getImplementation()).getComponents().get(0).getServices().remove(1);
+ Binding b = ((Composite)composite.getComponents().get(0).getImplementation()).getComponents().get(0).getServices().get(0).getBindings().get(0);
+
+ try {
+ configurationBuilder.build(nodeComposite(composite));
+
+ assertEquals("http://myhost:8080/root/c1/c2", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testNestedCompositeServiceBindingDefault() {
+ Composite composite = createNestCompositeServiceBinding();
+ Binding b = ((Composite)composite.getComponents().get(0).getImplementation()).getComponents().get(0).getServices().get(0).getBindings().get(0);
+
+ try {
+ configurationBuilder.build(nodeComposite(composite));
+
+ assertEquals("http://myhost:8080/root/c1/c2/s1", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testNestedCompositeServiceBindingName() {
+ Composite composite = createNestCompositeServiceBinding();
+ Binding b = ((Composite)composite.getComponents().get(0).getImplementation()).getComponents().get(0).getServices().get(0).getBindings().get(0);
+ b.setName("n");
+
+ try {
+ configurationBuilder.build(nodeComposite(composite));
+
+ assertEquals("http://myhost:8080/root/c1/c2/n", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testNestedCompositeServiceBindingURIRelative() {
+ Composite composite = createNestCompositeServiceBinding();
+ Binding b = ((Composite)composite.getComponents().get(0).getImplementation()).getComponents().get(0).getServices().get(0).getBindings().get(0);
+ b.setName("n");
+ b.setURI("b");
+
+ try {
+ configurationBuilder.build(nodeComposite(composite));
+
+ assertEquals("http://myhost:8080/root/c1/c2/b", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ public void testNestedCompositeServiceBindingURIAbsolute() {
+ Composite composite = createNestCompositeServiceBinding();
+ Binding b = ((Composite)composite.getComponents().get(0).getImplementation()).getComponents().get(0).getServices().get(0).getBindings().get(0);
+ b.setName("n");
+ b.setURI("http://myhost:8080/b");
+
+ try {
+ configurationBuilder.build(nodeComposite(composite));
+
+ assertEquals("http://myhost:8080/b", b.getURI());
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ fail();
+ }
+ }
+
+ // component service binding name error tests
+
+ //FIXME Need to find a better way to test these error cases as
+ // the composite builder now (intentionally) logs warnings instead of
+ // throwing exceptions
+ public void FIXMEtestComponentServiceBindingNameError1() {
+ Composite composite = createComponentServiceBinding();
+ Binding b1 = composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+ Binding b2 = new TestBindingImpl();
+ composite.getComponents().get(0).getServices().get(0).getBindings().add(b2);
+
+
+ try {
+ configurationBuilder.build(nodeComposite(composite));
+ fail();
+ } catch(Exception ex){
+ //System.out.println(ex.toString());
+ }
+ }
+
+ //FIXME Need to find a better way to test these error cases as
+ // the composite builder now (intentionally) logs warnings instead of
+ // throwing exceptions
+ public void FIXMEtestComponentServiceBindingNameError2() {
+ Composite composite = createComponentServiceBinding();
+ Binding b1 = composite.getComponents().get(0).getServices().get(0).getBindings().get(0);
+ Binding b2 = new TestBindingImpl();
+ composite.getComponents().get(0).getServices().get(0).getBindings().add(b2);
+
+ b1.setName("b");
+ b2.setName("b");
+
+
+ try {
+ configurationBuilder.build(nodeComposite(composite));
+ fail();
+ } catch(Exception ex){
+ System.out.println(ex.toString());
+ }
+ }
+
+
+ public class TestBindingFactory implements SCABindingFactory {
+ public SCABinding createSCABinding() {
+ return new TestBindingImpl();
+ }
+ }
+
+ public class TestBindingImpl implements SCABinding {
+ private String name;
+ private String uri;
+ private boolean unresolved;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getURI() {
+ return uri;
+ }
+
+ public void setURI(String uri) {
+ this.uri = uri;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ this.unresolved = unresolved;
+ }
+
+ public boolean isUnresolved() {
+ return unresolved;
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node/src/test/java/org/apache/tuscany/sca/implementation/node/xml/ReadTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/test/java/org/apache/tuscany/sca/implementation/node/xml/ReadTestCase.java
new file mode 100644
index 0000000000..bc0c3b1507
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/test/java/org/apache/tuscany/sca/implementation/node/xml/ReadTestCase.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.implementation.node.xml;
+
+import java.io.InputStream;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl;
+import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
+
+/**
+ * Test reading Node implementations.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReadTestCase extends TestCase {
+
+ private XMLInputFactory inputFactory;
+ private StAXArtifactProcessor<Object> staxProcessor;
+ private CompositeBuilder compositeBuilder;
+
+ @Override
+ public void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ inputFactory = XMLInputFactory.newInstance();
+ StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, null);
+
+ ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ SCABindingFactory scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class);
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class);
+ IntentAttachPointTypeFactory attachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class);
+ compositeBuilder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, attachPointTypeFactory, mapper, null);
+ }
+
+ public void testReadComposite() throws Exception {
+ InputStream is = getClass().getResourceAsStream("TestNode.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = (Composite)staxProcessor.read(reader);
+ assertNotNull(composite);
+
+ compositeBuilder.build(composite);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node/src/test/java/org/apache/tuscany/sca/implementation/node/xml/WriteTestCase.java b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/test/java/org/apache/tuscany/sca/implementation/node/xml/WriteTestCase.java
new file mode 100644
index 0000000000..c5e6a40f89
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/test/java/org/apache/tuscany/sca/implementation/node/xml/WriteTestCase.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.implementation.node.xml;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+
+/**
+ * Test reading/writing Node implementations.
+ *
+ * @version $Rev$ $Date$
+ */
+public class WriteTestCase extends TestCase {
+
+ private XMLInputFactory inputFactory;
+ private XMLOutputFactory outputFactory;
+ private StAXArtifactProcessor<Object> staxProcessor;
+
+ @Override
+ public void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ inputFactory = XMLInputFactory.newInstance();
+ outputFactory = XMLOutputFactory.newInstance();
+ StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null);
+ }
+
+ public void testReadWriteComposite() throws Exception {
+ InputStream is = getClass().getResourceAsStream("TestNode.composite");
+ Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is));
+ assertNotNull(composite);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos));
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node/src/test/resources/org/apache/tuscany/sca/implementation/node/xml/TestComposite.composite b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/test/resources/org/apache/tuscany/sca/implementation/node/xml/TestComposite.composite
new file mode 100644
index 0000000000..55644c27e5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/test/resources/org/apache/tuscany/sca/implementation/node/xml/TestComposite.composite
@@ -0,0 +1,29 @@
+<?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/1.0"
+ targetNamespace="http://sample/composite"
+ xmlns:sc="http://sample/composite"
+ name="TestComposite">
+
+ <component name="TestComponent">
+ </component>
+
+</composite>
diff --git a/sca-java-1.x/branches/sca-android/modules/implementation-node/src/test/resources/org/apache/tuscany/sca/implementation/node/xml/TestNode.composite b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/test/resources/org/apache/tuscany/sca/implementation/node/xml/TestNode.composite
new file mode 100644
index 0000000000..92787d3ac1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/implementation-node/src/test/resources/org/apache/tuscany/sca/implementation/node/xml/TestNode.composite
@@ -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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.0"
+ targetNamespace="http://sample/node"
+ xmlns:sc="http://sample/composite"
+ name="TestNode">
+
+ <component name="TestNode">
+ <tuscany:implementation.node composite="sc:TestComposite"/>
+ <service name="Default">
+ <binding.sca uri="http://localhost:8080"/>
+ </service>
+ </component>
+
+ <component name="TestNode2">
+ <tuscany:implementation.node.configured>
+
+ <feed xmlns="http://www.w3.org/2005/Atom">
+ <title type="text">Feed</title>
+ <entry>
+ <id>composite:store;http://store;store</id>
+ <title type="text">store - http://store;store</title>
+ <content type="text" />
+ <link
+ href="/resolved/composite/composite:store;http://store;store" />
+ </entry>
+ <entry>
+ <id>assets</id>
+ <title type="text">assets</title>
+ <content type="text" />
+ <link
+ href="http://localhost:9990/files/tutorial-assets.jar" />
+ </entry>
+ <entry>
+ <id>store</id>
+ <title type="text">store</title>
+ <content type="text" />
+ <link
+ href="http://localhost:9990/files/tutorial-store.jar" />
+ </entry>
+ </feed>
+
+ </tuscany:implementation.node.configured>
+ </component>
+
+</composite>
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java-xml/LICENSE b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java-xml/META-INF/README b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java-xml/NOTICE b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java-xml/pom.xml b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/pom.xml
new file mode 100644
index 0000000000..989e7bd6ae
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/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>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-interface-java-xml</artifactId>
+ <name>Apache Tuscany SCA Java Interface XML Model</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-interface-java</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution-impl</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-binding-sca</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.interface.java.xml</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.interfacedef.java.xml*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaConstants.java b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaConstants.java
new file mode 100644
index 0000000000..5d2d8ed51c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaConstants.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.interfacedef.java.xml;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.xml.Constants;
+
+/**
+ * Interface Java XML Constants.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface JavaConstants {
+
+ String INTERFACE_JAVA = "interface.java";
+ QName INTERFACE_JAVA_QNAME = new QName(Constants.SCA10_NS, "interface.java");
+ String INTERFACE = "interface";
+ String CALLBACK_INTERFACE = "callbackInterface";
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java
new file mode 100644
index 0000000000..ae5bf4c56d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/main/java/org/apache/tuscany/sca/interfacedef/java/xml/JavaInterfaceProcessor.java
@@ -0,0 +1,193 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.interfacedef.java.xml;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.assembly.xml.Constants;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ClassReference;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaInterfaceProcessor implements StAXArtifactProcessor<JavaInterfaceContract>, JavaConstants {
+
+ private JavaInterfaceFactory javaFactory;
+ private Monitor monitor;
+
+ public JavaInterfaceProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
+ this.javaFactory = modelFactories.getFactory(JavaInterfaceFactory.class);
+ this.monitor = monitor;
+ }
+
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "interface-javaxml-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "interface-javaxml-validation-messages", Severity.ERROR, model, message,(Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ private JavaInterface createJavaInterface(String interfaceName) {
+ JavaInterface javaInterface = javaFactory.createJavaInterface();
+ javaInterface.setUnresolved(true);
+ javaInterface.setName(interfaceName);
+ return javaInterface;
+ }
+
+ public JavaInterfaceContract read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+
+ // Read an <interface.java>
+ JavaInterfaceContract javaInterfaceContract = javaFactory.createJavaInterfaceContract();
+ String interfaceName = reader.getAttributeValue(null, INTERFACE);
+ if (interfaceName != null) {
+ JavaInterface javaInterface = createJavaInterface(interfaceName);
+ javaInterfaceContract.setInterface(javaInterface);
+ }
+
+ String callbackInterfaceName = reader.getAttributeValue(null, CALLBACK_INTERFACE);
+ if (callbackInterfaceName != null) {
+ JavaInterface javaCallbackInterface = createJavaInterface(callbackInterfaceName);
+ javaInterfaceContract.setCallbackInterface(javaCallbackInterface);
+ }
+
+ // Skip to end element
+ while (reader.hasNext()) {
+ if (reader.next() == END_ELEMENT && INTERFACE_JAVA_QNAME.equals(reader.getName())) {
+ break;
+ }
+ }
+ return javaInterfaceContract;
+ }
+
+ public void write(JavaInterfaceContract javaInterfaceContract, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+
+ // Write an <interface.java>
+ writer.writeStartElement(Constants.SCA10_NS, INTERFACE_JAVA);
+ JavaInterface javaInterface = (JavaInterface)javaInterfaceContract.getInterface();
+
+ if (javaInterface != null && javaInterface.getName() != null) {
+ writer.writeAttribute(INTERFACE, javaInterface.getName());
+ }
+
+ JavaInterface javaCallbackInterface = (JavaInterface)javaInterfaceContract.getCallbackInterface();
+ if (javaCallbackInterface != null && javaCallbackInterface.getName() != null) {
+ writer.writeAttribute(CALLBACK_INTERFACE, javaCallbackInterface.getName());
+ }
+
+ writer.writeEndElement();
+ }
+
+ private JavaInterface resolveJavaInterface(JavaInterface javaInterface, ModelResolver resolver) throws ContributionResolveException {
+
+ if (javaInterface != null && javaInterface.isUnresolved()) {
+
+ // Resolve the Java interface
+ javaInterface = resolver.resolveModel(JavaInterface.class, javaInterface);
+ if (javaInterface.isUnresolved()) {
+
+ // If the Java interface has never been resolved yet, do it now
+ ClassReference classReference = new ClassReference(javaInterface.getName());
+ classReference = resolver.resolveModel(ClassReference.class, classReference);
+ Class javaClass = classReference.getJavaClass();
+ if (javaClass == null) {
+ error("ClassNotFoundException", resolver, javaInterface.getName());
+ return javaInterface;
+ //throw new ContributionResolveException(new ClassNotFoundException(javaInterface.getName()));
+ }
+
+ try {
+ // Introspect the Java interface and populate the interface and
+ // operations
+ javaFactory.createJavaInterface(javaInterface, javaClass);
+
+ } catch (InvalidInterfaceException e) {
+ ContributionResolveException ce = new ContributionResolveException(e);
+ error("ContributionResolveException", javaFactory, ce);
+ return javaInterface;
+ //throw ce;
+ }
+
+ // Cache the resolved interface
+ javaInterface.setUnresolved(false);
+ resolver.addModel(javaInterface);
+ }
+ }
+ return javaInterface;
+ }
+
+ public void resolve(JavaInterfaceContract javaInterfaceContract, ModelResolver resolver) throws ContributionResolveException {
+
+ // Resolve the interface and callback interface
+ JavaInterface javaInterface = resolveJavaInterface((JavaInterface)javaInterfaceContract.getInterface(), resolver);
+ javaInterfaceContract.setInterface(javaInterface);
+
+ JavaInterface javaCallbackInterface = resolveJavaInterface((JavaInterface)javaInterfaceContract.getCallbackInterface(), resolver);
+ javaInterfaceContract.setCallbackInterface(javaCallbackInterface);
+ }
+
+ public QName getArtifactType() {
+ return INTERFACE_JAVA_QNAME;
+ }
+
+ public Class<JavaInterfaceContract> getModelType() {
+ return JavaInterfaceContract.class;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
new file mode 100644
index 0000000000..b3e52e5709
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for the artifact processor extension
+org.apache.tuscany.sca.interfacedef.java.xml.JavaInterfaceProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#interface.java,model=org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/main/resources/interface-javaxml-validation-messages.properties b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/main/resources/interface-javaxml-validation-messages.properties
new file mode 100644
index 0000000000..bc0a7192b5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/main/resources/interface-javaxml-validation-messages.properties
@@ -0,0 +1,22 @@
+#
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+#
+ClassNotFoundException = Class Not Found Exception: {0}
+ContributionResolveException = ContributionResolveException occured due to :
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/ReadTestCase.java b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/ReadTestCase.java
new file mode 100644
index 0000000000..313f950873
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/ReadTestCase.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.interfacedef.java.xml;
+
+import java.io.InputStream;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl;
+import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
+
+/**
+ * Test reading Java interfaces.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ReadTestCase extends TestCase {
+
+ private XMLInputFactory inputFactory;
+ private XMLOutputFactory outputFactory;
+ private StAXArtifactProcessor<Object> staxProcessor;
+ private CompositeBuilder compositeBuilder;
+
+ @Override
+ public void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ inputFactory = XMLInputFactory.newInstance();
+ outputFactory = XMLOutputFactory.newInstance();
+ StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null);
+
+ ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ SCABindingFactory scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class);
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class);
+ IntentAttachPointTypeFactory attachPointTypeFactory = modelFactories.getFactory(IntentAttachPointTypeFactory.class);
+ compositeBuilder = new CompositeBuilderImpl(assemblyFactory, scaBindingFactory, attachPointTypeFactory, mapper, null);
+ }
+
+ public void testReadComponentType() throws Exception {
+ InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ ComponentType componentType = (ComponentType)staxProcessor.read(reader);
+ assertNotNull(componentType);
+ }
+
+ public void testReadConstrainingType() throws Exception {
+ InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ ConstrainingType constrainingType = (ConstrainingType)staxProcessor.read(reader);
+ assertNotNull(constrainingType);
+ }
+
+ public void testReadComposite() throws Exception {
+ InputStream is = getClass().getResourceAsStream("Calculator.composite");
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ Composite composite = (Composite)staxProcessor.read(reader);
+ assertNotNull(composite);
+
+ compositeBuilder.build(composite);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/WriteTestCase.java b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/WriteTestCase.java
new file mode 100644
index 0000000000..55fc12d176
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/test/java/org/apache/tuscany/sca/interfacedef/java/xml/WriteTestCase.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.interfacedef.java.xml;
+
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.assembly.ComponentType;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.ConstrainingType;
+import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+
+/**
+ * Test writing Java interfaces.
+ *
+ * @version $Rev$ $Date$
+ */
+public class WriteTestCase extends TestCase {
+
+ private XMLInputFactory inputFactory;
+ private XMLOutputFactory outputFactory;
+ private StAXArtifactProcessor<Object> staxProcessor;
+
+ @Override
+ public void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ inputFactory = XMLInputFactory.newInstance();
+ outputFactory = XMLOutputFactory.newInstance();
+ StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null);
+ }
+
+ public void testReadWriteComponentType() throws Exception {
+ InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType");
+ ComponentType componentType = (ComponentType)staxProcessor.read(inputFactory.createXMLStreamReader(is));
+ assertNotNull(componentType);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(componentType, outputFactory.createXMLStreamWriter(bos));
+ }
+
+ public void testReadWriteConstrainingType() throws Exception {
+ InputStream is = getClass().getResourceAsStream("CalculatorComponent.constrainingType");
+ ConstrainingType constrainingType = (ConstrainingType)staxProcessor.read(inputFactory.createXMLStreamReader(is));
+ assertNotNull(constrainingType);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(constrainingType, outputFactory.createXMLStreamWriter(bos));
+ }
+
+ public void testReadWriteComposite() throws Exception {
+ InputStream is = getClass().getResourceAsStream("Calculator.composite");
+ Composite composite = (Composite)staxProcessor.read(inputFactory.createXMLStreamReader(is));
+ assertNotNull(composite);
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ staxProcessor.write(composite, outputFactory.createXMLStreamWriter(bos));
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/java/xml/Calculator.composite b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/java/xml/Calculator.composite
new file mode 100644
index 0000000000..3de6410596
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/java/xml/Calculator.composite
@@ -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.
+-->
+<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:calc="http://sample.calculator"
+ targetNamespace="http://calc"
+ name="Calculator">
+
+ <service name="CalculatorService" promote="CalculatorServiceComponent">
+ <interface.java interface="calculator.CalculatorService"/>
+ </service>
+
+ <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/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/java/xml/CalculatorComponent.constrainingType b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/java/xml/CalculatorComponent.constrainingType
new file mode 100644
index 0000000000..dca38c9224
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/java/xml/CalculatorComponent.constrainingType
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<constrainingType xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:calc="http://calc"
+ targetNamespace="http://calc"
+ name="CalculatorComponent">
+
+ <service name="CalculatorService">
+ <interface.java interface="calculator.CalculatorService" />
+ </service>
+
+ <reference name="divideService">
+ <interface.java interface="calculator.DivideService" />
+ </reference>
+
+</constrainingType>
+ \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/java/xml/CalculatorImpl.componentType b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/java/xml/CalculatorImpl.componentType
new file mode 100644
index 0000000000..23ebf576e5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java-xml/src/test/resources/org/apache/tuscany/sca/interfacedef/java/xml/CalculatorImpl.componentType
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+-->
+<componentType xmlns="http://www.osoa.org/xmlns/sca/1.0">
+
+ <service name="CalculatorService">
+ <interface.java interface="calculator.CalculatorService" />
+ </service>
+
+ <reference name="divideService">
+ <interface.java interface="calculator.DivideService" />
+ </reference>
+
+</componentType>
+ \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java/LICENSE b/sca-java-1.x/branches/sca-android/modules/interface-java/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java/META-INF/README b/sca-java-1.x/branches/sca-android/modules/interface-java/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java/NOTICE b/sca-java-1.x/branches/sca-android/modules/interface-java/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java/pom.xml b/sca-java-1.x/branches/sca-android/modules/interface-java/pom.xml
new file mode 100644
index 0000000000..bab2576ea8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java/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.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-interface-java</artifactId>
+ <name>Apache Tuscany SCA Java Interface Model</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-extensibility</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-interface</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-sca-api</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.interface.java</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.interfacedef.java*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/DefaultJavaInterfaceFactory.java b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/DefaultJavaInterfaceFactory.java
new file mode 100644
index 0000000000..7853b597d3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/DefaultJavaInterfaceFactory.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef.java;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+import org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceFactoryImpl;
+import org.apache.tuscany.sca.interfacedef.java.impl.PolicyJavaInterfaceVisitor;
+import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+
+/**
+ * A factory for the Java interface model.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultJavaInterfaceFactory extends JavaInterfaceFactoryImpl implements JavaInterfaceFactory {
+ private ModelFactoryExtensionPoint modelFactoryExtensionPoint;
+ private boolean loadedVisitors;
+
+ public DefaultJavaInterfaceFactory() {
+ }
+
+ public DefaultJavaInterfaceFactory(ModelFactoryExtensionPoint modelFactoryExtensionPoint) {
+ this.modelFactoryExtensionPoint = modelFactoryExtensionPoint;
+ }
+
+ @Override
+ public List<JavaInterfaceVisitor> getInterfaceVisitors() {
+ loadVisitors();
+ return super.getInterfaceVisitors();
+ }
+
+ /**
+ * Load visitors declared under META-INF/services
+ */
+ @SuppressWarnings("unchecked")
+ private void loadVisitors() {
+ if (loadedVisitors)
+ return;
+
+ if (modelFactoryExtensionPoint != null) {
+ PolicyFactory policyFactory = modelFactoryExtensionPoint.getFactory(PolicyFactory.class);
+ if (policyFactory != null) {
+ addInterfaceVisitor(new PolicyJavaInterfaceVisitor(policyFactory));
+ }
+ }
+
+ // Get the databinding service declarations
+ Set<ServiceDeclaration> visitorDeclarations;
+ try {
+ visitorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(JavaInterfaceVisitor.class);
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+
+ // Load data bindings
+ for (ServiceDeclaration visitorDeclaration: visitorDeclarations) {
+ JavaInterfaceVisitor visitor;
+ try {
+ Class<JavaInterfaceVisitor> visitorClass = (Class<JavaInterfaceVisitor>)visitorDeclaration.loadClass();
+ visitor = visitorClass.newInstance();
+ } catch (ClassNotFoundException e) {
+ throw new IllegalArgumentException(e);
+ } catch (InstantiationException e) {
+ throw new IllegalArgumentException(e);
+ } catch (IllegalAccessException e) {
+ throw new IllegalArgumentException(e);
+ }
+ addInterfaceVisitor(visitor);
+ }
+
+ loadedVisitors = true;
+ }
+
+
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterface.java b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterface.java
new file mode 100644
index 0000000000..9c09ef50c2
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterface.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef.java;
+
+import javax.xml.namespace.QName;
+import org.apache.tuscany.sca.assembly.Base;
+import org.apache.tuscany.sca.interfacedef.Interface;
+
+/**
+ * Represents a Java interface.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface JavaInterface extends Interface, Base {
+
+ /**
+ * Returns the name of the Java interface class.
+ *
+ * @return the name of the Java interface class
+ */
+ String getName();
+
+ /**
+ * Sets the name of the Java interface class.
+ *
+ * @param className the name of the Java interface class
+ */
+ void setName(String className);
+
+ /**
+ * Returns the QName of the JAX-WS interface.
+ *
+ * @return the QName of the JAX-WS interface
+ */
+ QName getQName();
+
+ /**
+ * Sets the QName of the JAX-WS interface.
+ *
+ * @param interfaceName the QName of the JAX-WS interface
+ */
+ void setQName(QName interfaceName);
+
+ /**
+ * Returns the Java interface class.
+ *
+ * @return the Java interface class
+ */
+ Class<?> getJavaClass();
+
+ /**
+ * Sets the Java interface class.
+ *
+ * @param javaClass the Java interface class
+ */
+ void setJavaClass(Class<?> javaClass);
+
+ /**
+ * Returns the callback class specified in an @Callback annotation.
+ *
+ * @return the callback class specified in an @Callback annotation
+ */
+ Class<?> getCallbackClass();
+
+ /**
+ * Sets the callback class specified in an @Callback annotation.
+ *
+ * @param callbackClass the callback class specified in an @Callback annotation
+ */
+ void setCallbackClass(Class<?> callbackClass);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceContract.java b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceContract.java
new file mode 100644
index 0000000000..e3a84c63f0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceContract.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.interfacedef.java;
+
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+
+/**
+ * Represents a Java interface contract.
+ * JavaInterfaceContract
+ *
+ * @version $Rev$ $Date$
+ */
+public interface JavaInterfaceContract extends InterfaceContract {
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceFactory.java b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceFactory.java
new file mode 100644
index 0000000000..9225926269
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaInterfaceFactory.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef.java;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor;
+
+/**
+ * Factory for the Java interface model
+ *
+ * @version $Rev$ $Date$
+ */
+public interface JavaInterfaceFactory {
+
+ /**
+ * Creates a new Java interface model.
+ *
+ * @return
+ */
+ JavaInterface createJavaInterface();
+
+ /**
+ * Creates a new Java interface model from an interface class.
+ * @param interfaceClass the interface class to introspect.
+ * @return
+ */
+ JavaInterface createJavaInterface(Class<?> interfaceClass) throws InvalidInterfaceException;
+
+ /**
+ * Creates the contents of a Java interface model from an interface class.
+ * @param javaInterface the Java interface model
+ * @param interfaceClass the interface class to introspect.
+ * @return
+ */
+ void createJavaInterface(JavaInterface javaInterface, Class<?> interfaceClass) throws InvalidInterfaceException;
+
+ /**
+ * Creates a new Java interface contract.
+ *
+ * @return
+ */
+ JavaInterfaceContract createJavaInterfaceContract();
+
+ /**
+ * Registers the given visitor.
+ *
+ * @param visitor
+ */
+ void addInterfaceVisitor(JavaInterfaceVisitor visitor);
+
+ /**
+ * Deregisters the given visitor.
+ *
+ * @param visitor
+ */
+ void removeInterfaceVisitor(JavaInterfaceVisitor visitor);
+
+ /**
+ * Returns a list of interface visitors.
+ *
+ * @return
+ */
+ List<JavaInterfaceVisitor> getInterfaceVisitors();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaOperation.java b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaOperation.java
new file mode 100644
index 0000000000..e6cb35cc4b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/JavaOperation.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.interfacedef.java;
+
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.sca.interfacedef.Operation;
+
+/**
+ * Represents a Java operation.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface JavaOperation extends Operation {
+
+ /**
+ * Returns the Java method defining the operation.
+ * @return the Java method
+ */
+ Method getJavaMethod();
+
+ /**
+ * Sets the Java method defining the operation.
+ * @param method the Java method
+ */
+ void setJavaMethod(Method method);
+
+ /**
+ * Returns the JAX-WS @WebMethod action parameter.
+ * @return the action value
+ */
+ String getAction();
+
+ /**
+ * Sets the JAX-WS @WebMethod action parameter.
+ * @param action the action value
+ */
+ void setAction(String action);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceContractImpl.java b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceContractImpl.java
new file mode 100644
index 0000000000..d43ebe558b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceContractImpl.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef.java.impl;
+
+import org.apache.tuscany.sca.interfacedef.impl.InterfaceContractImpl;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
+
+/**
+ * Represents a Java interface contract.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaInterfaceContractImpl extends InterfaceContractImpl implements JavaInterfaceContract {
+
+ protected JavaInterfaceContractImpl() {
+ }
+
+ @Override
+ public JavaInterfaceContractImpl clone() throws CloneNotSupportedException {
+ return (JavaInterfaceContractImpl) super.clone();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java
new file mode 100644
index 0000000000..b1efd6e197
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceFactoryImpl.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef.java.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceContract;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor;
+
+/**
+ * A factory for the Java model.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class JavaInterfaceFactoryImpl implements JavaInterfaceFactory {
+
+ private List<JavaInterfaceVisitor> visitors = new ArrayList<JavaInterfaceVisitor>();
+ private JavaInterfaceIntrospectorImpl introspector;
+
+ public JavaInterfaceFactoryImpl() {
+ introspector = new JavaInterfaceIntrospectorImpl(this);
+ }
+
+ public JavaInterface createJavaInterface() {
+ return new JavaInterfaceImpl();
+ }
+
+ public JavaInterface createJavaInterface(Class<?> interfaceClass) throws InvalidInterfaceException {
+ JavaInterface javaInterface = createJavaInterface();
+ introspector.introspectInterface(javaInterface, interfaceClass);
+ return javaInterface;
+ }
+
+ public void createJavaInterface(JavaInterface javaInterface, Class<?> interfaceClass) throws InvalidInterfaceException {
+ introspector.introspectInterface(javaInterface, interfaceClass);
+ }
+
+ public JavaInterfaceContract createJavaInterfaceContract() {
+ return new JavaInterfaceContractImpl();
+ }
+
+ public void addInterfaceVisitor(JavaInterfaceVisitor extension) {
+ visitors.add(extension);
+ }
+
+ public void removeInterfaceVisitor(JavaInterfaceVisitor extension) {
+ visitors.remove(extension);
+ }
+
+ public List<JavaInterfaceVisitor> getInterfaceVisitors() {
+ return visitors;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceImpl.java b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceImpl.java
new file mode 100644
index 0000000000..42e45317b7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceImpl.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef.java.impl;
+
+import javax.xml.namespace.QName;
+import org.apache.tuscany.sca.interfacedef.impl.InterfaceImpl;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+
+/**
+ * Represents a Java interface.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaInterfaceImpl extends InterfaceImpl implements JavaInterface {
+
+ private String className;
+ private Class<?> javaClass;
+ private Class<?> callbackClass;
+ private QName qname;
+
+ protected JavaInterfaceImpl() {
+ }
+
+ public String getName() {
+ if (isUnresolved()) {
+ return className;
+ } else if (javaClass != null) {
+ return javaClass.getName();
+ } else {
+ return null;
+ }
+ }
+
+ public void setName(String className) {
+ if (!isUnresolved()) {
+ throw new IllegalStateException();
+ }
+ this.className = className;
+ }
+
+ public QName getQName() {
+ return qname;
+ }
+
+ public void setQName(QName interfacename) {
+ qname = interfacename;
+ }
+
+ public Class<?> getJavaClass() {
+ return javaClass;
+ }
+
+ public void setJavaClass(Class<?> javaClass) {
+ this.javaClass = javaClass;
+ }
+
+ public Class<?> getCallbackClass() {
+ return callbackClass;
+ }
+
+ public void setCallbackClass(Class<?> callbackClass) {
+ this.callbackClass = callbackClass;
+ }
+
+ @Override
+ public String toString() {
+ return getName();
+ }
+
+ @Override
+ public int hashCode() {
+ return String.valueOf(getName()).hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ } else if (obj instanceof JavaInterface) {
+ if (getName() != null) {
+ return getName().equals(((JavaInterface)obj).getName());
+ } else {
+ return ((JavaInterface)obj).getName() == null;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ return super.clone();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java
new file mode 100644
index 0000000000..b1198824fa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java
@@ -0,0 +1,258 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef.java.impl;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.interfacedef.ConversationSequence;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.InvalidCallbackException;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.interfacedef.InvalidOperationException;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.OverloadedOperationException;
+import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.JavaOperation;
+import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor;
+import org.apache.tuscany.sca.interfacedef.util.JavaXMLMapper;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+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 a Java interface introspector.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaInterfaceIntrospectorImpl {
+ public static final String IDL_INPUT = "idl:input";
+
+ private static final String UNKNOWN_DATABINDING = null;
+
+ private List<JavaInterfaceVisitor> visitors = new ArrayList<JavaInterfaceVisitor>();
+
+ public JavaInterfaceIntrospectorImpl(JavaInterfaceFactory javaFactory) {
+ this.visitors = javaFactory.getInterfaceVisitors();
+ }
+
+ public void introspectInterface(JavaInterface javaInterface, Class<?> clazz)
+ throws InvalidInterfaceException {
+ javaInterface.setJavaClass(clazz);
+
+ boolean remotable = clazz.isAnnotationPresent(Remotable.class);
+
+ // Consider @javax.ejb.Remote, java.rmi.Remote and javax.ejb.EJBObject
+ // equivalent to @Remotable
+ if (!remotable) {
+ for (Annotation annotation : clazz.getAnnotations()) {
+ if ("javax.ejb.Remote".equals(annotation.annotationType().getName())) {
+ remotable = true;
+ break;
+ }
+ }
+ }
+ if (!remotable) {
+ for (Class<?> superInterface : clazz.getInterfaces()) {
+ if (Remote.class == superInterface || "javax.ejb.EJBObject".equals(superInterface.getName())) {
+ remotable = true;
+ break;
+ }
+ }
+ }
+
+ javaInterface.setRemotable(remotable);
+
+ boolean conversational = clazz.isAnnotationPresent(Conversational.class);
+ javaInterface.setConversational(conversational);
+
+ Class<?> callbackClass = null;
+ org.osoa.sca.annotations.Callback callback = clazz.getAnnotation(org.osoa.sca.annotations.Callback.class);
+ if (callback != null && !Void.class.equals(callback.value())) {
+ callbackClass = callback.value();
+ if (remotable && !callbackClass.isAnnotationPresent(Remotable.class)) {
+ throw new InvalidCallbackException("Callback must be remotable on a remotable interface");
+ }
+ if (!remotable && callbackClass.isAnnotationPresent(Remotable.class)) {
+ throw new InvalidCallbackException("Callback must not be remotable on a local interface");
+ }
+ } else if (callback != null && Void.class.equals(callback.value())) {
+ throw new InvalidCallbackException("No callback interface specified on annotation");
+ }
+
+ javaInterface.setCallbackClass(callbackClass);
+
+ String ns = JavaXMLMapper.getNamespace(clazz);
+ javaInterface.getOperations().addAll(getOperations(clazz, remotable, conversational, ns));
+
+ for (JavaInterfaceVisitor extension : visitors) {
+ extension.visitInterface(javaInterface);
+ }
+ }
+
+ private Class<?>[] getActualTypes(Type[] types, Class<?>[] rawTypes, Map<String, Type> typeBindings) {
+ Class<?>[] actualTypes = new Class<?>[types.length];
+ for (int i = 0; i < actualTypes.length; i++) {
+ actualTypes[i] = getActualType(types[i], rawTypes[i], typeBindings);
+ }
+ return actualTypes;
+ }
+
+ private Class<?> getActualType(Type type, Class<?> rawType, Map<String, Type> typeBindings) {
+ if (type instanceof TypeVariable<?>) {
+ TypeVariable<?> typeVariable = (TypeVariable<?>)type;
+ type = typeBindings.get(typeVariable.getName());
+ if (type instanceof Class<?>) {
+ return (Class<?>)type;
+ }
+ }
+ return rawType;
+ }
+
+ private <T> List<Operation> getOperations(Class<T> clazz,
+ boolean remotable,
+ boolean conversational,
+ String ns) throws InvalidInterfaceException {
+
+ Set<Type> genericInterfaces = new HashSet<Type>();
+ for (Type t : clazz.getGenericInterfaces()) {
+ genericInterfaces.add(t);
+ }
+ Map<String, Type> typeBindings = new HashMap<String, Type>();
+ for (Type genericInterface : genericInterfaces) {
+ if (genericInterface instanceof ParameterizedType) {
+ ParameterizedType parameterizedType = (ParameterizedType)genericInterface;
+ TypeVariable<?>[] typeVariables = ((Class<?>)parameterizedType.getRawType()).getTypeParameters();
+ Type[] typeArguments = parameterizedType.getActualTypeArguments();
+ for (int i = 0; i < typeArguments.length; i++) {
+ typeBindings.put(typeVariables[i].getName(), typeArguments[i]);
+ }
+ }
+ }
+
+ Method[] methods = clazz.getMethods();
+ List<Operation> operations = new ArrayList<Operation>(methods.length);
+ Set<String> names = remotable ? new HashSet<String>() : null;
+ for (Method method : methods) {
+ if (method.getDeclaringClass() == Object.class) {
+ // Skip the methods on the Object.class
+ continue;
+ }
+ String name = method.getName();
+ if (remotable && names.contains(name)) {
+ throw new OverloadedOperationException(method);
+ }
+ if (remotable) {
+ names.add(name);
+ }
+
+ Class<?> returnType = getActualType(method.getGenericReturnType(), method.getReturnType(), typeBindings);
+ Class<?>[] parameterTypes =
+ getActualTypes(method.getGenericParameterTypes(), method.getParameterTypes(), typeBindings);
+ Class<?>[] faultTypes =
+ getActualTypes(method.getGenericExceptionTypes(), method.getExceptionTypes(), typeBindings);
+
+ boolean nonBlocking = method.isAnnotationPresent(OneWay.class);
+ if (nonBlocking) {
+ if (!(returnType == void.class)) {
+ throw new InvalidOperationException(
+ "Method should return 'void' when declared with an @OneWay annotation. " + method,
+ method);
+ }
+ if (!(faultTypes.length == 0)) {
+ throw new InvalidOperationException(
+ "Method should not declare exceptions with an @OneWay annotation. " + method,
+ method);
+ }
+ }
+
+ ConversationSequence conversationSequence = ConversationSequence.CONVERSATION_NONE;
+ if (method.isAnnotationPresent(EndsConversation.class)) {
+ if (!conversational) {
+ throw new InvalidOperationException(
+ "Method is marked as end conversation but contract is not conversational",
+ method);
+ }
+ conversationSequence = ConversationSequence.CONVERSATION_END;
+ } else if (conversational) {
+ conversationSequence = ConversationSequence.CONVERSATION_CONTINUE;
+ }
+
+ // Set outputType to null for void
+ XMLType xmlReturnType = new XMLType(new QName(ns, "return"), null);
+ DataType<XMLType> returnDataType =
+ returnType == void.class ? null : new DataTypeImpl<XMLType>(UNKNOWN_DATABINDING, returnType, method
+ .getGenericReturnType(), xmlReturnType);
+ List<DataType> paramDataTypes = new ArrayList<DataType>(parameterTypes.length);
+ Type[] genericParamTypes = method.getGenericParameterTypes();
+ for (int i = 0; i < parameterTypes.length; i++) {
+ Class paramType = parameterTypes[i];
+ XMLType xmlParamType = new XMLType(new QName(ns, "arg" + i), null);
+ paramDataTypes.add(new DataTypeImpl<XMLType>(UNKNOWN_DATABINDING, paramType, genericParamTypes[i],
+ xmlParamType));
+ }
+ List<DataType> faultDataTypes = new ArrayList<DataType>(faultTypes.length);
+ Type[] genericFaultTypes = method.getGenericExceptionTypes();
+ for (int i = 0; i < faultTypes.length; i++) {
+ Class<?> faultType = faultTypes[i];
+ // Only add checked exceptions
+ // JAXWS Specification v2.1 section 3.7 says RemoteException should not be mapped
+ if (Exception.class.isAssignableFrom(faultType) && (!RuntimeException.class.isAssignableFrom(faultType))
+ && (!RemoteException.class.isAssignableFrom(faultType))) {
+ XMLType xmlFaultType = new XMLType(new QName(ns, faultType.getSimpleName()), null);
+ DataType<XMLType> faultDataType =
+ new DataTypeImpl<XMLType>(UNKNOWN_DATABINDING, faultType, genericFaultTypes[i], xmlFaultType);
+ faultDataTypes.add(new DataTypeImpl<DataType>(UNKNOWN_DATABINDING, faultType, genericFaultTypes[i],
+ faultDataType));
+ }
+ }
+
+ DataType<List<DataType>> inputType =
+ new DataTypeImpl<List<DataType>>(IDL_INPUT, Object[].class, paramDataTypes);
+ JavaOperation operation = new JavaOperationImpl();
+ operation.setName(name);
+ operation.setInputType(inputType);
+ operation.setOutputType(returnDataType);
+ operation.setFaultTypes(faultDataTypes);
+ operation.setConversationSequence(conversationSequence);
+ operation.setNonBlocking(nonBlocking);
+ operation.setJavaMethod(method);
+ operations.add(operation);
+ }
+ return operations;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java
new file mode 100644
index 0000000000..2a9e3c5329
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtil.java
@@ -0,0 +1,173 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef.java.impl;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.JavaOperation;
+
+/**
+ * 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 JavaInterfaceUtil {
+
+ private JavaInterfaceUtil() {
+ }
+
+ /**
+ * 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 Method findMethod(Class<?> implClass, Operation operation) throws NoSuchMethodException {
+ String name = operation.getName();
+ if (operation instanceof JavaOperation) {
+ name = ((JavaOperation)operation).getJavaMethod().getName();
+ }
+ Interface interface1 = operation.getInterface();
+ int numParams = operation.getInputType().getLogical().size();
+ if (interface1 != null && interface1.isRemotable()) {
+ List<Method> matchingMethods = new ArrayList<Method>();
+ for (Method m : implClass.getMethods()) {
+ if (m.getName().equals(name) && m.getParameterTypes().length == numParams) {
+ matchingMethods.add(m);
+ }
+ }
+
+ // TUSCANY-2180 If there is only one method then we just match on the name
+ // (this is the same as the existing behaviour)
+ if (matchingMethods.size() == 1) {
+ return matchingMethods.get(0);
+ }
+ if (matchingMethods.size() > 1) {
+ // TUSCANY-2180 We need to check the parameter types too
+ Class<?>[] paramTypes = getPhysicalTypes(operation);
+ return implClass.getMethod(name, paramTypes);
+ }
+
+ // No matching method found
+ throw new NoSuchMethodException("No matching method for operation " + operation.getName()
+ + " is found on "
+ + implClass);
+ }
+ Class<?>[] paramTypes = getPhysicalTypes(operation);
+ return implClass.getMethod(name, paramTypes);
+ }
+
+ /**
+ * @Deprecated
+ */
+ private static Class<?>[] getPhysicalTypes(Operation operation) {
+ DataType<List<DataType>> inputType = operation.getInputType();
+ if (inputType == null) {
+ return new Class<?>[] {};
+ }
+ List<DataType> 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;
+ }
+
+ /**
+ * Determines if the given operation matches the given method
+ *
+ * @return true if the operation matches, false if does not
+ */
+ private static boolean match(Operation operation, Method method) {
+ Class<?>[] params = method.getParameterTypes();
+ DataType<List<DataType>> inputType = operation.getInputType();
+ List<DataType> 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;
+
+ }
+
+ private static String getPackageName(Class<?> cls) {
+ String name = cls.getName();
+ int index = name.lastIndexOf('.');
+ return index == -1 ? "" : name.substring(0, index);
+ }
+
+ public static String getNamespace(Class<?> cls) {
+ String packageName = getPackageName(cls);
+ if ("".equals(packageName)) {
+ return "";
+ }
+ StringBuffer ns = new StringBuffer("http://");
+ String[] names = packageName.split("\\.");
+ for (int i = names.length - 1; i >= 0; i--) {
+ ns.append(names[i]);
+ if (i != 0) {
+ ns.append('.');
+ }
+ }
+ ns.append('/');
+ return ns.toString();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaOperationImpl.java b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaOperationImpl.java
new file mode 100644
index 0000000000..4384213bf5
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaOperationImpl.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.interfacedef.java.impl;
+
+import java.lang.reflect.Method;
+
+import org.apache.tuscany.sca.interfacedef.impl.OperationImpl;
+import org.apache.tuscany.sca.interfacedef.java.JavaOperation;
+
+/**
+ * Represents a Java operation.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaOperationImpl extends OperationImpl implements JavaOperation {
+
+ private Method method;
+ private String action;
+
+ public Method getJavaMethod() {
+ return method;
+ }
+
+ public void setJavaMethod(Method method) {
+ this.method = method;
+ }
+
+ public String getAction() {
+ return action;
+ }
+
+ public void setAction(String action) {
+ this.action = action;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = super.hashCode();
+ result = prime * result + ((method == null) ? 0 : method.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (!super.equals(obj))
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ final JavaOperationImpl other = (JavaOperationImpl)obj;
+ if (method == null) {
+ if (other.method != null)
+ return false;
+ } else if (!method.equals(other.method))
+ return false;
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return method == null ? "null" : method.toGenericString();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/PolicyJavaInterfaceVisitor.java b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/PolicyJavaInterfaceVisitor.java
new file mode 100644
index 0000000000..ed00510a67
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/PolicyJavaInterfaceVisitor.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.interfacedef.java.impl;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaOperation;
+import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.osoa.sca.annotations.PolicySets;
+import org.osoa.sca.annotations.Requires;
+
+/**
+ * Processes an {@link org.osoa.sca.annotations.Requires} annotation
+ *
+ * @version $Rev$ $Date$
+ */
+public class PolicyJavaInterfaceVisitor implements JavaInterfaceVisitor {
+ private PolicyFactory policyFactory;
+
+ public PolicyJavaInterfaceVisitor(PolicyFactory policyFactory) {
+ super();
+ this.policyFactory = policyFactory;
+ }
+
+ private QName getQName(String intentName) {
+ QName qname;
+ if (intentName.startsWith("{")) {
+ int i = intentName.indexOf('}');
+ if (i != -1) {
+ qname = new QName(intentName.substring(1, i), intentName.substring(i + 1));
+ } else {
+ qname = new QName("", intentName);
+ }
+ } else {
+ qname = new QName("", intentName);
+ }
+ return qname;
+ }
+
+ /**
+ * Read policy intents on the given interface or class
+ * @param clazz
+ * @param requiredIntents
+ */
+ private void readIntentsAndPolicySets(Class<?> clazz, List<Intent> requiredIntents, List<PolicySet> policySets) {
+ Requires intentAnnotation = clazz.getAnnotation(Requires.class);
+ if (intentAnnotation != null) {
+ String[] intentNames = intentAnnotation.value();
+ if (intentNames.length != 0) {
+ for (String intentName : intentNames) {
+
+ // Add each intent to the list
+ Intent intent = policyFactory.createIntent();
+ intent.setName(getQName(intentName));
+ requiredIntents.add(intent);
+ }
+ }
+ }
+
+ PolicySets policySetAnnotation = clazz.getAnnotation(PolicySets.class);
+ if (policySetAnnotation != null) {
+ String[] policySetNames = policySetAnnotation.value();
+ if (policySetNames.length != 0) {
+ for (String policySetName : policySetNames) {
+
+ // Add each intent to the list
+ PolicySet policySet = policyFactory.createPolicySet();
+ policySet.setName(getQName(policySetName));
+ policySets.add(policySet);
+ }
+ }
+ }
+ }
+
+ private void readIntents(Requires intentAnnotation, List<Intent> requiredIntents) {
+ //Requires intentAnnotation = method.getAnnotation(Requires.class);
+ if (intentAnnotation != null) {
+ String[] intentNames = intentAnnotation.value();
+ if (intentNames.length != 0) {
+ //Operation operation = assemblyFactory.createOperation();
+ //operation.setName(method.getName());
+ //operation.setUnresolved(true);
+ for (String intentName : intentNames) {
+
+ // Add each intent to the list, associated with the
+ // operation corresponding to the annotated method
+ Intent intent = policyFactory.createIntent();
+ intent.setName(getQName(intentName));
+ //intent.getOperations().add(operation);
+ requiredIntents.add(intent);
+ }
+ }
+ }
+ }
+
+ private void readPolicySets(PolicySets policySetAnnotation, List<PolicySet> policySets) {
+ if (policySetAnnotation != null) {
+ String[] policySetNames = policySetAnnotation.value();
+ if (policySetNames.length != 0) {
+ //Operation operation = assemblyFactory.createOperation();
+ //operation.setName(method.getName());
+ //operation.setUnresolved(true);
+ for (String policySetName : policySetNames) {
+ // Add each intent to the list, associated with the
+ // operation corresponding to the annotated method
+ PolicySet policySet = policyFactory.createPolicySet();
+ policySet.setName(getQName(policySetName));
+ //intent.getOperations().add(operation);
+ policySets.add(policySet);
+ }
+ }
+ }
+ }
+
+ public void visitInterface(JavaInterface javaInterface) throws InvalidInterfaceException {
+
+ if (javaInterface.getJavaClass() != null) {
+ readIntentsAndPolicySets(javaInterface.getJavaClass(), javaInterface.getRequiredIntents(), javaInterface
+ .getPolicySets());
+
+ // Read intents on the service interface methods
+ List<Operation> operations = javaInterface.getOperations();
+ for (Operation op : operations) {
+ JavaOperation operation = (JavaOperation)op;
+ Method method = operation.getJavaMethod();
+ if (method.getAnnotation(Requires.class) != null || method.getAnnotation(PolicySets.class) != null) {
+ readIntents(method.getAnnotation(Requires.class), op.getRequiredIntents());
+ readPolicySets(method.getAnnotation(PolicySets.class), op.getPolicySets());
+ }
+ }
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/introspect/JavaInterfaceVisitor.java b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/introspect/JavaInterfaceVisitor.java
new file mode 100644
index 0000000000..3bc03a528e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/introspect/JavaInterfaceVisitor.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef.java.introspect;
+
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+
+/**
+ * Implementations introspect metadata on a Java interface, populating the
+ * corresponding {@link JavaInterface}
+ *
+ * @version $Rev$ $Date$
+ */
+public interface JavaInterfaceVisitor {
+
+ /**
+ * Visit a java interface
+ * @param javaInterface
+ * @throws InvalidInterfaceException
+ */
+ void visitInterface(JavaInterface javaInterface) throws InvalidInterfaceException;
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory
new file mode 100644
index 0000000000..5ba12ec137
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtilDuplicateRemotableTestCase.java b/sca-java-1.x/branches/sca-android/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtilDuplicateRemotableTestCase.java
new file mode 100644
index 0000000000..14b0577f65
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtilDuplicateRemotableTestCase.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.sca.interfacedef.java.impl;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.OverloadedOperationException;
+import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
+import org.apache.tuscany.sca.interfacedef.impl.InterfaceImpl;
+import org.apache.tuscany.sca.interfacedef.impl.OperationImpl;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.osoa.sca.annotations.Remotable;
+
+/**
+ * This test case will test that a Component that has multiple Remotable interfaces
+ * that contain methods with the same name will correctly select the right method.
+ *
+ * @version $Rev$ $Date$
+ */
+public class JavaInterfaceUtilDuplicateRemotableTestCase extends TestCase {
+
+ /**
+ * Test to get the getTime() method from the LocalTimeService
+ *
+ * @throws Exception Test failed
+ */
+ public void testLocalTimeServiceGetTime() throws Exception {
+ doTestLocalTimeServiceGetTime(LocalTimeService.class);
+ }
+
+ /**
+ * Test to get the getTime() method from the LocalTimeService interface from
+ * the specified class
+ *
+ * @param timeServiceClass The class that implements the LocalTimeService
+ * @throws Exception Test failed
+ */
+ private void doTestLocalTimeServiceGetTime(Class timeServiceClass) throws Exception {
+ // Add a getTime() method
+ Operation operation = newOperation("getTime", LocalTimeService.class);
+
+ Method method = JavaInterfaceUtil.findMethod(timeServiceClass, operation);
+ assertEquals("getTime", method.getName());
+ assertEquals(0, method.getParameterTypes().length);
+ }
+
+ /**
+ * Test to get the getTime(String) method from the WorldTimeService
+ *
+ * @throws Exception Test failed
+ */
+ public void testWorldTimeServiceGetTime() throws Exception {
+ doTestWorldTimeServiceGetTime(WorldTimeService.class);
+ }
+
+ /**
+ * Test to get the getTime(String) method from the WorldTimeService interface from
+ * the specified class
+ *
+ * @param timeServiceClass The class that implements the WorldTimeService
+ * @throws Exception Test failed
+ */
+ private void doTestWorldTimeServiceGetTime(Class timeServiceClass) throws Exception {
+ // Add a getTime(String) method
+ Operation operation = newOperation("getTime", WorldTimeService.class, String.class);
+
+ Method method = JavaInterfaceUtil.findMethod(timeServiceClass, operation);
+ assertEquals("getTime", method.getName());
+ assertEquals(1, method.getParameterTypes().length);
+ assertEquals(String.class, method.getParameterTypes()[0]);
+ }
+
+ /**
+ * Test to get the getTime(int) method from the GMTTimeService
+ *
+ * @throws Exception Test failed
+ */
+ public void testGMTTimeServiceGetTime() throws Exception {
+ doTestGMTTimeServiceGetTime(GMTTimeService.class);
+ }
+
+ /**
+ * Test to get the getTime(int) method from the GMTTimeService interface from
+ * the specified class
+ *
+ * @param timeServiceClass The class that implements the WorldTimeService
+ * @throws Exception Test failed
+ */
+ private void doTestGMTTimeServiceGetTime(Class timeServiceClass) throws Exception {
+ // Add a getTime(String) method
+ Operation operation = newOperation("getTime", GMTTimeService.class, Integer.TYPE);
+
+ Method method = JavaInterfaceUtil.findMethod(timeServiceClass, operation);
+ assertEquals("getTime", method.getName());
+ assertEquals(1, method.getParameterTypes().length);
+ assertEquals(Integer.TYPE, method.getParameterTypes()[0]);
+ }
+
+
+ /**
+ * Test to get the getTime() method from the LocalTimeService on the
+ * TimeServiceImpl class
+ *
+ * @throws Exception Test failed
+ */
+ public void testLocalTimeServiceGetTimeFromTimeServiceImpl() throws Exception {
+ doTestLocalTimeServiceGetTime(TimeServiceImpl.class);
+ }
+
+ /**
+ * Test to get the getTime(String) method from the WorldTimeService on the
+ * TimeServiceImpl class
+ *
+ * @throws Exception Test failed
+ */
+ public void testWorldTimeServiceGetTimeFromTimeServiceImpl() throws Exception {
+ doTestWorldTimeServiceGetTime(TimeServiceImpl.class);
+ }
+
+ /**
+ * Test to get the getTime(int) method from the GMTTimeService
+ *
+ * @throws Exception Test failed
+ */
+ public void testGMTTimeServiceGetTimeFromTimeServiceImpl() throws Exception {
+ doTestGMTTimeServiceGetTime(TimeServiceImpl.class);
+ }
+
+ /**
+ * Creates a new operation with the specified name and parameter types
+ *
+ * @param name The name of the operation
+ * @param operationInterface The interface to which the operation belongs
+ * @param parameterTypes The types of the parameters for this operation
+ * @return An operation with the specified name and parameter types
+ */
+ private static Operation newOperation(String name, Class operationInterface, Class... parameterTypes) {
+ // Create and set the operation name
+ Operation operation = new OperationImpl();
+ operation.setName(name);
+
+ // Make the operation remotable
+ Interface iface = new InterfaceImpl();
+ iface.setRemotable(true);
+ operation.setInterface(iface);
+
+ // Construct the parameters
+ List<DataType> types = new ArrayList<DataType>();
+ DataType<List<DataType>> inputType = new DataTypeImpl<List<DataType>>(Object[].class, types);
+ for (Class parameterType : parameterTypes) {
+ DataType type = new DataTypeImpl<Class>(parameterType, Object.class);
+ types.add(type);
+ }
+ operation.setInputType(inputType);
+
+ // Return the created operation
+ return operation;
+ }
+
+ /**
+ * Test case that validates that a @Remotable interface with Overloaded operations
+ * is detected.
+ *
+ * This test case is for TUSCANY-2194
+ */
+ public void testDuplicateOpeartionOnRemotableInterface()
+ {
+ JavaInterfaceFactory javaFactory = new DefaultJavaInterfaceFactory();
+ JavaInterfaceIntrospectorImpl introspector = new JavaInterfaceIntrospectorImpl(javaFactory);
+ JavaInterfaceImpl javaInterface = new JavaInterfaceImpl();
+
+ try {
+ introspector.introspectInterface(javaInterface, DuplicateMethodOnRemotableInterface.class);
+ Assert.fail("Should have thrown an exception as @Remotable interface has overloaded methods");
+ } catch (OverloadedOperationException ex) {
+ // As expected
+ // Make sure that the class and method names are in the exception
+ String exMsg = ex.toString();
+ Assert.assertTrue("Method name missing from exception", exMsg.indexOf("aDuplicateMethod") != -1);
+ Assert.assertTrue("Class name missing from exception",
+ exMsg.indexOf(DuplicateMethodOnRemotableInterface.class.getName()) != -1);
+ } catch (InvalidInterfaceException ex) {
+ // Should have thrown OverloadedOperationException
+ Assert.fail("Should have thrown an OverloadedOperationException but threw " + ex);
+ }
+ }
+
+
+ /**
+ * Sample @Remotable interface that has an overloaded operation which is not
+ * allowed according to the SCA Assembly Specification.
+ */
+ @Remotable
+ private interface DuplicateMethodOnRemotableInterface {
+ void aNonDuplicateMethod();
+ void aDuplicateMethod();
+ void aDuplicateMethod(String aParam);
+ }
+
+
+ /**
+ * Sample interface needed for the unit tests
+ */
+ @Remotable
+ private interface LocalTimeService {
+
+ /**
+ * Gets the local time
+ *
+ * @return The Local Time
+ */
+ String getTime();
+ }
+
+ /**
+ * Sample interface needed for the unit tests
+ */
+ @Remotable
+ private interface WorldTimeService {
+
+ /**
+ * Gets the time in the specified TimeZone
+ *
+ * @param timeZone A Time Zone
+ *
+ * @return The time in the specified TimeZone
+ */
+ String getTime(String timeZone);
+ }
+
+ /**
+ * Sample interface needed for the unit tests
+ */
+ @Remotable
+ private interface GMTTimeService {
+
+ /**
+ * Gets the time with the specified GMT offset
+ *
+ * @param gmtOffset A GMT offset in hours
+ *
+ * @return The time with the specified GMT offset
+ */
+ String getTime(int gmtOffset);
+ }
+
+ /**
+ * Sample implementation class that implements the three @Remotable interfaces
+ */
+ private class TimeServiceImpl implements LocalTimeService, WorldTimeService, GMTTimeService {
+ /**
+ * Gets the local time
+ *
+ * @return The Local Time
+ */
+ public String getTime() {
+ return "The current local time";
+ }
+
+ /**
+ * Gets the time in the specified TimeZone
+ *
+ * @param timeZone A Time Zone
+ *
+ * @return The time in the specified TimeZone
+ */
+ public String getTime(String timeZone) {
+ return "The current time in TimeZone " + timeZone;
+ }
+
+ /**
+ * Gets the time with the specified GMT offset
+ *
+ * @param gmtOffset A GMT offset in hours
+ *
+ * @return The time with the specified GMT offset
+ */
+ public String getTime(int gmtOffset) {
+ return "The current time with GMT offset of " + gmtOffset;
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtilTestCase.java b/sca-java-1.x/branches/sca-android/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtilTestCase.java
new file mode 100644
index 0000000000..66f98adce3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceUtilTestCase.java
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef.java.impl;
+
+import static org.apache.tuscany.sca.interfacedef.java.impl.JavaInterfaceUtil.findOperation;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
+import org.apache.tuscany.sca.interfacedef.impl.OperationImpl;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaInterfaceUtilTestCase 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());
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ Operation operation = newOperation("foo");
+ List<DataType> types = new ArrayList<DataType>();
+ DataType<List<DataType>> inputType = new DataTypeImpl<List<DataType>>(Object[].class, types);
+ operation.setInputType(inputType);
+
+ operations = new ArrayList<Operation>();
+ operations.add(operation);
+
+ types = new ArrayList<DataType>();
+ inputType = new DataTypeImpl<List<DataType>>(Object[].class, types);
+ DataType type = new DataTypeImpl<Class>(String.class, Object.class);
+ types.add(type);
+ operation = newOperation("foo");
+ operation.setInputType(inputType);
+ operations.add(operation);
+
+ types = new ArrayList<DataType>();
+ type = new DataTypeImpl<Class>(String.class, Object.class);
+ DataType type2 = new DataTypeImpl<Class>(String.class, Object.class);
+ types.add(type);
+ types.add(type2);
+ inputType = new DataTypeImpl<List<DataType>>(Object[].class, types);
+ operation = newOperation("foo");
+ operation.setInputType(inputType);
+ operations.add(operation);
+
+ types = new ArrayList<DataType>();
+ type = new DataTypeImpl<Class>(Integer.class, Object.class);
+ types.add(type);
+ inputType = new DataTypeImpl<List<DataType>>(Object[].class, types);
+ operation = newOperation("foo");
+ operation.setInputType(inputType);
+ operations.add(operation);
+
+ types = new ArrayList<DataType>();
+ type = new DataTypeImpl<Class>(Integer.TYPE, Object.class);
+ types.add(type);
+ inputType = new DataTypeImpl<List<DataType>>(Object[].class, types);
+ operation = newOperation("foo");
+ operation.setInputType(inputType);
+ operations.add(operation);
+
+ }
+
+ private interface Foo {
+ void foo();
+
+ void foo(String foo);
+
+ void foo(int b);
+ }
+
+ private static Operation newOperation(String name) {
+ Operation operation = new OperationImpl();
+ operation.setName(name);
+ return operation;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/ConversationalIntrospectionTestCase.java b/sca-java-1.x/branches/sca-android/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/ConversationalIntrospectionTestCase.java
new file mode 100644
index 0000000000..f90a5cb8a1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/ConversationalIntrospectionTestCase.java
@@ -0,0 +1,98 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef.java.introspection.impl;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.interfacedef.ConversationSequence;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.InvalidOperationException;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.osoa.sca.annotations.Conversational;
+import org.osoa.sca.annotations.EndsConversation;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class ConversationalIntrospectionTestCase extends TestCase {
+ private JavaInterfaceFactory javaFactory;
+
+ @Override
+ protected void setUp() throws Exception {
+ javaFactory = new DefaultJavaInterfaceFactory();
+ }
+
+ private Operation getOperation(Interface i, String name) {
+ for (Operation op : i.getOperations()) {
+ if (op.getName().equals(name)) {
+ return op;
+ }
+ }
+ return null;
+ }
+
+ public void testServiceContractConversationalInformationIntrospection() throws Exception {
+ Interface i = javaFactory.createJavaInterface(Foo.class);
+ assertNotNull(i);
+ assertTrue(i.isConversational());
+ ConversationSequence seq = getOperation(i, "operation").getConversationSequence();
+ assertEquals(ConversationSequence.CONVERSATION_CONTINUE, seq);
+ seq = getOperation(i, "endOperation").getConversationSequence();
+ assertEquals(ConversationSequence.CONVERSATION_END, seq);
+ }
+
+ public void testBadServiceContract() throws Exception {
+ try {
+ javaFactory.createJavaInterface(BadFoo.class);
+ fail();
+ } catch (InvalidOperationException e) {
+ // expected
+ }
+ }
+
+ public void testNonConversationalInformationIntrospection() throws Exception {
+ Interface i = javaFactory.createJavaInterface(NonConversationalFoo.class);
+ assertFalse(i.isConversational());
+ ConversationSequence seq = getOperation(i, "operation")
+ .getConversationSequence();
+ assertEquals(ConversationSequence.CONVERSATION_NONE, 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/sca-java-1.x/branches/sca-android/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/JavaInterfaceProcessorRegistryImplTestCase.java b/sca-java-1.x/branches/sca-android/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/JavaInterfaceProcessorRegistryImplTestCase.java
new file mode 100644
index 0000000000..14ac8b0134
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/JavaInterfaceProcessorRegistryImplTestCase.java
@@ -0,0 +1,107 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef.java.introspection.impl;
+
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expectLastCall;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+
+import java.io.IOException;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.InvalidInterfaceException;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.introspect.JavaInterfaceVisitor;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.easymock.EasyMock;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaInterfaceProcessorRegistryImplTestCase extends TestCase {
+ private JavaInterfaceFactory factory;
+
+ @SuppressWarnings("unchecked")
+ public void testSimpleInterface() throws InvalidInterfaceException {
+ JavaInterface intf = factory.createJavaInterface(Simple.class);
+
+ assertEquals(Simple.class, intf.getJavaClass());
+ List<Operation> operations = intf.getOperations();
+ assertEquals(1, operations.size());
+ Operation baseInt = operations.get(0);
+ assertEquals("baseInt", baseInt.getName());
+
+ QName element = new QName("http://impl.introspection.java.interfacedef.sca.tuscany.apache.org/", "return");
+
+ DataType<XMLType> returnType = baseInt.getOutputType();
+ assertEquals(Integer.TYPE, returnType.getPhysical());
+ assertEquals(element, returnType.getLogical().getElementName());
+
+ List<DataType> parameterTypes = baseInt.getInputType().getLogical();
+ assertEquals(1, parameterTypes.size());
+ DataType<XMLType> arg0 = parameterTypes.get(0);
+ assertEquals(Integer.TYPE, arg0.getPhysical());
+
+ element = new QName("http://impl.introspection.java.interfacedef.sca.tuscany.apache.org/", "arg0");
+ assertEquals(element, arg0.getLogical().getElementName());
+
+ List<DataType> faultTypes = baseInt.getFaultTypes();
+ assertEquals(1, faultTypes.size());
+ DataType<DataType<XMLType>> fault0 = faultTypes.get(0);
+ assertEquals(IOException.class, fault0.getPhysical());
+ element = new QName("http://impl.introspection.java.interfacedef.sca.tuscany.apache.org/", "IOException");
+ assertEquals(element, fault0.getLogical().getLogical().getElementName());
+ }
+
+ public void testUnregister() throws Exception {
+ JavaInterfaceVisitor extension = createMock(JavaInterfaceVisitor.class);
+ extension.visitInterface(EasyMock.isA(JavaInterface.class));
+ expectLastCall().once();
+ replay(extension);
+ factory.addInterfaceVisitor(extension);
+ factory.createJavaInterface(Base.class);
+ factory.removeInterfaceVisitor(extension);
+ factory.createJavaInterface(Base.class);
+ verify(extension);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ factory = new DefaultJavaInterfaceFactory();
+
+ }
+
+ private static interface Base {
+ int baseInt(int param) throws IllegalArgumentException, IOException;
+ }
+
+ private static interface Simple extends Base {
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/PolicyProcessorTestCase.java b/sca-java-1.x/branches/sca-android/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/PolicyProcessorTestCase.java
new file mode 100644
index 0000000000..5a454f176c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface-java/src/test/java/org/apache/tuscany/sca/interfacedef/java/introspection/impl/PolicyProcessorTestCase.java
@@ -0,0 +1,108 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef.java.introspection.impl;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.interfacedef.java.DefaultJavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterface;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.interfacedef.java.impl.PolicyJavaInterfaceVisitor;
+import org.apache.tuscany.sca.policy.DefaultPolicyFactory;
+import org.osoa.sca.annotations.PolicySets;
+import org.osoa.sca.annotations.Requires;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PolicyProcessorTestCase extends TestCase {
+ private JavaInterfaceFactory factory = new DefaultJavaInterfaceFactory();
+ private PolicyJavaInterfaceVisitor policyProcessor;
+
+ public void testInterfaceLevel() throws Exception {
+ JavaInterface type = factory.createJavaInterface(Interface1.class);
+ policyProcessor.visitInterface(type);
+ assertEquals(1, type.getRequiredIntents().size());
+ assertEquals(1, type.getPolicySets().size());
+ }
+
+ public void testMethodLevel() throws Exception {
+ JavaInterface type = factory.createJavaInterface(Interface2.class);
+ policyProcessor.visitInterface(type);
+ assertEquals(0, type.getRequiredIntents().size());
+ assertEquals(1, type.getOperations().get(0).getRequiredIntents().size());
+ assertEquals(1, type.getOperations().get(1).getRequiredIntents().size());
+ assertEquals(0, type.getPolicySets().size());
+ assertEquals(1, type.getOperations().get(0).getPolicySets().size());
+ assertEquals(1, type.getOperations().get(1).getPolicySets().size());
+ }
+
+ public void testInterfaceAndMethodLevel() throws Exception {
+ JavaInterface type = factory.createJavaInterface(Interface3.class);
+ policyProcessor.visitInterface(type);
+ assertEquals(1, type.getRequiredIntents().size());
+ assertEquals(1, type.getOperations().get(0).getRequiredIntents().size());
+ assertEquals(1, type.getOperations().get(1).getRequiredIntents().size());
+ assertEquals(1, type.getPolicySets().size());
+ assertEquals(1, type.getOperations().get(0).getPolicySets().size());
+ assertEquals(1, type.getOperations().get(1).getPolicySets().size());
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ policyProcessor = new PolicyJavaInterfaceVisitor(new DefaultPolicyFactory());
+ }
+
+ // @Remotable
+ @Requires( {"transaction.global"})
+ @PolicySets( {"{http://ns1}PS1"})
+ private interface Interface1 {
+ int method1();
+
+ int method2();
+
+ int method3();
+
+ int method4();
+ }
+
+ private interface Interface2 {
+ @Requires( {"transaction.global"})
+ @PolicySets( {"{http://ns1}PS1"})
+ int method1();
+
+ @Requires( {"transaction.local"})
+ @PolicySets( {"{http://ns1}PS2"})
+ int method2();
+ }
+
+ @Requires( {"transaction.global.Interface6"})
+ @PolicySets( {"{http://ns1}PS1"})
+ private interface Interface3 {
+ @Requires( {"transaction.global.Interface6.method1"})
+ @PolicySets( {"{http://ns1}PS2"})
+ int method1();
+
+ @Requires( {"transaction.local.Interface6.method2"})
+ @PolicySets( {"{http://ns1}PS3"})
+ int method2();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/LICENSE b/sca-java-1.x/branches/sca-android/modules/interface/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/META-INF/README b/sca-java-1.x/branches/sca-android/modules/interface/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/NOTICE b/sca-java-1.x/branches/sca-android/modules/interface/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/pom.xml b/sca-java-1.x/branches/sca-android/modules/interface/pom.xml
new file mode 100644
index 0000000000..7c75e66767
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/pom.xml
@@ -0,0 +1,57 @@
+<?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.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-interface</artifactId>
+ <name>Apache Tuscany SCA Interface Model</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-policy</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.interface</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.interfacedef*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/ConversationSequence.java b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/ConversationSequence.java
new file mode 100644
index 0000000000..247a432330
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/ConversationSequence.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.interfacedef;
+
+/**
+ * Enum of the Conversation Sequence values.
+ *
+ * @version $Rev$ $Date$
+ */
+public enum ConversationSequence {
+ CONVERSATION_NONE, CONVERSATION_START, CONVERSATION_CONTINUE, CONVERSATION_END
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/DataType.java b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/DataType.java
new file mode 100644
index 0000000000..1f5620c0b9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/DataType.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef;
+
+import java.lang.reflect.Type;
+
+/**
+ * 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 interface DataType<L> extends Cloneable {
+ /**
+ * Set the java type for the data
+ * @param cls
+ */
+ void setPhysical(Class<?> cls);
+
+ /**
+ * Returns the physical type used by the runtime.
+ *
+ * @return the physical type used by the runtime
+ */
+ Class<?> getPhysical();
+
+ /**
+ * Get the java generic type
+ * @return The java generic type
+ */
+ Type getGenericType();
+
+ /**
+ * Set the java generic type
+ * @param genericType
+ */
+ void setGenericType(Type genericType);
+
+ /**
+ * 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 Class identifies a Java type by name and
+ * ClassLoader; this includes Java Classes as they are specializations of
+ * Type</li>
+ * <li>a XMLType identifies an XML type by local name and
+ * namespace</li>
+ * </ul>
+ *
+ * @return the logical type name
+ */
+ L getLogical();
+
+ /**
+ * Get the databinding for the given data type
+ * @return the databinding
+ */
+ String getDataBinding();
+
+ /**
+ * Set the databinding for the given data type
+ * @param dataBinding the dataBinding to set
+ */
+ void setDataBinding(String dataBinding);
+
+ /**
+ * Clone a data type
+ * @return The cloned data type
+ * @throws CloneNotSupportedException
+ */
+ Object clone() throws CloneNotSupportedException;
+
+ /**
+ * Set the logical type of the data type
+ * @param logical the logical to set
+ */
+ void setLogical(L logical);
+
+ /**
+ * Get the databinding-specific metadata
+ * @param type The java type of the metadata
+ * @return the databinding-specific metadata
+ */
+ <T> T getMetaData(Class<T> type);
+ /**
+ * Set the databinding-specific metadata
+ * @param type The java type of the metadata
+ * @param metaData the databinding-specific metadata, such as SDO's commonj.sdo.Type or
+ * JAXB's javax.xml.bind.JAXBContext
+ */
+ <T> void setMetaData(Class<T> type, T metaData);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/FaultExceptionMapper.java b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/FaultExceptionMapper.java
new file mode 100644
index 0000000000..70f6d5b403
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/FaultExceptionMapper.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.interfacedef;
+
+/**
+ * This interface represents the mapping between WSDL faults and Java exceptions
+ *
+ * @version $Rev$ $Date$
+ */
+@SuppressWarnings("unchecked")
+public interface FaultExceptionMapper {
+ /**
+ * Introspect an exception class to find out the fault data type following the WSDL2Java
+ * mapping rules. The result will be populated into the logical type of the exception data
+ * type
+ *
+ * @param exceptionDataType The data type representing a java exception class
+ * @param operation TODO
+ * @param generatingFaultBean If JAXWS Section 3.7 Fault Bean will be generated
+ * @return true if the introspection can recognize the exception data type
+ */
+ boolean introspectFaultDataType(DataType<DataType> exceptionDataType, Operation operation, boolean generatingFaultBean);
+
+ /**
+ * Create a java exception to wrap the fault data
+ *
+ * @param exceptionType The DataType for the exception
+ * @param message message for the exception
+ * @param faultInfo The fault data
+ * @param cause of the exception
+ * @param operation TODO
+ * @return An instance of java exception to represent the fault
+ */
+ Throwable wrapFaultInfo(DataType<DataType> exceptionType, String message, Object faultInfo, Throwable cause, Operation operation);
+
+ /**
+ * Retrieve the fault info from a java exception
+ *
+ * @param exception The java exception that represents the fault data
+ * @param faultBeanClass
+ * @param operation TODO
+ * @return The fault data
+ */
+ Object getFaultInfo(Throwable exception, Class<?> faultBeanClass, Operation operation);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/IncompatibleInterfaceContractException.java b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/IncompatibleInterfaceContractException.java
new file mode 100644
index 0000000000..179dc1755e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/IncompatibleInterfaceContractException.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.interfacedef;
+
+/**
+ * Denotes incompatible service contracts for a wire
+ *
+ * @version $Rev$ $Date$
+ */
+public class IncompatibleInterfaceContractException extends Exception {
+ private static final long serialVersionUID = 5127478601823295587L;
+ private final InterfaceContract source;
+ private final InterfaceContract target;
+ private final Operation sourceOperation;
+ private final Operation targetOperation;
+
+ public IncompatibleInterfaceContractException(String message, InterfaceContract source, InterfaceContract target) {
+ super(message);
+ this.source = source;
+ this.target = target;
+ this.sourceOperation = null;
+ this.targetOperation = null;
+ }
+
+ public IncompatibleInterfaceContractException(String message,
+ InterfaceContract source,
+ InterfaceContract target,
+ Operation sourceOperation,
+ Operation targetOperation) {
+ super(message);
+ this.source = source;
+ this.target = target;
+ this.sourceOperation = sourceOperation;
+ this.targetOperation = targetOperation;
+ }
+
+ public InterfaceContract getTarget() {
+ return target;
+ }
+
+ public InterfaceContract getSource() {
+ return source;
+ }
+
+ public Operation getSourceOperation() {
+ return sourceOperation;
+ }
+
+ public Operation getTargetOperation() {
+ return targetOperation;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Interface.java b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Interface.java
new file mode 100644
index 0000000000..f9de645a6e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Interface.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+
+/**
+ * Represents a service interface. This interface will typically be extended to
+ * support concrete interface type systems, such as Java interfaces, WSDL 1.1
+ * portTypes and WSDL 2.0 interfaces.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Interface extends Cloneable, PolicySetAttachPoint {
+
+ /**
+ * Returns true if the interface is a remotable interface..
+ *
+ * @return true if the interface is a remotable interface
+ */
+ boolean isRemotable();
+
+ /**
+ * Sets whether the interface is a remotable or local interface.
+ *
+ * @param remotable indicates whether the interface is remotable or local
+ */
+ void setRemotable(boolean remotable);
+
+
+ // FIXME: [rfeng] We need to re-consider the conversational as an intent
+ /**
+ * Test if the interface is conversational
+ * @return
+ */
+ boolean isConversational();
+
+ /**
+ * Set whether the interface is conversational
+ * @param conversational
+ */
+ void setConversational(boolean conversational);
+
+ /**
+ * Returns the operations defined on this interface.
+ *
+ * @return the operations defined on this interface
+ */
+ List<Operation> getOperations();
+
+ /**
+ * Set the databinding for the interface
+ * @param dataBinding
+ * @deprecated Please use resetDataBinding
+ */
+ @Deprecated
+ void setDefaultDataBinding(String dataBinding);
+
+ /**
+ * Reset the databinding for the interface
+ * @param dataBinding
+ */
+ void resetDataBinding(String dataBinding);
+
+ /**
+ * Returns true if the Interface is dynamic.
+ *
+ * @return true if the Interface is dynamic.
+ */
+ boolean isDynamic();
+
+ /**
+ * Implementations must support cloning.
+ */
+ Object clone() throws CloneNotSupportedException;
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContract.java b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContract.java
new file mode 100644
index 0000000000..568a6c595c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContract.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.interfacedef;
+
+
+/**
+ * Interface contracts define one or more business functions. These business
+ * functions are provided by services and are used by references.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface InterfaceContract extends Cloneable {
+
+ /**
+ * Returns the interface definition representing the interface for
+ * invocations from the requestor to the provider.
+ *
+ * @return the interface definition representing the interface for
+ * invocations from the requestor to the provider
+ */
+ Interface getInterface();
+
+ /**
+ * Sets the interface definition representing the interface for invocations
+ * from the requestor to the provider.
+ *
+ * @param callInterface the interface definition representing the interface
+ * for invocations from the requestor to the provider
+ */
+ void setInterface(Interface callInterface);
+
+ /**
+ * Returns the interface definition representing the interface for
+ * invocations from the provider to the requestor.
+ *
+ * @return the interface definition representing the interface for
+ * invocations from the provider to the requestor.
+ */
+ Interface getCallbackInterface();
+
+ /**
+ * Sets the interface definition representing the interface for invocations
+ * from the provider to the requestor.
+ *
+ * @param callbackInterface the interface definition representing the
+ * interface for invocations from the provider to the requestor.
+ */
+ void setCallbackInterface(Interface callbackInterface);
+
+ // FIXME: We need a better way to do this
+ /**
+ * Convert an interface contract to a unidirectional interface contract
+ *
+ * @param isCallback true for a callback interface contract, false for
+ * a forward interface contract
+ * @return A unidirectional interface contract, cloned if necessary
+ */
+ InterfaceContract makeUnidirectional(boolean isCallback);
+
+ /**
+ * Implementations must support cloning.
+ */
+ Object clone() throws CloneNotSupportedException;
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java
new file mode 100644
index 0000000000..5601b09660
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InterfaceContractMapper.java
@@ -0,0 +1,115 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.interfacedef;
+
+/**
+ * The InterfaceContractMapper is responsible to match interfaces
+ *
+ * @version $Rev$ $Date$
+ */
+public interface InterfaceContractMapper {
+ /**
+ * Check the compatibility of the source and the target interface 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 symmetric: the success of isCompatible(A, B)
+ * does NOT imply isCompatible(B, A)
+ *
+ * @param source The source interface contract
+ * @param target The target interface contract
+ * @return true if the source contract can be supported by the target
+ * contract
+ */
+ boolean isCompatible(InterfaceContract source, InterfaceContract target);
+
+ /**
+ * @param source
+ * @param target
+ * @param ignoreCallback
+ * @param silent
+ * @return
+ * @throws IncompatibleInterfaceContractException
+ */
+ boolean checkCompatibility(InterfaceContract source,
+ InterfaceContract target,
+ boolean ignoreCallback,
+ boolean silent) throws IncompatibleInterfaceContractException;
+
+ /**
+ * Test if the source data type is compatible with the target data type. The
+ * compatibility is defined as follows.
+ * <ul>
+ * <li>source's logical type is either the same or subtype of the target's
+ * logical type
+ * </ul>
+ * For example, if the source type is a SDO Customer and the target type is
+ * a JAXB Customer and both Customer are generated from the same XSD type.
+ *
+ * @param source The source data type
+ * @param target The target data type
+ * @return
+ */
+ boolean isCompatible(DataType source, DataType target, boolean remotable);
+
+ /**
+ * Check if source operation is compatible with the target operation
+ *
+ * @param source The source operation
+ * @param target The target operation
+ * @return true if the source operation is compatible with the target
+ * operation
+ */
+ boolean isCompatible(Operation source, Operation target, boolean remotable);
+
+ /**
+ * @param source
+ * @param target
+ * @return
+ */
+ boolean isCompatible(Interface source, Interface target);
+
+ /**
+ * Map the source operation to a compatible operation in the target
+ * interface
+ *
+ * @param target The target interface
+ * @param source The source operation
+ * @return A compatible operation
+ */
+ Operation map(Interface target, Operation source);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidCallbackException.java b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidCallbackException.java
new file mode 100644
index 0000000000..f952a86478
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidCallbackException.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef;
+
+
+/**
+ * Denotes an illegal callback interface
+ *
+ * @version $Rev$ $Date$
+ */
+
+public class InvalidCallbackException extends InvalidInterfaceException {
+ private static final long serialVersionUID = 2727755895702116397L;
+
+ public InvalidCallbackException(String message) {
+ super(message);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidInterfaceException.java b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidInterfaceException.java
new file mode 100644
index 0000000000..2a273c9a26
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidInterfaceException.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public abstract class InvalidInterfaceException extends Exception {
+
+ public InvalidInterfaceException() {
+ super();
+ }
+
+ public InvalidInterfaceException(String message) {
+ super(message);
+ }
+
+ public InvalidInterfaceException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public InvalidInterfaceException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidOperationException.java b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidOperationException.java
new file mode 100644
index 0000000000..b19805c5b1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/InvalidOperationException.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef;
+
+import java.lang.reflect.Method;
+
+/**
+ * Denotes an invalid conversational interface definition
+ *
+ * @version $Rev$ $Date$
+ */
+public class InvalidOperationException extends InvalidInterfaceException {
+
+ private static final long serialVersionUID = -1797615361821517091L;
+ private final Method operation;
+
+ public InvalidOperationException(String message, Method operation) {
+ super(message);
+ this.operation = operation;
+ }
+
+ public Method getOperation() {
+ return operation;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Operation.java b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Operation.java
new file mode 100644
index 0000000000..4676e35f80
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/Operation.java
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.interfacedef.util.WrapperInfo;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+
+/**
+ * Represents an operation on a service interface.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Operation extends Cloneable, PolicySetAttachPoint {
+ /**
+ * Returns the name of the operation.
+ *
+ * @return the name of the operation
+ */
+ String getName();
+
+ /**
+ * Sets the name of the operation.
+ *
+ * @param name the name of the operation
+ */
+ void setName(String name);
+
+ /**
+ * Returns true if the model element is unresolved.
+ *
+ * @return true if the model element is unresolved.
+ */
+ boolean isUnresolved();
+
+ /**
+ * Sets whether the model element is unresolved.
+ *
+ * @param unresolved whether the model element is unresolved
+ */
+ void setUnresolved(boolean unresolved);
+
+ /**
+ * Get the data type that represents the input of this operation. The logic
+ * type is a list of data types and each element represents a parameter
+ *
+ * @return the inputType
+ */
+ DataType<List<DataType>> getInputType();
+
+ /**
+ * @param inputType
+ */
+ void setInputType(DataType<List<DataType>> inputType);
+
+ /**
+ * Get the data type for the output
+ *
+ * @return the outputType
+ */
+ DataType getOutputType();
+
+ /**
+ * @param outputType
+ */
+ void setOutputType(DataType outputType);
+
+ /**
+ * Get a list of data types to represent the faults/exceptions
+ *
+ * @return the faultTypes
+ */
+ List<DataType> getFaultTypes();
+
+ /**
+ * @param faultTypes
+ */
+ void setFaultTypes(List<DataType> faultTypes);
+
+ /**
+ * Get the owning interface
+ * @return
+ */
+ Interface getInterface();
+
+ /**
+ * Set the owning interface
+ * @param interfaze
+ */
+ void setInterface(Interface interfaze);
+
+ /**
+ * Get the sequence of the conversation
+ * @return
+ */
+ ConversationSequence getConversationSequence();
+
+ /**
+ * Set the sequence of conversation for the operation
+ * @param sequence
+ */
+ void setConversationSequence(ConversationSequence sequence);
+
+ /**
+ * Indicate if the operation is non-blocking
+ * @return
+ */
+ boolean isNonBlocking();
+
+ /**
+ * Set the operation to be non-blocking
+ */
+ void setNonBlocking(boolean nonBlocking);
+
+ /**
+ * @return the wrapperInfo
+ */
+ WrapperInfo getWrapper();
+
+ /**
+ * @param wrapperInfo the wrapperInfo to set
+ */
+ void setWrapper(WrapperInfo wrapperInfo);
+
+ /**
+ * @return the wrapperStyle
+ */
+ boolean isWrapperStyle();
+
+ /**
+ * @param wrapperStyle the wrapperStyle to set
+ */
+ void setWrapperStyle(boolean wrapperStyle);
+
+ /**
+ * @deprecated This should be the WrapperInfo.getDataBinding()
+ * Get the databinding for the operation
+ * @return
+ */
+ @Deprecated
+ String getDataBinding();
+
+ /**
+ * @deprecated This should be the WrapperInfo.setDataBinding()
+ * Set the databinding for the operation
+ * @param dataBinding
+ */
+ @Deprecated
+ void setDataBinding(String dataBinding);
+
+ /**
+ * Returns true if the operation is dynamic.
+ *
+ * @return true if the operation is dynamic otherwise false
+ */
+ boolean isDynamic();
+
+ /**
+ * Set if the operation is dynamic
+ * @param b
+ */
+ void setDynamic(boolean b);
+
+ /**
+ * Get the synthesized fault beans for this operation
+ *
+ * @return the fault beans
+ */
+ Map<QName, List<DataType<XMLType>>> getFaultBeans();
+
+ /**
+ * Set the synthesized fault beans for this operation
+ * @param faultBeans
+ */
+ void setFaultBeans(Map<QName, List<DataType<XMLType>>> faultBeans);
+
+ /**
+ * Implementations must support cloning.
+ */
+ Object clone() throws CloneNotSupportedException;
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/OverloadedOperationException.java b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/OverloadedOperationException.java
new file mode 100644
index 0000000000..6773b29088
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/OverloadedOperationException.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef;
+
+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 InvalidInterfaceException {
+ private static final long serialVersionUID = -4658711318608885638L;
+ private final Method operation;
+
+ public OverloadedOperationException(Method operation) {
+ super(operation == null ?
+ null : "Cannot overload operation " + operation.getName()
+ + " on " + operation.getDeclaringClass().getName()
+ + " as it is a @Remotable interface");
+ this.operation = operation;
+ }
+
+ public Method getOperation() {
+ return operation;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/DataTypeImpl.java b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/DataTypeImpl.java
new file mode 100644
index 0000000000..c1c8400b71
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/DataTypeImpl.java
@@ -0,0 +1,219 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef.impl;
+
+import java.lang.reflect.Type;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.tuscany.sca.interfacedef.DataType;
+
+/**
+ * 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 DataTypeImpl<L> implements DataType<L> {
+ private String dataBinding;
+ private Class<?> physical;
+ private Type genericType;
+ private L logical;
+ private Map<Class<?>, Object> metaDataMap;
+
+ /**
+ * 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 DataTypeImpl(Class<?> physical, L logical) {
+ this(null, physical, physical, logical);
+ }
+
+ /**
+ * @param dataBinding
+ * @param physical
+ * @param logical
+ */
+ public DataTypeImpl(String dataBinding, Class<?> physical, L logical) {
+ this(dataBinding, physical, physical, logical);
+ }
+
+ /**
+ * @param dataBinding
+ * @param physical
+ * @param genericType
+ * @param logical
+ */
+ public DataTypeImpl(String dataBinding, Class<?> physical, Type genericType, L logical) {
+ super();
+ this.dataBinding = dataBinding;
+ this.physical = physical;
+ this.genericType = genericType;
+ this.logical = logical;
+ }
+
+ /**
+ * Returns the physical type used by the runtime.
+ *
+ * @return the physical type used by the runtime
+ */
+ public Class<?> getPhysical() {
+ return physical;
+ }
+
+ /**
+ * @param physical the physical to set
+ */
+ public void setPhysical(Class<?> physical) {
+ this.physical = physical;
+ }
+
+ /**
+ * Get the java generic type
+ * @return The java generic type
+ */
+ public Type getGenericType() {
+ return genericType;
+ }
+
+ /**
+ * Set the java generic type
+ * @param genericType
+ */
+ public void setGenericType(Type genericType) {
+ this.genericType = genericType;
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * @param logical the logical to set
+ */
+ public void setLogical(L logical) {
+ this.logical = logical;
+ }
+
+ public String getDataBinding() {
+ return dataBinding;
+ }
+
+ /**
+ * @param dataBinding the dataBinding to set
+ */
+ public void setDataBinding(String dataBinding) {
+ this.dataBinding = dataBinding;
+ }
+
+ @Override
+ 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 {
+ DataTypeImpl copy = (DataTypeImpl)super.clone();
+ return copy;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((dataBinding == null) ? 0 : dataBinding.hashCode());
+ result = prime * result + ((genericType == null) ? 0 : genericType.hashCode());
+ result = prime * result + ((logical == null) ? 0 : logical.hashCode());
+ result = prime * result + ((physical == null) ? 0 : physical.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 DataTypeImpl other = (DataTypeImpl)obj;
+ if (dataBinding == null) {
+ if (other.dataBinding != null)
+ return false;
+ } else if (!dataBinding.equals(other.dataBinding))
+ return false;
+ if (genericType == null) {
+ if (other.genericType != null)
+ return false;
+ } else if (!genericType.equals(other.genericType))
+ return false;
+ if (logical == null) {
+ if (other.logical != null)
+ return false;
+ } else if (!logical.equals(other.logical))
+ return false;
+ if (physical == null) {
+ if (other.physical != null)
+ return false;
+ } else if (!physical.equals(other.physical))
+ return false;
+ return true;
+ }
+
+ public <T> T getMetaData(Class<T> type) {
+ return metaDataMap == null ? null : type.cast(metaDataMap.get(type));
+ }
+
+ public <T> void setMetaData(Class<T> type, T metaData) {
+ if (metaDataMap == null) {
+ metaDataMap = new ConcurrentHashMap<Class<?>, Object>();
+ }
+ metaDataMap.put(type, metaData);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractImpl.java b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractImpl.java
new file mode 100644
index 0000000000..15581b5e04
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractImpl.java
@@ -0,0 +1,128 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.interfacedef.impl;
+
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+
+/**
+ * Represents an interface contract. InterfaceContractImpl
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class InterfaceContractImpl implements InterfaceContract {
+ private Interface callInterface;
+ private Interface callbackInterface;
+
+ public Interface getCallbackInterface() {
+ return callbackInterface;
+ }
+
+ public Interface getInterface() {
+ return callInterface;
+ }
+
+ public void setCallbackInterface(Interface callbackInterface) {
+ this.callbackInterface = callbackInterface;
+ }
+
+ public void setInterface(Interface callInterface) {
+ this.callInterface = callInterface;
+ }
+
+ public InterfaceContract makeUnidirectional(boolean isCallback) {
+ if (!isCallback && callbackInterface == null)
+ return this; // already a unidirectional forward interface contract
+
+ if (isCallback && callInterface == null)
+ return this; // already a unidirectional callback interface contract
+
+ // contract is bidirectional, so create a new unidirectional contract
+ try {
+ InterfaceContract newContract = clone();
+ if (!isCallback) {
+ newContract.setCallbackInterface(null); // create unidirectional forward interface contract
+ } else {
+ newContract.setInterface(null); // create unidirectional callback interface contract
+ }
+ return newContract;
+ } catch (CloneNotSupportedException e) {
+ // will not happen
+ return null;
+ }
+ }
+
+ @Override
+ public InterfaceContractImpl clone() throws CloneNotSupportedException {
+ InterfaceContractImpl copy = (InterfaceContractImpl)super.clone();
+ if (this.callbackInterface != null) {
+ copy.callbackInterface = (Interface)this.callbackInterface.clone();
+ }
+ if (this.callInterface != null) {
+ copy.callInterface = (Interface)this.callInterface.clone();
+ }
+ return copy;
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((callInterface == null) ? 0 : callInterface.hashCode());
+ result = prime * result + ((callbackInterface == null) ? 0 : callbackInterface.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 InterfaceContractImpl other = (InterfaceContractImpl)obj;
+ if (callInterface == null) {
+ if (other.callInterface != null) {
+ return false;
+ }
+ } else if (!callInterface.equals(other.callInterface)) {
+ return false;
+ }
+ if (callbackInterface == null) {
+ if (other.callbackInterface != null) {
+ return false;
+ }
+ } else if (!callbackInterface.equals(other.callbackInterface)) {
+ return false;
+ }
+ return true;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.java
new file mode 100644
index 0000000000..9e7d6882f7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractMapperImpl.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.sca.interfacedef.impl;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.IncompatibleInterfaceContractException;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.Operation;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InterfaceContractMapperImpl implements InterfaceContractMapper {
+
+ public boolean isCompatible(DataType source, DataType target, boolean remotable) {
+ if (source == target) {
+ return true;
+ }
+ if (!remotable) {
+ if (source == null || target == null) {
+ return false;
+ }
+ // For local case
+ return target.getPhysical().isAssignableFrom(source.getPhysical());
+ } else {
+ // FIXME: How to test if two remotable data type is compatible?
+ // return target.getLogical().equals(source.getLogical());
+ return true;
+ }
+
+ }
+
+ public boolean isCompatible(Operation source, Operation target, boolean remotable) {
+ if (source == target) {
+ return true;
+ }
+
+ if (source.isDynamic() || target.isDynamic()) {
+ return true;
+ }
+
+ // Check name
+ if (!source.getName().equals(target.getName())) {
+ return false;
+ }
+
+ if (source.getInterface().isRemotable() != target.getInterface().isRemotable()) {
+ return false;
+ }
+
+ // if (source.getInterface().isRemotable()) {
+ // return true;
+ // }
+
+ // FIXME: We need to deal with wrapped<-->unwrapped conversion
+
+ // Check output type
+ DataType sourceOutputType = source.getOutputType();
+ DataType targetOutputType = target.getOutputType();
+
+ // Note the target output type is now the source for checking
+ // compatibility
+ if (!isCompatible(targetOutputType, sourceOutputType, remotable)) {
+ return false;
+ }
+
+ boolean checkSourceWrapper = true;
+ List<DataType> sourceInputType = source.getInputType().getLogical();
+ if (source.isWrapperStyle() && source.getWrapper() != null) {
+ sourceInputType = source.getWrapper().getUnwrappedInputType().getLogical();
+ checkSourceWrapper = false;
+ }
+ boolean checkTargetWrapper = true;
+ List<DataType> targetInputType = target.getInputType().getLogical();
+ if (target.isWrapperStyle() && target.getWrapper() != null) {
+ targetInputType = target.getWrapper().getUnwrappedInputType().getLogical();
+ checkTargetWrapper = false;
+ }
+
+ if (checkSourceWrapper != checkTargetWrapper) {
+ return true;
+ }
+ if (sourceInputType.size() != targetInputType.size()) {
+ return false;
+ }
+
+ int size = sourceInputType.size();
+ for (int i = 0; i < size; i++) {
+ if (!isCompatible(sourceInputType.get(i), targetInputType.get(i), remotable)) {
+ return false;
+ }
+ }
+
+ // Check fault types
+ for (DataType targetFaultType : target.getFaultTypes()) {
+ // Source fault types must be the same or superset of target fault
+ // types
+ boolean found = true;
+ for (DataType sourceFaultType : source.getFaultTypes()) {
+ found = false;
+ if (isCompatible(targetFaultType, sourceFaultType, remotable)) {
+ // Target fault type can be covered by the source fault type
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ // FIXME: How to improve the performance for the lookup
+ private Operation getOperation(List<Operation> operations, String name) {
+ for (Operation op : operations) {
+ if (op.getName().equals(name)) {
+ return op;
+ }
+ }
+ return null;
+ }
+
+ public boolean checkCompatibility(InterfaceContract source,
+ InterfaceContract target,
+ boolean ignoreCallback,
+ boolean silent) throws IncompatibleInterfaceContractException {
+ if (source == target) {
+ // Shortcut for performance
+ return true;
+ }
+
+ if (source.getInterface().isDynamic() || target.getInterface().isDynamic()) {
+ return true;
+ }
+
+ if (source.getInterface().isRemotable() != target.getInterface().isRemotable()) {
+ if (!silent) {
+ throw new IncompatibleInterfaceContractException("Remotable settings do not match", source, target);
+ } else {
+ return false;
+ }
+ }
+ if (source.getInterface().isConversational() != target.getInterface().isConversational()) {
+ if (!silent) {
+ throw new IncompatibleInterfaceContractException("Interaction scopes do not match", source, target);
+ } else {
+ return false;
+ }
+ }
+
+ for (Operation operation : source.getInterface().getOperations()) {
+ Operation targetOperation = map(target.getInterface(), operation);
+ if (targetOperation == null) {
+ if (!silent) {
+ throw new IncompatibleInterfaceContractException("Operation not found on target", source, target);
+ } else {
+ return false;
+ }
+ }
+ if (!source.getInterface().isRemotable()) {
+ // FIXME: for remotable operation, only compare name for now
+ if (!isCompatible(operation, targetOperation, false)) {
+ if (!silent) {
+ throw new IncompatibleInterfaceContractException("Target operations are not compatible",
+ source, target);
+ } else {
+ return false;
+ }
+ }
+ }
+ }
+
+ if (ignoreCallback) {
+ return true;
+ }
+
+ if (source.getCallbackInterface() == null && target.getCallbackInterface() == null) {
+ return true;
+ }
+ if (source.getCallbackInterface() == null || target.getCallbackInterface() == null) {
+ if (!silent) {
+ throw new IncompatibleInterfaceContractException("Callback interface doesn't match", source, target);
+ } else {
+ return false;
+ }
+ }
+
+ for (Operation operation : source.getCallbackInterface().getOperations()) {
+ Operation targetOperation =
+ getOperation(target.getCallbackInterface().getOperations(), operation.getName());
+ if (targetOperation == null) {
+ if (!silent) {
+ throw new IncompatibleInterfaceContractException("Callback operation not found on target", source,
+ target, null, targetOperation);
+ } else {
+ return false;
+ }
+ }
+ if (!source.getCallbackInterface().isRemotable()) {
+ // FIXME: for remotable operation, only compare name for now
+ if (!operation.equals(targetOperation)) {
+ if (!silent) {
+ throw new IncompatibleInterfaceContractException("Target callback operation is not compatible",
+ source, target, operation, targetOperation);
+ } else {
+ return false;
+ }
+ }
+ }
+ }
+ return true;
+ }
+
+ public boolean isCompatible(Interface source, Interface target) {
+ if (source == target) {
+ // Shortcut for performance
+ return true;
+ }
+ if (source == null || target == null) {
+ return false;
+ }
+
+ if (source.isDynamic() || target.isDynamic()) {
+ return true;
+ }
+
+ if (source.isRemotable() != target.isRemotable()) {
+ return false;
+ }
+ if (source.isConversational() != target.isConversational()) {
+ return false;
+ }
+
+ for (Operation operation : source.getOperations()) {
+ Operation targetOperation = getOperation(target.getOperations(), operation.getName());
+ if (targetOperation == null) {
+ return false;
+ }
+ if (!isCompatible(operation, targetOperation, source.isRemotable())) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public boolean isCompatible(InterfaceContract source, InterfaceContract target) {
+ try {
+ return checkCompatibility(source, target, false, false);
+ } catch (IncompatibleInterfaceContractException e) {
+ return false;
+ }
+ }
+
+ /**
+ * @see org.apache.tuscany.sca.interfacedef.InterfaceContractMapper#map(org.apache.tuscany.sca.interfacedef.Interface,
+ * org.apache.tuscany.sca.interfacedef.Operation)
+ */
+ public Operation map(Interface target, Operation source) {
+ // TODO: How to handle the case that source operation is dynamic?
+ if (target == null || target.isDynamic()) {
+ return source;
+ } else if (target.isRemotable()) {
+ for (Operation op : target.getOperations()) {
+ if (op.getName().equals(source.getName())) {
+ return op;
+ }
+ }
+ return null;
+ } else {
+ for (Operation op : target.getOperations()) {
+ if (isCompatible(source, op, target.isRemotable())) {
+ return op;
+ }
+ }
+ return null;
+ }
+
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceImpl.java b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceImpl.java
new file mode 100644
index 0000000000..e2a524c5e0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceImpl.java
@@ -0,0 +1,296 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef.impl;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.WrapperInfo;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicySet;
+
+/**
+ * Represents a service interface.
+ *
+ * @version $Rev$ $Date$
+ */
+public class InterfaceImpl implements Interface {
+
+ private boolean remotable;
+ private boolean conversational;
+ private OperationList operations = new OperationList();
+ private boolean unresolved;
+
+ private List<PolicySet> applicablePolicySets = new ArrayList<PolicySet>();
+ private IntentAttachPointType type;
+ private List<PolicySet> policySets = new ArrayList<PolicySet>();
+ private List<Intent> requiredIntents = new ArrayList<Intent>();
+
+
+ public boolean isRemotable() {
+ return remotable;
+ }
+
+ public void setRemotable(boolean local) {
+ this.remotable = local;
+ }
+
+ public List<Operation> getOperations() {
+ return operations;
+ }
+
+ public boolean isUnresolved() {
+ return unresolved;
+ }
+
+ public void setUnresolved(boolean undefined) {
+ this.unresolved = undefined;
+ }
+
+ /**
+ * @return the conversational
+ */
+ public boolean isConversational() {
+ return conversational;
+ }
+
+ /**
+ * @param conversational the conversational to set
+ */
+ public void setConversational(boolean conversational) {
+ this.conversational = conversational;
+ }
+
+ private class OperationList extends ArrayList<Operation> {
+ private static final long serialVersionUID = -903469106307606099L;
+
+ @Override
+ public Operation set(int index, Operation element) {
+ element.setInterface(InterfaceImpl.this);
+ return super.set(index, element);
+ }
+
+ @Override
+ public void add(int index, Operation element) {
+ element.setInterface(InterfaceImpl.this);
+ super.add(index, element);
+ }
+
+ @Override
+ public boolean add(Operation o) {
+ o.setInterface(InterfaceImpl.this);
+ return super.add(o);
+ }
+
+ @Override
+ public boolean addAll(Collection<? extends Operation> c) {
+ for (Operation op : c) {
+ op.setInterface(InterfaceImpl.this);
+ }
+ return super.addAll(c);
+ }
+
+ @Override
+ public boolean addAll(int index, Collection<? extends Operation> c) {
+ for (Operation op : c) {
+ op.setInterface(InterfaceImpl.this);
+ }
+ return super.addAll(index, c);
+ }
+
+ }
+
+ @Deprecated
+ public void setDefaultDataBinding(String dataBinding) {
+ for (Operation op : getOperations()) {
+ if (op.getDataBinding() == null) {
+ op.setDataBinding(dataBinding);
+ DataType<List<DataType>> inputType = op.getInputType();
+ if (inputType != null) {
+ for (DataType d : inputType.getLogical()) {
+ if (d.getDataBinding() == null) {
+ d.setDataBinding(dataBinding);
+ }
+ }
+ }
+ DataType outputType = op.getOutputType();
+ if (outputType != null && outputType.getDataBinding() == null) {
+ outputType.setDataBinding(dataBinding);
+ }
+ List<DataType> faultTypes = op.getFaultTypes();
+ if (faultTypes != null) {
+ for (DataType d : faultTypes) {
+ if (d.getDataBinding() == null) {
+ d.setDataBinding(dataBinding);
+ }
+ DataType ft = (DataType) d.getLogical();
+ if (ft.getDataBinding() == null) {
+ ft.setDataBinding(dataBinding);
+ }
+
+ }
+ }
+ if (op.isWrapperStyle()) {
+ WrapperInfo wrapper = op.getWrapper();
+ if (wrapper != null) {
+ DataType<List<DataType>> unwrappedInputType = wrapper.getUnwrappedInputType();
+ if (unwrappedInputType != null) {
+ for (DataType d : unwrappedInputType.getLogical()) {
+ if (d.getDataBinding() == null) {
+ d.setDataBinding(dataBinding);
+ }
+ }
+ }
+ DataType unwrappedOutputType = wrapper.getUnwrappedOutputType();
+ if (unwrappedOutputType != null && unwrappedOutputType.getDataBinding() == null) {
+ unwrappedOutputType.setDataBinding(dataBinding);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private void setDataBinding(DataType dataType, String dataBinding) {
+ if ("java:array".equals(dataType.getDataBinding())) {
+ setDataBinding((DataType)dataType.getLogical(), dataBinding);
+ } else {
+ dataType.setDataBinding(dataBinding);
+ }
+ }
+
+ public void resetDataBinding(String dataBinding) {
+ for (Operation op : getOperations()) {
+ op.setDataBinding(dataBinding);
+ DataType<List<DataType>> inputType = op.getInputType();
+ if (inputType != null) {
+ for (DataType d : inputType.getLogical()) {
+ setDataBinding(d, dataBinding);
+ }
+ }
+ DataType outputType = op.getOutputType();
+ if (outputType != null) {
+ setDataBinding(outputType, dataBinding);
+ }
+ List<DataType> faultTypes = op.getFaultTypes();
+ if (faultTypes != null) {
+ for (DataType d : faultTypes) {
+ setDataBinding(d, dataBinding);
+ setDataBinding((DataType) d.getLogical(), dataBinding);
+ }
+ }
+ if (op.isWrapperStyle()) {
+ WrapperInfo wrapper = op.getWrapper();
+ if (wrapper != null) {
+ DataType<List<DataType>> unwrappedInputType = wrapper.getUnwrappedInputType();
+ if (unwrappedInputType != null) {
+ for (DataType d : unwrappedInputType.getLogical()) {
+ setDataBinding(d, dataBinding);
+ }
+ }
+ DataType unwrappedOutputType = wrapper.getUnwrappedOutputType();
+ if (unwrappedOutputType != null) {
+ setDataBinding(unwrappedOutputType, dataBinding);
+ }
+ }
+ }
+ }
+ }
+
+ public boolean isDynamic() {
+ return false;
+ }
+
+ public List<PolicySet> getApplicablePolicySets() {
+ return applicablePolicySets;
+ }
+
+ public List<PolicySet> getPolicySets() {
+ return policySets;
+ }
+
+ public List<Intent> getRequiredIntents() {
+ return requiredIntents;
+ }
+
+ public IntentAttachPointType getType() {
+ return type;
+ }
+
+ public void setType(IntentAttachPointType type) {
+ this.type = type;
+ }
+
+ @Override
+ public Object clone() throws CloneNotSupportedException {
+ InterfaceImpl copy = (InterfaceImpl)super.clone();
+ copy.operations = new OperationList();
+ for (Operation operation : this.operations) {
+ Operation clonedOperation = (Operation)operation.clone();
+ copy.operations.add(clonedOperation);
+ }
+ return copy;
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (conversational ? 1231 : 1237);
+ result = prime * result + ((operations == null) ? 0 : operations.hashCode());
+ result = prime * result + (remotable ? 1231 : 1237);
+ result = prime * result + (unresolved ? 1231 : 1237);
+ 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 InterfaceImpl other = (InterfaceImpl)obj;
+ if (conversational != other.conversational)
+ return false;
+ if (operations == null) {
+ if (other.operations != null)
+ return false;
+ } else if (!operations.equals(other.operations))
+ return false;
+ if (remotable != other.remotable)
+ return false;
+ if (unresolved != other.unresolved)
+ return false;
+ return true;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/OperationImpl.java b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/OperationImpl.java
new file mode 100644
index 0000000000..00a5dc3065
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/impl/OperationImpl.java
@@ -0,0 +1,339 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.interfacedef.ConversationSequence;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.WrapperInfo;
+import org.apache.tuscany.sca.interfacedef.util.XMLType;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicySet;
+
+/**
+ * Represents an operation on a service interface.
+ *
+ * @version $Rev$ $Date$
+ */
+public class OperationImpl implements Operation {
+
+ private String name;
+ private boolean unresolved;
+ private DataType outputType;
+ private DataType<List<DataType>> inputType;
+ private List<DataType> faultTypes;
+ private Interface interfaze;
+ private ConversationSequence conversationSequence = ConversationSequence.CONVERSATION_NONE;
+ private boolean nonBlocking;
+ private boolean wrapperStyle;
+ private WrapperInfo wrapper;
+ private boolean dynamic;
+ private Map<QName, List<DataType<XMLType>>> faultBeans;
+
+ private List<PolicySet> applicablePolicySets = new ArrayList<PolicySet>();
+ private List<PolicySet> policySets = new ArrayList<PolicySet>();
+ private List<Intent> requiredIntents = new ArrayList<Intent>();
+ private IntentAttachPointType type;
+
+ /**
+ * @param name
+ */
+ public OperationImpl() {
+ inputType = new DataTypeImpl<List<DataType>>("idl:input", Object[].class, new ArrayList<DataType>());
+ faultTypes = new ArrayList<DataType>();
+ faultBeans = new HashMap<QName, List<DataType<XMLType>>>();
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public boolean isUnresolved() {
+ return unresolved;
+ }
+
+ public void setUnresolved(boolean undefined) {
+ this.unresolved = undefined;
+ }
+
+ /**
+ * @return the faultTypes
+ */
+ public List<DataType> getFaultTypes() {
+ return faultTypes;
+ }
+
+ /**
+ * @param faultTypes the faultTypes to set
+ */
+ public void setFaultTypes(List<DataType> faultTypes) {
+ this.faultTypes = faultTypes;
+ }
+
+ /**
+ * @return the inputType
+ */
+ public DataType<List<DataType>> getInputType() {
+ return inputType;
+ }
+
+ /**
+ * @param inputType the inputType to set
+ */
+ public void setInputType(DataType<List<DataType>> inputType) {
+ this.inputType = inputType;
+ }
+
+ /**
+ * @return the outputType
+ */
+ public DataType getOutputType() {
+ return outputType;
+ }
+
+ /**
+ * @param outputType the outputType to set
+ */
+ public void setOutputType(DataType outputType) {
+ this.outputType = outputType;
+ }
+
+ /**
+ * @return the interface
+ */
+ public Interface getInterface() {
+ return interfaze;
+ }
+
+ /**
+ * @param interfaze the interface to set
+ */
+ public void setInterface(Interface interfaze) {
+ this.interfaze = interfaze;
+ }
+
+ /**
+ * @return the conversationSequence
+ */
+ public ConversationSequence getConversationSequence() {
+ return conversationSequence;
+ }
+
+ /**
+ * @param conversationSequence the conversationSequence to set
+ */
+ public void setConversationSequence(ConversationSequence conversationSequence) {
+ this.conversationSequence = conversationSequence;
+ }
+
+ /**
+ * @return the nonBlocking
+ */
+ public boolean isNonBlocking() {
+ return nonBlocking;
+ }
+
+ /**
+ * @param nonBlocking the nonBlocking to set
+ */
+ public void setNonBlocking(boolean nonBlocking) {
+ this.nonBlocking = nonBlocking;
+ }
+
+ @Override
+ public int hashCode() {
+ final int PRIME = 31;
+ int result = 1;
+ result = PRIME * result + ((conversationSequence == null) ? 0 : conversationSequence.hashCode());
+ // result = PRIME * result + ((faultTypes == null) ? 0 :
+ // faultTypes.hashCode());
+ result = PRIME * result + ((inputType == null) ? 0 : inputType.hashCode());
+ result = PRIME * result + ((name == null) ? 0 : name.hashCode());
+ result = PRIME * result + (nonBlocking ? 1231 : 1237);
+ result = PRIME * result + ((outputType == null) ? 0 : outputType.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 OperationImpl other = (OperationImpl)obj;
+ if (conversationSequence == null) {
+ if (other.conversationSequence != null) {
+ return false;
+ }
+ } else if (!conversationSequence.equals(other.conversationSequence)) {
+ return false;
+ }
+ /*
+ * if (faultTypes == null) { if (other.faultTypes != null) { return
+ * false; } } else if (!faultTypes.equals(other.faultTypes)) { return
+ * false; }
+ */
+
+ if (inputType == null) {
+ if (other.inputType != null) {
+ return false;
+ }
+ } else if (!inputType.equals(other.inputType)) {
+ return false;
+ }
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+ if (nonBlocking != other.nonBlocking) {
+ return false;
+ }
+ if (outputType == null) {
+ if (other.outputType != null) {
+ return false;
+ }
+ } else if (!outputType.equals(other.outputType)) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * @return the wrapperInfo
+ */
+ public WrapperInfo getWrapper() {
+ return wrapper;
+ }
+
+ /**
+ * @param wrapperInfo the wrapperInfo to set
+ */
+ public void setWrapper(WrapperInfo wrapperInfo) {
+ this.wrapper = wrapperInfo;
+ }
+
+ /**
+ * @return the wrapperStyle
+ */
+ public boolean isWrapperStyle() {
+ return wrapperStyle;
+ }
+
+ /**
+ * @param wrapperStyle the wrapperStyle to set
+ */
+ public void setWrapperStyle(boolean wrapperStyle) {
+ this.wrapperStyle = wrapperStyle;
+ }
+
+ public String getDataBinding() {
+ return wrapper != null ? wrapper.getDataBinding() : null;
+ }
+
+ public void setDataBinding(String dataBinding) {
+ if (wrapper != null) {
+ wrapper.setDataBinding(dataBinding);
+ }
+ }
+
+ public boolean isDynamic() {
+ return dynamic;
+ }
+
+ public void setDynamic(boolean b) {
+ this.dynamic = b;
+ }
+
+ public Map<QName, List<DataType<XMLType>>> getFaultBeans() {
+ return faultBeans;
+ }
+
+ public void setFaultBeans(Map<QName, List<DataType<XMLType>>> faultBeans) {
+ this.faultBeans = faultBeans;
+ }
+
+ @Override
+ public OperationImpl clone() throws CloneNotSupportedException {
+ OperationImpl copy = (OperationImpl) super.clone();
+
+ final List<DataType> clonedFaultTypes = new ArrayList<DataType>(this.faultTypes.size());
+ for (DataType t : this.faultTypes) {
+ clonedFaultTypes.add((DataType) t.clone());
+ }
+ copy.faultTypes = clonedFaultTypes;
+
+ List<DataType> clonedLogicalTypes = new ArrayList<DataType>();
+ for (DataType t : inputType.getLogical()) {
+ DataType type = (DataType) t.clone();
+ clonedLogicalTypes.add(type);
+ }
+ DataType<List<DataType>> clonedInputType =
+ new DataTypeImpl<List<DataType>>(inputType.getPhysical(), clonedLogicalTypes);
+ clonedInputType.setDataBinding(inputType.getDataBinding());
+ copy.inputType = clonedInputType;
+
+ if (this.outputType != null) {
+ copy.outputType = (DataType) this.outputType.clone();
+ }
+
+ return copy;
+ }
+
+ public List<PolicySet> getApplicablePolicySets() {
+ return applicablePolicySets;
+ }
+
+ public List<PolicySet> getPolicySets() {
+ return policySets;
+ }
+
+ public List<Intent> getRequiredIntents() {
+ return requiredIntents;
+ }
+
+ public IntentAttachPointType getType() {
+ return type;
+ }
+
+ public void setType(IntentAttachPointType type) {
+ this.type = type;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/ElementInfo.java b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/ElementInfo.java
new file mode 100644
index 0000000000..777fa567f1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/ElementInfo.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.interfacedef.util;
+
+import javax.xml.namespace.QName;
+
+/**
+ * An abstraction of XML schema elements.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ElementInfo {
+ private final QName name;
+ private final TypeInfo type;
+ private boolean many = false;
+ private boolean nillable = false;
+
+ /**
+ * @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;
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("Element: ").append(name).append(" ").append(type);
+ return sb.toString();
+ }
+
+ public boolean isMany() {
+ return many;
+ }
+
+ public void setMany(boolean many) {
+ this.many = many;
+ }
+
+ public boolean isNillable() {
+ return nillable;
+ }
+
+ public void setNillable(boolean nillable) {
+ this.nillable = nillable;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((type == null) ? 0 : type.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 ElementInfo other = (ElementInfo)obj;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ /*
+ if (type == null) {
+ if (other.type != null)
+ return false;
+ } else if (!type.equals(other.type))
+ return false;
+ */
+ return true;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/FaultException.java b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/FaultException.java
new file mode 100644
index 0000000000..844b0af509
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/FaultException.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.interfacedef.util;
+
+import javax.xml.namespace.QName;
+
+/**
+ * The generic java exception to wrap service faults
+ *
+ * @version $Rev$ $Date$
+ */
+public class FaultException extends Exception {
+ private static final long serialVersionUID = -8002583655240625792L;
+ private transient Object faultInfo; // FIXME: How to serialize it?
+ private QName faultName;
+
+ /**
+ * @param message
+ * @param faultInfo
+ */
+ public FaultException(String message, Object faultInfo) {
+ super(message);
+ this.faultInfo = faultInfo;
+ }
+
+ /**
+ * @param message
+ * @param faultInfo
+ * @param cause
+ */
+ public FaultException(String message, Object faultInfo, Throwable cause) {
+ super(message, cause);
+ this.faultInfo = faultInfo;
+ }
+
+ /**
+ * @return the faultInfo
+ */
+ public Object getFaultInfo() {
+ return faultInfo;
+ }
+
+ public QName getFaultName() {
+ return faultName;
+ }
+
+ public void setFaultName(QName logical) {
+ this.faultName = logical;
+ }
+
+ public boolean isMatchingType(Object type) {
+ if (faultName == null) {
+ return false;
+ }
+
+ if ((type instanceof QName) && faultName.equals(type)) {
+ return true;
+ }
+ if (type instanceof XMLType && faultName.equals(((XMLType)type).getElementName())) {
+ return true;
+ }
+ return false;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/JavaXMLMapper.java b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/JavaXMLMapper.java
new file mode 100644
index 0000000000..54c0a3ec11
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/JavaXMLMapper.java
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.interfacedef.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Utility class that can be used to map XSD types to Java classes and Java classes to XSD types.
+ *
+ * @version $Rev$ $Date$
+ */
+public final class JavaXMLMapper {
+ public static final String URI_2001_SCHEMA_XSD = "http://www.w3.org/2001/XMLSchema";
+ private static final Map<Class, QName> JAVA2XML = new HashMap<Class, QName>();
+ private static final Map<String, Class> XML2JAVA = new HashMap<String, Class>();
+
+ private JavaXMLMapper() {
+ }
+
+ static {
+ JAVA2XML.put(boolean.class, getTypeName("boolean"));
+ JAVA2XML.put(byte.class, getTypeName("byte"));
+ JAVA2XML.put(short.class, getTypeName("short"));
+ JAVA2XML.put(int.class, getTypeName("int"));
+ JAVA2XML.put(long.class, getTypeName("long"));
+ JAVA2XML.put(float.class, getTypeName("float"));
+ JAVA2XML.put(double.class, getTypeName("double"));
+ JAVA2XML.put(Boolean.class, getTypeName("boolean"));
+ JAVA2XML.put(Byte.class, getTypeName("byte"));
+ JAVA2XML.put(Short.class, getTypeName("short"));
+ JAVA2XML.put(Integer.class, getTypeName("int"));
+ JAVA2XML.put(Long.class, getTypeName("long"));
+ JAVA2XML.put(Float.class, getTypeName("float"));
+ JAVA2XML.put(Double.class, getTypeName("double"));
+ JAVA2XML.put(java.lang.String.class, getTypeName("string"));
+ JAVA2XML.put(java.math.BigInteger.class, getTypeName("integer"));
+ JAVA2XML.put(java.math.BigDecimal.class, getTypeName("decimal"));
+ JAVA2XML.put(java.util.Calendar.class, getTypeName("dateTime"));
+ JAVA2XML.put(java.util.Date.class, getTypeName("dateTime"));
+ JAVA2XML.put(javax.xml.namespace.QName.class, getTypeName("QName"));
+ JAVA2XML.put(java.net.URI.class, getTypeName("string"));
+ JAVA2XML.put(javax.xml.datatype.XMLGregorianCalendar.class, getTypeName("anySimpleType"));
+ JAVA2XML.put(javax.xml.datatype.Duration.class, getTypeName("duration"));
+ JAVA2XML.put(java.lang.Object.class, getTypeName("anyType"));
+ JAVA2XML.put(java.awt.Image.class, getTypeName("base64Binary"));
+ JAVA2XML.put(byte[].class, getTypeName("base64Binary"));
+ // java2XSD.put(javax.activation.DataHandler.class, getTypeName("base64Binary"));
+ JAVA2XML.put(javax.xml.transform.Source.class, getTypeName("base64Binary"));
+ JAVA2XML.put(java.util.UUID.class, getTypeName("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);
+ }
+
+ public static Class getJavaType(QName xmlType) {
+ if (URI_2001_SCHEMA_XSD.equals(xmlType.getNamespaceURI())) {
+ return XML2JAVA.get(xmlType.getLocalPart());
+ } else {
+ return null;
+ }
+ }
+
+ private static QName getTypeName(String name) {
+ return new QName(URI_2001_SCHEMA_XSD, name);
+ }
+
+ public static QName getXMLType(Class javaType) {
+ return JAVA2XML.get(javaType);
+ }
+
+ private static String getPackageName(Class<?> cls) {
+ String name = cls.getName();
+ int index = name.lastIndexOf('.');
+ return index == -1 ? "" : name.substring(0, index);
+ }
+
+ public static String getNamespace(Class<?> cls) {
+ String packageName = getPackageName(cls);
+ if ("".equals(packageName)) {
+ return "";
+ }
+ StringBuffer ns = new StringBuffer("http://");
+ String[] names = packageName.split("\\.");
+ for (int i = names.length - 1; i >= 0; i--) {
+ ns.append(names[i]);
+ if (i != 0) {
+ ns.append('.');
+ }
+ }
+ ns.append('/');
+ return ns.toString();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/TypeInfo.java b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/TypeInfo.java
new file mode 100644
index 0000000000..2598dc8545
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/TypeInfo.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.interfacedef.util;
+
+import javax.xml.namespace.QName;
+
+/**
+ * An abstraction of XML schema types
+ *
+ * @version $Rev$ $Date$
+ */
+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;
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer sb = new StringBuffer();
+ sb.append("Type: ").append(name);
+ return sb.toString();
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((name == null) ? 0 : name.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 TypeInfo other = (TypeInfo)obj;
+ if (name == null) {
+ if (other.name != null)
+ return false;
+ } else if (!name.equals(other.name))
+ return false;
+ return true;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/WrapperInfo.java b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/WrapperInfo.java
new file mode 100644
index 0000000000..12db460959
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/WrapperInfo.java
@@ -0,0 +1,190 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.interfacedef.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.impl.DataTypeImpl;
+
+/**
+ * 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;
+
+ // The data type of the unwrapped input child elements
+ private DataType<List<DataType>> unwrappedInputType;
+
+ // The data type of the unwrapped output child element (we only supports one child)
+ private DataType<XMLType> unwrappedOutputType;
+
+ // The data for the input/output wrappers
+ private String dataBinding;
+
+ // The data type for the input (request) wrapper bean
+ private DataType<XMLType> inputWrapperType;
+ // The data type for the output (response) wrapper bean
+ private DataType<XMLType> outputWrapperType;
+
+ 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>> getUnwrappedInputType() {
+ if (unwrappedInputType == null) {
+ List<DataType> childTypes = new ArrayList<DataType>();
+ for (ElementInfo element : getInputChildElements()) {
+ DataType type = getDataType(element);
+ childTypes.add(type);
+ }
+ unwrappedInputType = new DataTypeImpl<List<DataType>>("idl:unwrapped.input", Object[].class, childTypes);
+ }
+ return unwrappedInputType;
+ }
+
+ private DataType getDataType(ElementInfo element) {
+ DataType type = null;
+ if (element.isMany()) {
+ DataType logical = new DataTypeImpl<XMLType>(dataBinding, Object.class, new XMLType(element));
+ type = new DataTypeImpl<DataType>("java:array", Object[].class, logical);
+ } else {
+ type = new DataTypeImpl<XMLType>(dataBinding, Object.class, new XMLType(element));
+ }
+ return type;
+ }
+
+ /**
+ * @return the unwrappedOutputType
+ */
+ public DataType 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 = getDataType(element);
+ }
+ }
+ return unwrappedOutputType;
+ }
+
+ public Class<?> getInputWrapperClass() {
+ return inputWrapperType == null ? null : inputWrapperType.getPhysical();
+ }
+
+ public Class<?> getOutputWrapperClass() {
+ return outputWrapperType == null ? null : outputWrapperType.getPhysical();
+ }
+
+ public String getDataBinding() {
+ return dataBinding;
+ }
+
+ public void setDataBinding(String dataBinding) {
+ this.dataBinding = dataBinding;
+ }
+
+ public DataType<XMLType> getInputWrapperType() {
+ return inputWrapperType;
+ }
+
+ public void setInputWrapperType(DataType<XMLType> inputWrapperType) {
+ this.inputWrapperType = inputWrapperType;
+ }
+
+ public DataType<XMLType> getOutputWrapperType() {
+ return outputWrapperType;
+ }
+
+ public void setOutputWrapperType(DataType<XMLType> outputWrapperType) {
+ this.outputWrapperType = outputWrapperType;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/XMLType.java b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/XMLType.java
new file mode 100644
index 0000000000..26ecf6e352
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/java/org/apache/tuscany/sca/interfacedef/util/XMLType.java
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.interfacedef.util;
+
+import javax.xml.namespace.QName;
+
+/**
+ * The metadata for an XML element or type.
+ *
+ * @version $Rev$ $Date$
+ */
+public class XMLType {
+ public static final XMLType UNKNOWN = new XMLType(null, null);
+ protected QName element;
+ protected QName type;
+ protected boolean nillable = true;
+ protected boolean many = false;
+
+ /**
+ * @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 void setElementName(QName element) {
+ this.element = element;
+ }
+
+ public void setTypeName(QName type) {
+ this.type = type;
+ }
+
+ 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;
+ }
+
+ public boolean isNillable() {
+ return nillable;
+ }
+
+ public void setNillable(boolean niable) {
+ this.nillable = niable;
+ }
+
+ public boolean isMany() {
+ return many;
+ }
+
+ public void setMany(boolean many) {
+ this.many = many;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.InterfaceContractMapper b/sca-java-1.x/branches/sca-android/modules/interface/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.InterfaceContractMapper
new file mode 100644
index 0000000000..821c58bde1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/main/resources/META-INF/services/org.apache.tuscany.sca.interfacedef.InterfaceContractMapper
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.interfacedef.impl.InterfaceContractMapperImpl
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/test/java/org/apache/tuscany/sca/interfacedef/impl/ContractCompatibilityTestCase.java b/sca-java-1.x/branches/sca-android/modules/interface/src/test/java/org/apache/tuscany/sca/interfacedef/impl/ContractCompatibilityTestCase.java
new file mode 100644
index 0000000000..269a3dc038
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/test/java/org/apache/tuscany/sca/interfacedef/impl/ContractCompatibilityTestCase.java
@@ -0,0 +1,380 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.interfacedef.impl;
+
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.DataType;
+import org.apache.tuscany.sca.interfacedef.IncompatibleInterfaceContractException;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.Operation;
+
+/**
+ * TODO some tests commented out due to DataType.equals() needing to be strict
+ *
+ * @version $Rev$ $Date$
+ */
+public class ContractCompatibilityTestCase extends TestCase {
+
+ private InterfaceContractMapper mapper;
+
+ @Override
+ protected void setUp() throws Exception {
+ ExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ mapper = utilities.getUtility(InterfaceContractMapper.class);
+ }
+
+ public void testNoOperation() throws Exception {
+ InterfaceContract source = new MockContract("FooContract");
+ InterfaceContract target = new MockContract("FooContract");
+ mapper.checkCompatibility(source, target, false, false);
+ }
+
+ public void testBasic() throws Exception {
+ InterfaceContract source = new MockContract("FooContract");
+ Operation opSource1 = newOperation("op1");
+ Map<String, Operation> sourceOperations = new HashMap<String, Operation>();
+ sourceOperations.put("op1", opSource1);
+ source.getInterface().getOperations().addAll(sourceOperations.values());
+ InterfaceContract target = new MockContract("FooContract");
+ Operation opSource2 = newOperation("op1");
+ Map<String, Operation> targetOperations = new HashMap<String, Operation>();
+ targetOperations.put("op1", opSource2);
+ target.getInterface().getOperations().addAll(targetOperations.values());
+ mapper.checkCompatibility(source, target, false, false);
+ }
+
+ public void testBasicIncompatibleOperationNames() throws Exception {
+ InterfaceContract source = new MockContract("FooContract");
+ Operation opSource1 = newOperation("op1");
+ Map<String, Operation> sourceOperations = new HashMap<String, Operation>();
+ sourceOperations.put("op1", opSource1);
+ source.getInterface().getOperations().addAll(sourceOperations.values());
+ InterfaceContract target = new MockContract("FooContract");
+ Operation opSource2 = newOperation("op2");
+ Map<String, Operation> targetOperations = new HashMap<String, Operation>();
+ targetOperations.put("op2", opSource2);
+ target.getInterface().getOperations().addAll(targetOperations.values());
+ try {
+ mapper.checkCompatibility(source, target, false, false);
+ fail();
+ } catch (IncompatibleInterfaceContractException e) {
+ // expected
+ }
+ }
+
+ public void testInputTypes() throws Exception {
+ InterfaceContract source = new MockContract("FooContract");
+ List<DataType> sourceInputTypes = new ArrayList<DataType>();
+ sourceInputTypes.add(new DataTypeImpl<Type>(Object.class, Object.class));
+ DataType<List<DataType>> inputType = new DataTypeImpl<List<DataType>>(String.class, sourceInputTypes);
+ Operation opSource1 = newOperation("op1");
+ opSource1.setInputType(inputType);
+ Map<String, Operation> sourceOperations = new HashMap<String, Operation>();
+ sourceOperations.put("op1", opSource1);
+ source.getInterface().getOperations().addAll(sourceOperations.values());
+
+ InterfaceContract target = new MockContract("FooContract");
+ List<DataType> targetInputTypes = new ArrayList<DataType>();
+ targetInputTypes.add(new DataTypeImpl<Type>(Object.class, Object.class));
+ DataType<List<DataType>> targetInputType = new DataTypeImpl<List<DataType>>(String.class, targetInputTypes);
+
+ Operation opTarget = newOperation("op1");
+ opTarget.setInputType(targetInputType);
+ Map<String, Operation> targetOperations = new HashMap<String, Operation>();
+ targetOperations.put("op1", opTarget);
+ target.getInterface().getOperations().addAll(targetOperations.values());
+ mapper.checkCompatibility(source, target, false, false);
+ }
+
+ public void testIncompatibleInputTypes() throws Exception {
+ InterfaceContract source = new MockContract("FooContract");
+ List<DataType> sourceInputTypes = new ArrayList<DataType>();
+ sourceInputTypes.add(new DataTypeImpl<Type>(Integer.class, Integer.class));
+ DataType<List<DataType>> inputType = new DataTypeImpl<List<DataType>>(String.class, sourceInputTypes);
+ Operation opSource1 = newOperation("op1");
+ opSource1.setInputType(inputType);
+ Map<String, Operation> sourceOperations = new HashMap<String, Operation>();
+ sourceOperations.put("op1", opSource1);
+ source.getInterface().getOperations().addAll(sourceOperations.values());
+
+ InterfaceContract target = new MockContract("FooContract");
+ List<DataType> targetInputTypes = new ArrayList<DataType>();
+ targetInputTypes.add(new DataTypeImpl<Type>(String.class, String.class));
+ DataType<List<DataType>> targetInputType = new DataTypeImpl<List<DataType>>(String.class, targetInputTypes);
+
+ Operation opTarget = newOperation("op1");
+ opTarget.setInputType(targetInputType);
+ Map<String, Operation> targetOperations = new HashMap<String, Operation>();
+ targetOperations.put("op1", opTarget);
+ target.getInterface().getOperations().addAll(targetOperations.values());
+ try {
+ mapper.checkCompatibility(source, target, false, false);
+ fail();
+ } catch (IncompatibleInterfaceContractException e) {
+ // expected
+ }
+ }
+
+ /**
+ * Verfies source input types can be super types of the target
+ */
+ public void testSourceSuperTypeInputCompatibility() throws Exception {
+ // InterfaceContract source = new MockContract("FooContract");
+ // List<DataType> sourceInputTypes = new ArrayList<DataType>();
+ // sourceInputTypes.add(new DataTypeImpl<Type>(Object.class,
+ // Object.class));
+ // DataType<List<DataType>> inputType = new
+ // DataTypeImpl<List<DataType>>(String.class, sourceInputTypes);
+ // Operation opSource1 = newOperationImpl("op1", inputType, null, null,
+ // false, null);
+ // Map<String, Operation> sourceOperations = new HashMap<String,
+ // Operation>();
+ // sourceOperations.put("op1", opSource1);
+ // source.getInterface().getOperations().addAll(sourceOperations.values());
+ //
+ // InterfaceContract target = new MockContract("FooContract");
+ // List<DataType> targetInputTypes = new ArrayList<DataType>();
+ // targetInputTypes.add(new DataTypeImpl<Type>(String.class,
+ // String.class));
+ // DataType<List<DataType>> targetInputType =
+ // new DataTypeImpl<List<DataType>>(String.class, targetInputTypes);
+ //
+ // Operation opTarget = newOperationImpl("op1", targetInputType, null,
+ // null, false, null);
+ // Map<String, Operation> targetOperations = new HashMap<String,
+ // Operation>();
+ // targetOperations.put("op1", opTarget);
+ // target.getInterface().getOperations().addAll(targetOperations.values());
+ // wireService.checkCompatibility(source, target, false);
+ }
+
+ public void testOutputTypes() throws Exception {
+ InterfaceContract source = new MockContract("FooContract");
+ DataType sourceOutputType = new DataTypeImpl<Type>(String.class, String.class);
+ Operation opSource1 = newOperation("op1");
+ opSource1.setOutputType(sourceOutputType);
+ Map<String, Operation> sourceOperations = new HashMap<String, Operation>();
+ sourceOperations.put("op1", opSource1);
+ source.getInterface().getOperations().addAll(sourceOperations.values());
+
+ InterfaceContract target = new MockContract("FooContract");
+ DataType targetOutputType = new DataTypeImpl<Type>(String.class, String.class);
+ Operation opTarget = newOperation("op1");
+ opTarget.setOutputType(targetOutputType);
+ Map<String, Operation> targetOperations = new HashMap<String, Operation>();
+ targetOperations.put("op1", opTarget);
+ target.getInterface().getOperations().addAll(targetOperations.values());
+ mapper.checkCompatibility(source, target, false, false);
+ }
+
+ /**
+ * Verifies a return type that is a supertype of of the target is compatible
+ */
+ public void testSupertypeOutputTypes() throws Exception {
+ // InterfaceContract source = new MockContract("FooContract");
+ // DataType sourceOutputType = new DataTypeImpl<Type>(Object.class,
+ // Object.class);
+ // Operation opSource1 = newOperationImpl("op1", null,
+ // sourceOutputType, null, false, null);
+ // Map<String, Operation> sourceOperations = new HashMap<String,
+ // Operation>();
+ // sourceOperations.put("op1", opSource1);
+ // source.getInterface().getOperations().addAll(sourceOperations.values());
+ //
+ // InterfaceContract target = new MockContract("FooContract");
+ // DataType targetOutputType = new DataTypeImpl<Type>(String.class,
+ // String.class);
+ // Operation opTarget = newOperationImpl("op1", null, targetOutputType,
+ // null, false, null);
+ // Map<String, Operation> targetOperations = new HashMap<String,
+ // Operation>();
+ // targetOperations.put("op1", opTarget);
+ // target.getInterface().getOperations().addAll(targetOperations.values());
+ // wireService.checkCompatibility(source, target, false);
+ }
+
+ public void testIncompatibleOutputTypes() throws Exception {
+ InterfaceContract source = new MockContract("FooContract");
+ DataType sourceOutputType = new DataTypeImpl<Type>(String.class, String.class);
+ Operation opSource1 = newOperation("op1");
+ opSource1.setOutputType(sourceOutputType);
+ Map<String, Operation> sourceOperations = new HashMap<String, Operation>();
+ sourceOperations.put("op1", opSource1);
+ source.getInterface().getOperations().addAll(sourceOperations.values());
+
+ InterfaceContract target = new MockContract("FooContract");
+ DataType targetOutputType = new DataTypeImpl<Type>(Integer.class, Integer.class);
+ Operation opTarget = newOperation("op1");
+ opTarget.setOutputType(targetOutputType);
+ Map<String, Operation> targetOperations = new HashMap<String, Operation>();
+ targetOperations.put("op1", opTarget);
+ target.getInterface().getOperations().addAll(targetOperations.values());
+ try {
+ mapper.checkCompatibility(source, target, false, false);
+ fail();
+ } catch (IncompatibleInterfaceContractException e) {
+ // expected
+ }
+ }
+
+ public void testFaultTypes() throws Exception {
+ InterfaceContract source = new MockContract("FooContract");
+ DataType sourceFaultType = new DataTypeImpl<Type>(String.class, String.class);
+ List<DataType> sourceFaultTypes = new ArrayList<DataType>();
+ sourceFaultTypes.add(0, sourceFaultType);
+ Operation opSource1 = newOperation("op1");
+ opSource1.setFaultTypes(sourceFaultTypes);
+ Map<String, Operation> sourceOperations = new HashMap<String, Operation>();
+ sourceOperations.put("op1", opSource1);
+ source.getInterface().getOperations().addAll(sourceOperations.values());
+
+ InterfaceContract target = new MockContract("FooContract");
+ DataType targetFaultType = new DataTypeImpl<Type>(String.class, String.class);
+ List<DataType> targetFaultTypes = new ArrayList<DataType>();
+ targetFaultTypes.add(0, targetFaultType);
+
+ Operation opTarget = newOperation("op1");
+ opTarget.setFaultTypes(targetFaultTypes);
+ Map<String, Operation> targetOperations = new HashMap<String, Operation>();
+ targetOperations.put("op1", opTarget);
+ target.getInterface().getOperations().addAll(targetOperations.values());
+ mapper.checkCompatibility(source, target, false, false);
+ }
+
+ public void testSourceFaultTargetNoFaultCompatibility() throws Exception {
+ InterfaceContract source = new MockContract("FooContract");
+ DataType sourceFaultType = new DataTypeImpl<Type>(String.class, String.class);
+ List<DataType> sourceFaultTypes = new ArrayList<DataType>();
+ sourceFaultTypes.add(0, sourceFaultType);
+ Operation opSource1 = newOperation("op1");
+ opSource1.setFaultTypes(sourceFaultTypes);
+ Map<String, Operation> sourceOperations = new HashMap<String, Operation>();
+ sourceOperations.put("op1", opSource1);
+ source.getInterface().getOperations().addAll(sourceOperations.values());
+
+ InterfaceContract target = new MockContract("FooContract");
+ Operation opTarget = newOperation("op1");
+ Map<String, Operation> targetOperations = new HashMap<String, Operation>();
+ targetOperations.put("op1", opTarget);
+ target.getInterface().getOperations().addAll(targetOperations.values());
+ mapper.checkCompatibility(source, target, false, false);
+ }
+
+ /**
+ * Verifies a source's fault which is a supertype of the target's fault are
+ * compatible
+ *
+ * @throws Exception
+ */
+ public void testFaultSuperTypes() throws Exception {
+ // InterfaceContract source = new MockContract("FooContract");
+ // DataType sourceFaultType = new DataTypeImpl<Type>(Exception.class,
+ // Exception.class);
+ // List<DataType> sourceFaultTypes = new ArrayList<DataType>();
+ // sourceFaultTypes.add(0, sourceFaultType);
+ // Operation opSource1 = newOperationImpl("op1", null, null,
+ // sourceFaultTypes, false, null);
+ // Map<String, Operation> sourceOperations = new HashMap<String,
+ // Operation>();
+ // sourceOperations.put("op1", opSource1);
+ // source.getInterface().getOperations().addAll(sourceOperations.values());
+ //
+ // InterfaceContract target = new MockContract("FooContract");
+ // DataType targetFaultType = new
+ // DataTypeImpl<Type>(TuscanyException.class, TuscanyException.class);
+ // List<DataType> targetFaultTypes = new ArrayList<DataType>();
+ // targetFaultTypes.add(0, targetFaultType);
+ //
+ // Operation opTarget = newOperationImpl("op1", null, null,
+ // targetFaultTypes, false, null);
+ // Map<String, Operation> targetOperations = new HashMap<String,
+ // Operation>();
+ // targetOperations.put("op1", opTarget);
+ // target.getInterface().getOperations().addAll(targetOperations.values());
+ // wireService.checkCompatibility(source, target, false);
+ }
+
+ /**
+ * Verifies a source's faults which are supertypes and a superset of the
+ * target's faults are compatible
+ */
+ public void testFaultSuperTypesAndSuperset() throws Exception {
+ // InterfaceContract source = new MockContract("FooContract");
+ // DataType sourceFaultType = new DataTypeImpl<Type>(Exception.class,
+ // Exception.class);
+ // DataType sourceFaultType2 = new
+ // DataTypeImpl<Type>(RuntimeException.class, RuntimeException.class);
+ // List<DataType> sourceFaultTypes = new ArrayList<DataType>();
+ // sourceFaultTypes.add(0, sourceFaultType);
+ // sourceFaultTypes.add(1, sourceFaultType2);
+ // Operation opSource1 = newOperationImpl("op1", null, null,
+ // sourceFaultTypes, false, null);
+ // Map<String, Operation> sourceOperations = new HashMap<String,
+ // Operation>();
+ // sourceOperations.put("op1", opSource1);
+ // source.getInterface().getOperations().addAll(sourceOperations.values());
+ //
+ // InterfaceContract target = new MockContract("FooContract");
+ // DataType targetFaultType = new
+ // DataTypeImpl<Type>(TuscanyException.class, TuscanyException.class);
+ // List<DataType> targetFaultTypes = new ArrayList<DataType>();
+ // targetFaultTypes.add(0, targetFaultType);
+ //
+ // Operation opTarget = newOperationImpl("op1", null, null,
+ // targetFaultTypes, false, null);
+ // Map<String, Operation> targetOperations = new HashMap<String,
+ // Operation>();
+ // targetOperations.put("op1", opTarget);
+ // target.getInterface().getOperations().addAll(targetOperations.values());
+ // wireService.checkCompatibility(source, target, false);
+ }
+
+ private static class MockInterface extends InterfaceImpl {
+
+ }
+
+ private class MockContract<T> extends InterfaceContractImpl {
+ public MockContract() {
+ }
+
+ public MockContract(String interfaceClass) {
+ Interface jInterface = new MockInterface();
+ setInterface(jInterface);
+ }
+ }
+
+ private static Operation newOperation(String name) {
+ Operation operation = new OperationImpl();
+ operation.setName(name);
+ return operation;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/interface/src/test/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractTestCase.java b/sca-java-1.x/branches/sca-android/modules/interface/src/test/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractTestCase.java
new file mode 100644
index 0000000000..338170da52
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/interface/src/test/java/org/apache/tuscany/sca/interfacedef/impl/InterfaceContractTestCase.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.interfacedef.impl;
+
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class InterfaceContractTestCase {
+ private InterfaceContract contract;
+ /**
+ * @throws java.lang.Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ contract = new MockInterfaceContract();
+ Interface i1 = new MockInterface();
+ contract.setInterface(i1);
+ Operation op1 = newOperation("op1");
+ i1.getOperations().add(op1);
+ Interface i2 = new MockInterface();
+ contract.setCallbackInterface(i2);
+ Operation callbackOp1 = newOperation("callbackOp1");
+ i2.getOperations().add(callbackOp1);
+ }
+
+ @Test
+ public void testClone() throws Exception {
+ InterfaceContract copy = (InterfaceContract) contract.clone();
+ Assert.assertEquals(contract, copy);
+ }
+
+ private static class MockInterfaceContract extends InterfaceContractImpl implements InterfaceContract {
+ }
+
+ private static class MockInterface extends InterfaceImpl implements Interface {
+ }
+
+ private static Operation newOperation(String name) {
+ Operation operation = new OperationImpl();
+ operation.setName(name);
+ return operation;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/monitor/LICENSE b/sca-java-1.x/branches/sca-android/modules/monitor/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/monitor/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/monitor/META-INF/README b/sca-java-1.x/branches/sca-android/modules/monitor/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/monitor/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/monitor/NOTICE b/sca-java-1.x/branches/sca-android/modules/monitor/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/monitor/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/monitor/pom.xml b/sca-java-1.x/branches/sca-android/modules/monitor/pom.xml
new file mode 100644
index 0000000000..44990c4c02
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/monitor/pom.xml
@@ -0,0 +1,57 @@
+<?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.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>tuscany-monitor</artifactId>
+ <name>Apache Tuscany SCA Monitor</name>
+
+ <dependencies>
+
+
+ </dependencies>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.monitor</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.monitor*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Monitor.java b/sca-java-1.x/branches/sca-android/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Monitor.java
new file mode 100644
index 0000000000..c16140213d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Monitor.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.monitor;
+
+import java.util.List;
+
+/**
+ * A monitor for the watching for validation problems
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Monitor {
+ /**
+ * Reports a build problem.
+ *
+ * @param problem
+ */
+ void problem(Problem problem);
+
+ /**
+ * Returns a list of reported problems.
+ *
+ * @return the list of problems. The list may be empty
+ */
+ List<Problem> getProblems();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/MonitorFactory.java b/sca-java-1.x/branches/sca-android/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/MonitorFactory.java
new file mode 100644
index 0000000000..38c3bbd991
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/MonitorFactory.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.monitor;
+
+/**
+ * A factory for validation monitors
+ *
+ * @version $Rev$ $Date$
+ */
+public interface MonitorFactory {
+
+ /**
+ * Create a new monitor
+ *
+ * @return a new monitor
+ */
+ Monitor createMonitor();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Problem.java b/sca-java-1.x/branches/sca-android/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Problem.java
new file mode 100644
index 0000000000..83a2d63eae
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/Problem.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.monitor;
+
+
+/**
+ * Records an validation problem.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Problem {
+
+ public enum Severity {
+ INFO,
+ WARNING,
+ ERROR
+ }
+
+ String getSourceClassName();
+
+ String getBundleName();
+
+ Severity getSeverity();
+
+ Object getProblemObject();
+
+ String getMessageId();
+
+ Exception getCause();
+
+ Object[] getMessageParams();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/DefaultMonitorFactoryImpl.java b/sca-java-1.x/branches/sca-android/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/DefaultMonitorFactoryImpl.java
new file mode 100644
index 0000000000..274b4faefd
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/DefaultMonitorFactoryImpl.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.monitor.impl;
+
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+
+
+/**
+ * A factory for creating validation monitors
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultMonitorFactoryImpl implements MonitorFactory {
+
+ private Monitor monitor = null;
+
+ public Monitor createMonitor() {
+ if (monitor == null){
+ monitor = new DefaultMonitorImpl();
+ }
+ return monitor ;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/DefaultMonitorImpl.java b/sca-java-1.x/branches/sca-android/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/DefaultMonitorImpl.java
new file mode 100644
index 0000000000..b98f29d4dd
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/monitor/src/main/java/org/apache/tuscany/sca/monitor/impl/DefaultMonitorImpl.java
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.monitor.impl;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+
+/**
+ * A monitor for the watching for validation problems
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultMonitorImpl implements Monitor {
+ private static final Logger logger = Logger.getLogger(DefaultMonitorImpl.class.getName());
+
+ // Cache all the problem reported to monitor for further analysis
+ private List<Problem> problemCache = new ArrayList<Problem>();
+
+ public void problem(Problem problem) {
+
+ Logger problemLogger = Logger.getLogger(problem.getSourceClassName(), problem.getBundleName());
+
+ if (problemLogger == null){
+ logger.severe("Can't get logger " + problem.getSourceClassName()+ " with bundle " + problem.getBundleName());
+ }
+
+ if (problem.getSeverity() == Severity.INFO) {
+ problemCache.add(problem);
+ problemLogger.logp(Level.INFO, problem.getSourceClassName(), null,
+ problem.getMessageId(), problem.getMessageParams());
+ }
+ else if (problem.getSeverity() == Severity.WARNING) {
+ problemCache.add(problem);
+ problemLogger.logp(Level.WARNING, problem.getSourceClassName(), null,
+ problem.getMessageId(), problem.getMessageParams());
+ }
+ else if (problem.getSeverity() == Severity.ERROR) {
+ if (problem.getCause() != null) {
+ problemCache.add(problem);
+ problemLogger.logp(Level.SEVERE, problem.getSourceClassName(),
+ null, problem.getMessageId(), problem.getCause().toString());
+
+ } else {
+ problemCache.add(problem);
+ problemLogger.logp(Level.SEVERE, problem.getSourceClassName(), null,
+ problem.getMessageId(), problem.getMessageParams());
+ }
+ }
+ }
+
+ public List<Problem> getProblems(){
+ return problemCache;
+ }
+
+ public Problem getLastLoggedProblem(){
+ return problemCache.get(problemCache.size() - 1);
+ }
+
+ public boolean isMessageLogged(String messageId) {
+ for (Problem problem : problemCache){
+ if (problem.getMessageId().equals(messageId)){
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public Problem getProblem(String messageId) {
+ for (Problem problem : problemCache){
+ if (problem.getMessageId().equals(messageId)){
+ return problem;
+ }
+ }
+
+ return null;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/node-api/LICENSE b/sca-java-1.x/branches/sca-android/modules/node-api/LICENSE
new file mode 100644
index 0000000000..6e529a25c4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-api/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/node-api/META-INF/README b/sca-java-1.x/branches/sca-android/modules/node-api/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-api/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/node-api/NOTICE b/sca-java-1.x/branches/sca-android/modules/node-api/NOTICE
new file mode 100644
index 0000000000..1325efd8bf
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-api/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/node-api/pom.xml b/sca-java-1.x/branches/sca-android/modules/node-api/pom.xml
new file mode 100644
index 0000000000..02210daa88
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-api/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>
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>tuscany-node-api</artifactId>
+ <name>Apache Tuscany SCA Node API</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-sca-api</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.node.api</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.node*</Export-Package>
+ <DynamicImport-Package>org.apache.tuscany.sca.node.impl,org.apache.tuscany.sca.extensibility</DynamicImport-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCAClient.java b/sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCAClient.java
new file mode 100644
index 0000000000..f390e8881e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCAClient.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.node;
+
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ServiceReference;
+
+
+/**
+ * Provides client access to the services in a domain.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface SCAClient {
+
+ /**
+ * Cast a type-safe reference to a CallahbleReference. Converts a type-safe
+ * reference to an equivalent CallableReference; if the target refers to a
+ * service then a ServiceReference will be returned, if the target refers to
+ * a callback then a CallableReference will be returned.
+ *
+ * @param target a reference proxy provided by the SCA runtime
+ * @param <B> the Java type of the business interface for the reference
+ * @param <R> the type of reference to be returned
+ * @return a CallableReference equivalent for the proxy
+ * @throws IllegalArgumentException if the supplied instance is not a
+ * reference supplied by the SCA runtime
+ */
+ <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException;
+
+ /**
+ * Returns a proxy for a service provided by a component in the SCA domain.
+ *
+ * @param businessInterface the interface that will be used to invoke the
+ * service
+ * @param serviceName the name of the service
+ * @param <B> the Java type of the business interface for the service
+ * @return an object that implements the business interface
+ */
+ <B> B getService(Class<B> businessInterface, String serviceName);
+
+ /**
+ * Returns a ServiceReference for a service provided by a component in the
+ * SCA domain.
+ *
+ * @param businessInterface the interface that will be used to invoke the
+ * service
+ * @param serviceName the name of the service
+ * @param <B> the Java type of the business interface for the service
+ * @return a ServiceReference for the designated service
+ */
+ <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String serviceName);
+
+} \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCAContribution.java b/sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCAContribution.java
new file mode 100644
index 0000000000..de7f352122
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCAContribution.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.node;
+
+/**
+ * Represents an SCA contribution uri + location.
+ */
+public final class SCAContribution {
+ private String uri;
+ private String location;
+
+ /**
+ * Constructs a new SCA contribution.
+ *
+ * @param uri The URI that uniquely identifies the contribution in the SCA domain
+ * @param location The URL of the contribution archive
+ */
+ public SCAContribution(String uri, String location) {
+ this.uri = uri;
+ this.location = location;
+ }
+
+ /**
+ * Get the URI of the contribution
+ * @return The URI that uniquely identifies the contribution in the SCA domain
+ */
+ public String getURI() {
+ return uri;
+ }
+
+ /**
+ * The location of the contribution
+ * @return The URL of the contribution archive
+ */
+ public String getLocation() {
+ return location;
+ }
+} \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode.java b/sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode.java
new file mode 100644
index 0000000000..fea749a57c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.node;
+
+
+
+/**
+ * Represents an SCA processing node.
+ * A node is loaded with an SCA composites. It can start and stop that composite.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface SCANode {
+
+ /**
+ * Start the composite loaded in the node.
+ */
+ void start();
+
+ /**
+ * Stop the composite loaded in the node.
+ */
+ void stop();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode2.java b/sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode2.java
new file mode 100644
index 0000000000..a1d4ddb2b1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode2.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.node;
+
+
+
+/**
+ * Represents an SCA processing node.
+ * A node is loaded with an SCA composites. It can start and stop that composite.
+ *
+ * @version $Rev$ $Date$
+ * @deprecated Use SCANode instead
+ */
+@Deprecated
+public interface SCANode2 extends SCANode {
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode2Factory.java b/sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode2Factory.java
new file mode 100644
index 0000000000..2b0dbc88eb
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode2Factory.java
@@ -0,0 +1,203 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.node;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * A factory for SCA processing nodes. An SCA processing node can be loaded
+ * with an SCA composite and the SCA contributions required by the composite.
+ *
+ * @version $Rev$ $Date$
+ * @deprecated Use SCANodeFactory
+ */
+@Deprecated
+public abstract class SCANode2Factory {
+
+ public static class NodeProxy implements SCANode2, SCAClient {
+ private Object node;
+
+ private NodeProxy(Object node) {
+ super();
+ this.node = node;
+ }
+
+ public static <T> T createProxy(Class<T> type, Object node) {
+ try {
+ return type.getDeclaredConstructor(Object.class).newInstance(node);
+ } catch (Exception e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+ try {
+ return (R)node.getClass().getMethod("cast", Object.class).invoke(node, target);
+ } catch (Throwable e) {
+ handleException(e);
+ return null;
+ }
+ }
+
+ public <B> B getService(Class<B> businessInterface, String serviceName) {
+ try {
+ return (B)node.getClass().getMethod("getService", Class.class, String.class).invoke(node,
+ businessInterface,
+ serviceName);
+ } catch (Throwable e) {
+ handleException(e);
+ return null;
+ }
+ }
+
+ public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String serviceName) {
+ try {
+ return (ServiceReference<B>)node.getClass().getMethod("getServiceReference", Class.class, String.class)
+ .invoke(node, businessInterface, serviceName);
+ } catch (Throwable e) {
+ handleException(e);
+ return null;
+ }
+ }
+
+ public void start() {
+ try {
+ node.getClass().getMethod("start").invoke(node);
+ } catch (Throwable e) {
+ handleException(e);
+ }
+ }
+
+ public void stop() {
+ try {
+ node.getClass().getMethod("stop").invoke(node);
+ } catch (Throwable e) {
+ handleException(e);
+ }
+ }
+
+ private static void handleException(Throwable ex) {
+ if (ex instanceof InvocationTargetException) {
+ ex = ((InvocationTargetException)ex).getTargetException();
+ }
+ if (ex instanceof RuntimeException) {
+ throw (RuntimeException)ex;
+ }
+ if (ex instanceof Error) {
+ throw (Error)ex;
+ } else {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ }
+
+ /**
+ * Returns a new SCA node factory instance.
+ *
+ * @return a new SCA node factory
+ */
+ public static SCANode2Factory newInstance() {
+ SCANode2Factory scaNodeFactory = null;
+
+ try {
+ final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ // Use reflection APIs to call ServiceDiscovery to avoid hard dependency to tuscany-extensibility
+ try {
+ Class<?> discoveryClass =
+ Class.forName("org.apache.tuscany.sca.extensibility.ServiceDiscovery", true, classLoader);
+ Object instance = discoveryClass.getMethod("getInstance").invoke(null);
+ Class<?> factoryImplClass =
+ (Class<?>)discoveryClass.getMethod("loadFirstServiceClass", Class.class)
+ .invoke(instance, SCANode2Factory.class);
+ if (factoryImplClass != null) {
+ scaNodeFactory = (SCANode2Factory)factoryImplClass.newInstance();
+ return scaNodeFactory;
+ }
+ } catch (ClassNotFoundException e) {
+ // Ignore
+ }
+
+ // Fail back to default impl
+ String className = "org.apache.tuscany.sca.node.impl.Node2FactoryImpl";
+
+ Class<?> cls = Class.forName(className, true, classLoader);
+ scaNodeFactory = (SCANode2Factory)cls.newInstance();
+ return scaNodeFactory;
+
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ /**
+ * Create a SCA node based on the discovery of the contribution on the classpath for the
+ * given classloader. This method should be treated a convinient shortcut with the following
+ * assumptions:
+ * <ul>
+ * <li>This is a standalone application and there is a deployable composite file on the classpath.
+ * <li>There is only one contribution which contains the deployable composite file physically in its packaging hierarchy.
+ * </ul>
+ * @param compositeURI The URI of the composite file relative to the root of the enclosing contribution
+ * @param classLoader The ClassLoader used to load the composite file as a resource. If the value is null,
+ * then thread context classloader will be used
+ * @return A newly created SCA node
+ */
+ public abstract SCANode2 createSCANodeFromClassLoader(String compositeURI, ClassLoader classLoader);
+
+ /**
+ * Creates a new SCA node from the configuration URL
+ *
+ * @param configurationURL the URL of the node configuration which is the ATOM feed
+ * that contains the URI of the composite and a collection of URLs for the contributions
+ *
+ * @return a new SCA node.
+ */
+ public abstract SCANode2 createSCANodeFromURL(String configurationURL);
+
+ /**
+ * Creates a new SCA node.
+ *
+ * @param compositeURI the URI of the composite to use
+ * @param contributions the URI of the contributions that provides the composites and related
+ * artifacts. If the list is empty, then we will use the thread context classloader to discover
+ * the contribution on the classpath
+ *
+ * @return a new SCA node.
+ */
+ public abstract SCANode2 createSCANode(String compositeURI, SCAContribution... contributions);
+
+ /**
+ * Creates a new SCA node.
+ *
+ * @param compositeURI the URI of the composite to use
+ * @param compositeContent the XML content of the composite to use
+ * @param contributions the URI of the contributions that provides the composites and related artifacts
+ * @return a new SCA node.
+ */
+ public abstract SCANode2 createSCANode(String compositeURI,
+ String compositeContent,
+ SCAContribution... contributions);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANodeFactory.java b/sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANodeFactory.java
new file mode 100644
index 0000000000..e41afd29c4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANodeFactory.java
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.node;
+
+import java.lang.reflect.InvocationTargetException;
+
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * A factory for SCA processing nodes. An SCA processing node can be loaded
+ * with an SCA composite and the SCA contributions required by the composite.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class SCANodeFactory {
+
+ public static class NodeProxy implements SCANode, SCAClient {
+ private Object node;
+
+ private NodeProxy(Object node) {
+ super();
+ this.node = node;
+ }
+
+ public static <T> T createProxy(Class<T> type, Object node) {
+ try {
+ return type.getDeclaredConstructor(Object.class).newInstance(node);
+ } catch (Exception e) {
+ throw new IllegalArgumentException(e);
+ }
+ }
+
+ public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+ try {
+ return (R)node.getClass().getMethod("cast", Object.class).invoke(node, target);
+ } catch (Throwable e) {
+ handleException(e);
+ return null;
+ }
+ }
+
+ public <B> B getService(Class<B> businessInterface, String serviceName) {
+ try {
+ return (B)node.getClass().getMethod("getService", Class.class, String.class).invoke(node,
+ businessInterface,
+ serviceName);
+ } catch (Throwable e) {
+ handleException(e);
+ return null;
+ }
+ }
+
+ public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String serviceName) {
+ try {
+ return (ServiceReference<B>)node.getClass().getMethod("getServiceReference", Class.class, String.class)
+ .invoke(node, businessInterface, serviceName);
+ } catch (Throwable e) {
+ handleException(e);
+ return null;
+ }
+ }
+
+ public void start() {
+ try {
+ node.getClass().getMethod("start").invoke(node);
+ } catch (Throwable e) {
+ handleException(e);
+ }
+ }
+
+ public void stop() {
+ try {
+ node.getClass().getMethod("stop").invoke(node);
+ } catch (Throwable e) {
+ handleException(e);
+ }
+ }
+
+ private static void handleException(Throwable ex) {
+ if (ex instanceof InvocationTargetException) {
+ ex = ((InvocationTargetException)ex).getTargetException();
+ }
+ if (ex instanceof RuntimeException) {
+ throw (RuntimeException)ex;
+ }
+ if (ex instanceof Error) {
+ throw (Error)ex;
+ } else {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ }
+
+ /**
+ * Returns a new SCA node factory instance.
+ *
+ * @return a new SCA node factory
+ */
+ public static SCANodeFactory newInstance() {
+ SCANodeFactory scaNodeFactory = null;
+
+ try {
+ // final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ // Use reflection APIs to call ServiceDiscovery to avoid hard dependency to tuscany-extensibility
+ try {
+ Class<?> discoveryClass =
+ Class.forName("org.apache.tuscany.sca.extensibility.ServiceDiscovery");
+ Object instance = discoveryClass.getMethod("getInstance").invoke(null);
+ Class<?> factoryImplClass =
+ (Class<?>)discoveryClass.getMethod("loadFirstServiceClass", Class.class)
+ .invoke(instance, SCANodeFactory.class);
+ if (factoryImplClass != null) {
+ scaNodeFactory = (SCANodeFactory)factoryImplClass.newInstance();
+ return scaNodeFactory;
+ }
+ } catch (ClassNotFoundException e) {
+ // Ignore
+ }
+
+ // Fail back to default impl
+ String className = "org.apache.tuscany.sca.node.impl.NodeFactoryImpl";
+
+ Class<?> cls = Class.forName(className);
+ scaNodeFactory = (SCANodeFactory)cls.newInstance();
+ return scaNodeFactory;
+
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ /**
+ * Create a SCA node based on the discovery of the contribution on the classpath for the
+ * given classloader. This method should be treated a convinient shortcut with the following
+ * assumptions:
+ * <ul>
+ * <li>This is a standalone application and there is a deployable composite file on the classpath.
+ * <li>There is only one contribution which contains the deployable composite file physically in its packaging hierarchy.
+ * </ul>
+ * @param compositeURI The URI of the composite file relative to the root of the enclosing contribution
+ * @param classLoader The ClassLoader used to load the composite file as a resource. If the value is null,
+ * then thread context classloader will be used
+ * @return A newly created SCA node
+ */
+ public abstract SCANode createSCANodeFromClassLoader(String compositeURI, ClassLoader classLoader);
+
+ /**
+ * Creates a new SCA node from the configuration URL
+ *
+ * @param configurationURL the URL of the node configuration which is the ATOM feed
+ * that contains the URI of the composite and a collection of URLs for the contributions
+ *
+ * @return a new SCA node.
+ */
+ public abstract SCANode createSCANodeFromURL(String configurationURL);
+
+ /**
+ * Creates a new SCA node.
+ *
+ * @param compositeURI the URI of the composite to use
+ * @param contributions the URI of the contributions that provides the composites and related
+ * artifacts. If the list is empty, then we will use the thread context classloader to discover
+ * the contribution on the classpath
+ *
+ * @return a new SCA node.
+ */
+ public abstract SCANode createSCANode(String compositeURI, SCAContribution... contributions);
+
+ /**
+ * Creates a new SCA node.
+ *
+ * @param compositeURI the URI of the composite to use
+ * @param compositeContent the XML content of the composite to use
+ * @param contributions the URI of the contributions that provides the composites and related artifacts
+ * @return a new SCA node.
+ */
+ public abstract SCANode createSCANode(String compositeURI,
+ String compositeContent,
+ SCAContribution... contributions);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/node-impl/LICENSE b/sca-java-1.x/branches/sca-android/modules/node-impl/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-impl/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/node-impl/META-INF/README b/sca-java-1.x/branches/sca-android/modules/node-impl/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-impl/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/node-impl/NOTICE b/sca-java-1.x/branches/sca-android/modules/node-impl/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-impl/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/node-impl/pom.xml b/sca-java-1.x/branches/sca-android/modules/node-impl/pom.xml
new file mode 100644
index 0000000000..f932c9abc4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-impl/pom.xml
@@ -0,0 +1,154 @@
+<?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.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>tuscany-node-impl</artifactId>
+ <name>Apache Tuscany SCA Node Implementation</name>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-node-api</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-implementation-node</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution-impl</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-definitions-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-binding-sca</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-binding-sca-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-policy-xml</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-core-databinding</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-assembly-xsd</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-endpoint</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>runtime</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-implementation-java-runtime</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.node.impl</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.node.impl*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/Node2FactoryImpl.java b/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/Node2FactoryImpl.java
new file mode 100644
index 0000000000..419900c5ac
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/Node2FactoryImpl.java
@@ -0,0 +1,57 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.node.impl;
+
+import org.apache.tuscany.sca.node.SCAContribution;
+import org.apache.tuscany.sca.node.SCANode2;
+import org.apache.tuscany.sca.node.SCANode2Factory;
+
+/**
+ * Default implementation of an SCA node factory.
+ *
+ * @version $Rev$ $Date$
+ * @deprecated
+ */
+@Deprecated
+public class Node2FactoryImpl extends SCANode2Factory {
+ public Node2FactoryImpl() {
+ }
+
+ @Override
+ public SCANode2 createSCANodeFromClassLoader(String compositeURI, ClassLoader classLoader) {
+ return new Node2Impl(classLoader, compositeURI);
+ }
+
+ @Override
+ public SCANode2 createSCANodeFromURL(String configurationURI) {
+ return new Node2Impl(configurationURI);
+ }
+
+ @Override
+ public SCANode2 createSCANode(String compositeURI, SCAContribution... contributions) {
+ return new Node2Impl(compositeURI, contributions);
+ }
+
+ @Override
+ public SCANode2 createSCANode(String compositeURI, String compositeContent, SCAContribution... contributions) {
+ return new Node2Impl(compositeURI, compositeContent, contributions);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/Node2Impl.java b/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/Node2Impl.java
new file mode 100644
index 0000000000..bc2f10fb7e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/Node2Impl.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.node.impl;
+
+import org.apache.tuscany.sca.node.SCAContribution;
+import org.apache.tuscany.sca.node.SCANode2;
+
+/**
+ * Node2 Impl
+ */
+public class Node2Impl extends NodeImpl implements SCANode2 {
+
+ /**
+ * @param configurationURI
+ */
+ public Node2Impl(String configurationURI) {
+ super(configurationURI);
+ // TODO Auto-generated constructor stub
+ }
+
+ /**
+ * @param classLoader
+ * @param compositeURI
+ */
+ public Node2Impl(ClassLoader classLoader, String compositeURI) {
+ super(classLoader, compositeURI);
+ }
+
+ /**
+ * @param compositeURI
+ * @param contributions
+ */
+ public Node2Impl(String compositeURI, SCAContribution[] contributions) {
+ super(compositeURI, contributions);
+ }
+
+ /**
+ * @param compositeURI
+ * @param compositeContent
+ * @param contributions
+ */
+ public Node2Impl(String compositeURI, String compositeContent, SCAContribution[] contributions) {
+ super(compositeURI, compositeContent, contributions);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java b/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java
new file mode 100644
index 0000000000..18b166acdd
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.node.impl;
+
+import org.apache.tuscany.sca.node.SCAContribution;
+import org.apache.tuscany.sca.node.SCANode;
+import org.apache.tuscany.sca.node.SCANodeFactory;
+
+/**
+ * Default implementation of an SCA node factory.
+ *
+ * @version $Rev$ $Date$
+ */
+public class NodeFactoryImpl extends SCANodeFactory {
+ public NodeFactoryImpl() {
+ }
+
+ @Override
+ public SCANode createSCANodeFromClassLoader(String compositeURI, ClassLoader classLoader) {
+ return new NodeImpl(classLoader, compositeURI);
+ }
+
+ @Override
+ public SCANode createSCANodeFromURL(String configurationURI) {
+ return new NodeImpl(configurationURI);
+ }
+
+ @Override
+ public SCANode createSCANode(String compositeURI, SCAContribution... contributions) {
+ return new NodeImpl(compositeURI, contributions);
+ }
+
+ @Override
+ public SCANode createSCANode(String compositeURI, String compositeContent, SCAContribution... contributions) {
+ return new NodeImpl(compositeURI, compositeContent, contributions);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java b/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
new file mode 100644
index 0000000000..a8a076a602
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java
@@ -0,0 +1,824 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+
+package org.apache.tuscany.sca.node.impl;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Component;
+import org.apache.tuscany.sca.assembly.ComponentService;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.CompositeService;
+import org.apache.tuscany.sca.assembly.xml.CompositeDocumentProcessor;
+import org.apache.tuscany.sca.contribution.Artifact;
+import org.apache.tuscany.sca.contribution.Contribution;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionService;
+import org.apache.tuscany.sca.contribution.service.util.FileHelper;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.core.assembly.ActivationException;
+import org.apache.tuscany.sca.core.assembly.CompositeActivator;
+import org.apache.tuscany.sca.implementation.node.ConfiguredNodeImplementation;
+import org.apache.tuscany.sca.implementation.node.NodeImplementationFactory;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+import org.apache.tuscany.sca.node.SCAClient;
+import org.apache.tuscany.sca.node.SCAContribution;
+import org.apache.tuscany.sca.node.SCANode;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentContext;
+import org.osoa.sca.CallableReference;
+import org.osoa.sca.ServiceReference;
+import org.osoa.sca.ServiceRuntimeException;
+
+/**
+ * A local representation of the SCADomain running on a single node
+ *
+ * @version $Rev$ $Date$
+ */
+public class NodeImpl implements SCANode, SCAClient {
+
+ private static final Logger logger = Logger.getLogger(NodeImpl.class.getName());
+
+ // The node configuration name, used for logging
+ private String configurationName;
+
+ // The Tuscany runtime that does the hard work
+ private RuntimeBootStrapper runtime;
+ private CompositeActivator compositeActivator;
+ private XMLInputFactory inputFactory;
+ private ModelFactoryExtensionPoint modelFactories;
+ private StAXArtifactProcessorExtensionPoint artifactProcessors;
+ private URLArtifactProcessorExtensionPoint documentProcessors;
+ private Monitor monitor;
+
+ private List<Contribution> contributions;
+ // The composite loaded into this node
+ private Composite composite;
+
+ /**
+ * Constructs a new SCA node.
+ *
+ * @param configurationURI the URI of the node configuration information.
+ */
+ NodeImpl(String configurationURI) {
+ configurationName = configurationURI;
+ logger.log(Level.INFO, "Creating node: " + configurationName);
+
+ try {
+ // Initialize the runtime
+ initRuntime();
+
+ // Read the node configuration feed
+ StAXArtifactProcessor<ConfiguredNodeImplementation> configurationProcessor =
+ artifactProcessors.getProcessor(ConfiguredNodeImplementation.class);
+ URL configurationURL = new URL(configurationURI);
+ InputStream is = configurationURL.openStream();
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ reader.nextTag();
+ ConfiguredNodeImplementation configuration = configurationProcessor.read(reader);
+ is.close();
+
+ // Resolve contribution URLs
+ for (Contribution contribution : configuration.getContributions()) {
+ URL contributionURL = new URL(configurationURL, contribution.getLocation());
+ contribution.setLocation(contributionURL.toString());
+ }
+
+ // Resolve composite URL
+ URL compositeURL = new URL(configurationURL, configuration.getComposite().getURI());
+ configuration.getComposite().setURI(compositeURL.toString());
+
+ // Configure the node
+ configureNode(configuration);
+
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ /**
+ * Construct a node by discovering the node configuration (composite+contrbutions) on the classpath
+ * @param classLoader
+ * @param compositeURI
+ */
+ NodeImpl(ClassLoader classLoader, String compositeURI) {
+ configurationName = compositeURI;
+ logger.log(Level.INFO, "Creating node: " + configurationName);
+
+ if (compositeURI != null) {
+ URI uri = URI.create(compositeURI);
+ if (uri.isAbsolute()) {
+ throw new IllegalArgumentException("Composite URI must be a resource name: " + compositeURI);
+ }
+ }
+ try {
+ // Initialize the runtime
+ initRuntime();
+
+ ConfiguredNodeImplementation config = findNodeConfiguration(compositeURI, classLoader);
+ configureNode(config);
+ } catch (Throwable e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ /**
+ * Discover the contribution on the classpath
+ * @param compositeURI
+ * @param classLoader
+ * @return A configured node implementation
+ * @throws Exception
+ */
+ private ConfiguredNodeImplementation findNodeConfiguration(final String compositeURI, ClassLoader classLoader)
+ throws Exception {
+ NodeImplementationFactory nodeImplementationFactory =
+ modelFactories.getFactory(NodeImplementationFactory.class);
+ ConfiguredNodeImplementation config = nodeImplementationFactory.createConfiguredNodeImplementation();
+
+ // Default to thread context classloader
+ if (classLoader == null) {
+ classLoader = Thread.currentThread().getContextClassLoader();
+ }
+ String contributionArtifactPath = compositeURI;
+ URL contributionArtifactURL = null;
+ if (compositeURI != null) {
+ contributionArtifactURL = getResource(classLoader, compositeURI);
+ if (contributionArtifactURL == null) {
+ throw new IllegalArgumentException("Composite not found: " + contributionArtifactPath);
+ }
+ // Set to relative URI to avoid duplicate loading
+ Composite composite = createComposite(compositeURI);
+ config.setComposite(composite);
+ } else {
+ // No composite is specified, tring to search the SCA metadata files
+ contributionArtifactPath = Contribution.SCA_CONTRIBUTION_META;
+ contributionArtifactURL = getResource(classLoader, Contribution.SCA_CONTRIBUTION_META);
+
+ if (contributionArtifactURL == null) {
+ contributionArtifactPath = Contribution.SCA_CONTRIBUTION_GENERATED_META;
+ contributionArtifactURL = getResource(classLoader, Contribution.SCA_CONTRIBUTION_GENERATED_META);
+ }
+ if (contributionArtifactURL == null) {
+ contributionArtifactPath = Contribution.SCA_CONTRIBUTION_DEPLOYABLES;
+ contributionArtifactURL = getResource(classLoader, Contribution.SCA_CONTRIBUTION_DEPLOYABLES);
+ }
+
+ // No contribution can be discovered
+ if (contributionArtifactURL == null) {
+ throw new IllegalArgumentException("No default contribution can be discovered on the classpath");
+ }
+
+ // No composite will be created, all deployable composites will be used later
+ }
+
+ Contribution c = getContribution(contributionArtifactURL, contributionArtifactPath);
+ config.getContributions().add(c);
+
+ return config;
+ }
+
+ private Contribution getContribution(URL contributionArtifactURL, String contributionArtifactPath) {
+ URL contributionURL = getContributionURL(contributionArtifactURL, contributionArtifactPath);
+
+ ContributionFactory contributionFactory = modelFactories.getFactory(ContributionFactory.class);
+
+ SCAContribution contribution = new SCAContribution(contributionURL.toString(), contributionURL.toString());
+ Contribution c = createContribution(contributionFactory, contribution);
+ return c;
+ }
+
+ public static URL getContributionURL(URL contributionArtifactURL, String contributionArtifactPath) {
+ URL contributionURL = null;
+ // "jar:file://....../something.jar!/a/b/c/app.composite"
+ try {
+ String url = contributionArtifactURL.toExternalForm();
+ String protocol = contributionArtifactURL.getProtocol();
+ if ("file".equals(protocol)) {
+ // directory contribution
+ if (url.endsWith(contributionArtifactPath)) {
+ final String location = url.substring(0, url.lastIndexOf(contributionArtifactPath));
+ // workaround from evil URL/URI form Maven
+ // contributionURL = FileHelper.toFile(new URL(location)).toURI().toURL();
+ // Allow privileged access to open URL stream. Add FilePermission to added to
+ // security policy file.
+ try {
+ contributionURL = AccessController.doPrivileged(new PrivilegedExceptionAction<URL>() {
+ public URL run() throws IOException {
+ return FileHelper.toFile(new URL(location)).toURI().toURL();
+ }
+ });
+ } catch (PrivilegedActionException e) {
+ throw (MalformedURLException)e.getException();
+ }
+ }
+
+ } else if ("jar".equals(protocol)) {
+ // jar contribution
+ String location = url.substring(4, url.lastIndexOf("!/"));
+ // workaround for evil URL/URI from Maven
+ contributionURL = FileHelper.toFile(new URL(location)).toURI().toURL();
+
+ } else if ("wsjar".equals(protocol)) {
+ // See https://issues.apache.org/jira/browse/TUSCANY-2219
+ // wsjar contribution
+ String location = url.substring(6, url.lastIndexOf("!/"));
+ // workaround for evil url/uri from maven
+ contributionURL = FileHelper.toFile(new URL(location)).toURI().toURL();
+
+ } else if ("zip".equals(protocol)) {
+ // See https://issues.apache.org/jira/browse/TUSCANY-2598
+ // zip contribution, remove the zip prefix and pad with file:
+ String location = "file:"+url.substring(4, url.lastIndexOf("!/"));
+ contributionURL = FileHelper.toFile(new URL(location)).toURI().toURL();
+
+ } else if (protocol != null && (protocol.equals("bundle") || protocol.equals("bundleresource"))) {
+ contributionURL =
+ new URL(contributionArtifactURL.getProtocol(), contributionArtifactURL.getHost(),
+ contributionArtifactURL.getPort(), "/");
+ }
+ } catch (MalformedURLException mfe) {
+ throw new IllegalArgumentException(mfe);
+ }
+ return contributionURL;
+ }
+
+ private static URL getResource(final ClassLoader classLoader, final String compositeURI) {
+ return AccessController.doPrivileged(new PrivilegedAction<URL>() {
+ public URL run() {
+ return classLoader.getResource(compositeURI);
+ }
+ });
+ }
+
+ /**
+ * Constructs a new SCA node.
+ *
+ * @param compositeURI
+ * @param contributions
+ */
+ NodeImpl(String compositeURI, SCAContribution[] contributions) {
+ configurationName = compositeURI;
+ logger.log(Level.INFO, "Creating node: " + configurationName);
+
+ try {
+ // Initialize the runtime
+ initRuntime();
+
+ URI uri = compositeURI == null ? null : URI.create(compositeURI);
+ ConfiguredNodeImplementation configuration = null;
+ if (contributions == null || contributions.length == 0) {
+ if (uri != null && uri.getScheme() != null) {
+ throw new IllegalArgumentException("No SCA contributions are provided");
+ }
+ configuration = findNodeConfiguration(compositeURI, null);
+ } else {
+
+ // Create a node configuration
+ NodeImplementationFactory nodeImplementationFactory =
+ modelFactories.getFactory(NodeImplementationFactory.class);
+ configuration = nodeImplementationFactory.createConfiguredNodeImplementation();
+
+ Composite composite = compositeURI == null ? null : createComposite(compositeURI);
+ configuration.setComposite(composite);
+
+
+ // Create contribution models
+ ContributionFactory contributionFactory = modelFactories.getFactory(ContributionFactory.class);
+ for (SCAContribution c : contributions) {
+ Contribution contribution = createContribution(contributionFactory, c);
+ configuration.getContributions().add(contribution);
+ }
+ }
+
+ // Configure the node
+ configureNode(configuration);
+
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ private Composite createComposite(String compositeURI) {
+ // Create composite model
+ AssemblyFactory assemblyFactory = modelFactories.getFactory(AssemblyFactory.class);
+ Composite composite = assemblyFactory.createComposite();
+ composite.setURI(compositeURI);
+ composite.setUnresolved(true);
+ return composite;
+ }
+
+ /**
+ * Constructs a new SCA node.
+ *
+ * @param compositeURI
+ * @param compositeContent
+ * @param contributions
+ */
+ NodeImpl(String compositeURI, String compositeContent, SCAContribution[] contributions) {
+ configurationName = compositeURI;
+ logger.log(Level.INFO, "Creating node: " + configurationName);
+
+ try {
+ // Initialize the runtime
+ initRuntime();
+
+ ConfiguredNodeImplementation configuration = null;
+ if (contributions == null || contributions.length == 0) {
+ configuration = findNodeConfiguration(compositeURI, null);
+ } else {
+ // Create a node configuration
+ NodeImplementationFactory nodeImplementationFactory =
+ modelFactories.getFactory(NodeImplementationFactory.class);
+ configuration = nodeImplementationFactory.createConfiguredNodeImplementation();
+
+ // Read the composite model
+ StAXArtifactProcessor<Composite> compositeProcessor = artifactProcessors.getProcessor(Composite.class);
+ // URL compositeURL = new URL(compositeURI);
+ logger.log(Level.INFO, "Loading composite: " + compositeURI);
+
+ CompositeDocumentProcessor compositeDocProcessor =
+ (CompositeDocumentProcessor)documentProcessors.getProcessor(Composite.class);
+ composite =
+ compositeDocProcessor.read(URI.create(compositeURI), new ByteArrayInputStream(compositeContent
+ .getBytes("UTF-8")));
+
+ analyzeProblems();
+
+ configuration.setComposite(composite);
+
+ // Create contribution models
+ ContributionFactory contributionFactory = modelFactories.getFactory(ContributionFactory.class);
+ for (SCAContribution c : contributions) {
+ Contribution contribution = createContribution(contributionFactory, c);
+ configuration.getContributions().add(contribution);
+ }
+ }
+
+ // Configure the node
+ configureNode(configuration);
+
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ private static Contribution createContribution(ContributionFactory contributionFactory, SCAContribution c) {
+ Contribution contribution = contributionFactory.createContribution();
+ contribution.setURI(c.getURI());
+ contribution.setLocation(c.getLocation());
+ contribution.setUnresolved(true);
+ return contribution;
+ }
+
+ /**
+ * Initialize the Tuscany runtime.
+ *
+ * @throws Exception
+ */
+ private void initRuntime() throws Exception {
+
+ // Create a node runtime
+ runtime = new RuntimeBootStrapper(Thread.currentThread().getContextClassLoader());
+ runtime.start();
+
+ // Get the various factories we need
+ ExtensionPointRegistry registry = runtime.getExtensionPointRegistry();
+ modelFactories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ inputFactory = modelFactories.getFactory(XMLInputFactory.class);
+
+ // Create the required artifact processors
+ artifactProcessors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+
+ documentProcessors = registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+
+ // Save the composite activator
+ compositeActivator = runtime.getCompositeActivator();
+
+ // save the monitor
+ UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
+ MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
+ monitor = monitorFactory.createMonitor();
+ }
+
+ /**
+ * Escape the space in URL string
+ * @param uri
+ * @return
+ */
+ private static URI createURI(String uri) {
+ if (uri.indexOf(' ') != -1) {
+ uri = uri.replace(" ", "%20");
+ }
+ return URI.create(uri);
+ }
+
+ private void configureNode(ConfiguredNodeImplementation configuration) throws Exception {
+
+ // Find if any contribution JARs already available locally on the classpath
+ Map<String, URL> localContributions = localContributions();
+
+ // Load the specified contributions
+ ContributionService contributionService = runtime.getContributionService();
+ contributions = new ArrayList<Contribution>();
+ for (Contribution contribution : configuration.getContributions()) {
+ URI uri = createURI(contribution.getLocation());
+ if (uri.getScheme() == null) {
+ uri = new File(contribution.getLocation()).toURI();
+ }
+ URL contributionURL = uri.toURL();
+
+ // Extract contribution file name
+ String file = contributionURL.getPath();
+ int i = file.lastIndexOf('/');
+ if (i != -1 && i < file.length() - 1) {
+ file = file.substring(i + 1);
+
+ // If we find the local contribution file on the classpath, use it in
+ // place of the original contribution URL
+ URL localContributionURL = localContributions.get(file);
+ if (localContributionURL != null) {
+ contributionURL = localContributionURL;
+ }
+ }
+
+ // Load the contribution
+ logger.log(Level.INFO, "Loading contribution: " + contributionURL);
+ contributions.add(contributionService.contribute(contribution.getURI(), contributionURL, false));
+ analyzeProblems();
+ }
+
+ composite = configuration.getComposite();
+
+ // FIXME: This is a hack to get a list of deployable composites. By design, the deployment composite should
+ // has been configured
+ if (composite == null) {
+ List<Composite> deployables = new ArrayList<Composite>();
+ for (Contribution c : contributions) {
+ deployables.addAll(c.getDeployables());
+ }
+ aggregate(deployables);
+ configuration.setComposite(composite);
+ }
+
+ Contribution contribution = null;
+ if (composite.getName() == null) {
+ // Load the specified composite
+ URL compositeURL;
+
+ URI uri = createURI(configuration.getComposite().getURI());
+ if (uri.getScheme() == null) {
+
+ // If the composite URI is a relative URI, try to resolve it within the contributions
+ contribution = contribution(contributions, uri.toString());
+ if (contribution == null) {
+ throw new IllegalArgumentException("Composite is not found in contributions: " + uri);
+ }
+ compositeURL = new URL(location(contribution, uri.toString()));
+
+ } else {
+
+ // If the composite URI is an absolute URI, use it as is
+ compositeURL = uri.toURL();
+ }
+
+ URLArtifactProcessor<Composite> compositeDocProcessor = documentProcessors.getProcessor(Composite.class);
+ // Read the composite
+ logger.log(Level.INFO, "Loading composite: " + compositeURL);
+ // InputStream is = compositeURL.openStream();
+ // XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
+ composite = compositeDocProcessor.read(null, uri, compositeURL);
+ // reader.close();
+
+ analyzeProblems();
+
+ }
+ // And resolve the composite within the scope of the last contribution
+ if (contribution == null && contributions.size() != 0) {
+ contribution = contributions.get(contributions.size() - 1);
+ }
+
+ // Resolve the given composite within the scope of the selected contribution
+ if (contribution != null) {
+ StAXArtifactProcessor<Composite> compositeProcessor = artifactProcessors.getProcessor(Composite.class);
+ compositeProcessor.resolve(composite, contribution.getModelResolver());
+ analyzeProblems();
+ }
+ // Create a top level composite to host our composite
+ // This is temporary to make the activator happy
+ AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
+ Composite tempComposite = assemblyFactory.createComposite();
+ tempComposite.setName(new QName("http://tempuri.org", "temp"));
+ tempComposite.setURI("http://tempuri.org");
+
+ // Include the node composite in the top-level composite
+ tempComposite.getIncludes().add(composite);
+
+ // set the top level composite on the composite activator as
+ // logic in callable reference resolution relies on this being
+ // available
+ compositeActivator.setDomainComposite(tempComposite);
+
+ // Build the composite
+ runtime.buildComposite(composite);
+
+ analyzeProblems();
+ }
+
+ /**
+ * Create a deployment composite that includes a list of deployable composites
+ * @param composites
+ */
+ private void aggregate(List<Composite> composites) {
+ if (composites.size() == 0) {
+ throw new IllegalArgumentException("No deployable composite is declared");
+ } else if (composites.size() == 1) {
+ composite = composites.get(0);
+ } else {
+ // Include all composites
+ AssemblyFactory assemblyFactory = runtime.getAssemblyFactory();
+ Composite aggregated = assemblyFactory.createComposite();
+ aggregated.setName(new QName("http://tempuri.org", "aggregated"));
+ aggregated.setURI("http://tempuri.org/aggregated");
+ aggregated.getIncludes().addAll(composites);
+ composite = aggregated;
+ }
+ }
+
+ /**
+ * Returns the artifact representing the given composite.
+ *
+ * @param contribution
+ * @param compositeURI
+ * @return
+ */
+ private String location(Contribution contribution, String uri) {
+ if (uri != null && uri.startsWith("/")) {
+ uri = uri.substring(1);
+ }
+ ContributionFactory contributionFactory = modelFactories.getFactory(ContributionFactory.class);
+ Artifact compositeFile = contributionFactory.createArtifact();
+ compositeFile.setUnresolved(true);
+ compositeFile.setURI(uri);
+ ModelResolver resolver = contribution.getModelResolver();
+ Artifact resolved = resolver.resolveModel(Artifact.class, compositeFile);
+ if (resolved != null && !resolved.isUnresolved()) {
+ return resolved.getLocation();
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Returns the contribution containing the given composite.
+ *
+ * @param contributions
+ * @param compositeURI
+ * @return
+ */
+ private Contribution contribution(List<Contribution> contributions, String compositeURI) {
+ if (compositeURI != null && compositeURI.startsWith("/")) {
+ compositeURI = compositeURI.substring(1);
+ }
+ ContributionFactory contributionFactory = modelFactories.getFactory(ContributionFactory.class);
+ Artifact compositeFile = contributionFactory.createArtifact();
+ compositeFile.setUnresolved(true);
+ compositeFile.setURI(compositeURI);
+ for (Contribution c : contributions) {
+ ModelResolver resolver = c.getModelResolver();
+ Artifact resolved = resolver.resolveModel(Artifact.class, compositeFile);
+ if (resolved != null && !resolved.isUnresolved()) {
+ return c;
+ }
+ }
+ return null;
+ }
+
+ private void analyzeProblems() throws Exception {
+
+ for (Problem problem : monitor.getProblems()) {
+ if ((problem.getSeverity() == Severity.ERROR) && (!problem.getMessageId().equals("SchemaError"))) {
+ if (problem.getCause() != null) {
+ throw problem.getCause();
+ } else {
+ throw new ServiceRuntimeException(problem.toString());
+ }
+ }
+ }
+ }
+
+ public void start() {
+ logger.log(Level.INFO, "Starting node: " + configurationName);
+
+ try {
+
+ // Activate the composite
+ compositeActivator.activate(composite);
+
+ // Start the composite
+ compositeActivator.start(composite);
+
+ } catch (ActivationException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ public void stop() {
+ logger.log(Level.INFO, "Stopping node: " + configurationName);
+
+ try {
+
+ // Stop the composite
+ compositeActivator.stop(composite);
+
+ // Deactivate the composite
+ compositeActivator.deactivate(composite);
+
+ runtime.stop();
+ } catch (ActivationException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ public <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException {
+ return (R)runtime.getProxyFactory().cast(target);
+ }
+
+ public <B> B getService(Class<B> businessInterface, String serviceName) {
+
+ ServiceReference<B> serviceReference = getServiceReference(businessInterface, serviceName);
+ if (serviceReference == null) {
+ throw new ServiceRuntimeException("Service not found: " + serviceName);
+ }
+ return serviceReference.getService();
+ }
+
+ public <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String name) {
+
+ // Extract the component name
+ String componentName;
+ String serviceName;
+ int i = name.indexOf('/');
+ if (i != -1) {
+ componentName = name.substring(0, i);
+ serviceName = name.substring(i + 1);
+
+ } else {
+ componentName = name;
+ serviceName = null;
+ }
+
+ // Lookup the component
+ Component component = null;
+
+ for (Component compositeComponent : composite.getComponents()) {
+ if (compositeComponent.getName().equals(componentName)) {
+ component = compositeComponent;
+ }
+ }
+
+ if (component == null) {
+ throw new ServiceRuntimeException("The service " + name + " has not been contributed to the domain");
+ }
+ RuntimeComponentContext componentContext = null;
+
+ // If the component is a composite, then we need to find the
+ // non-composite component that provides the requested service
+ if (component.getImplementation() instanceof Composite) {
+ for (ComponentService componentService : component.getServices()) {
+ if (serviceName == null || serviceName.equals(componentService.getName())) {
+ CompositeService compositeService = (CompositeService)componentService.getService();
+ if (compositeService != null) {
+ if (serviceName != null) {
+ serviceName = "$promoted$" + component.getName() + "$slash$" + serviceName;
+ }
+ componentContext =
+ ((RuntimeComponent)compositeService.getPromotedComponent()).getComponentContext();
+ return componentContext.createSelfReference(businessInterface, compositeService
+ .getPromotedService());
+ }
+ break;
+ }
+ }
+ // No matching service found
+ throw new ServiceRuntimeException("Composite service not found: " + name);
+ } else {
+ componentContext = ((RuntimeComponent)component).getComponentContext();
+ if (serviceName != null) {
+ return componentContext.createSelfReference(businessInterface, serviceName);
+ } else {
+ return componentContext.createSelfReference(businessInterface);
+ }
+ }
+ }
+
+ /**
+ * Returns the extension point registry used by this node.
+ *
+ * @return
+ */
+ public ExtensionPointRegistry getExtensionPointRegistry() {
+ return runtime.getExtensionPointRegistry();
+ }
+
+ /**
+ * Returns the composite being run by this node.
+ *
+ * @return
+ */
+ public Composite getComposite() {
+ return composite;
+ }
+
+ /**
+ * Returns contribution JARs available on the classpath.
+ *
+ * @return
+ */
+ private static Map<String, URL> localContributions() {
+ Map<String, URL> localContributions = new HashMap<String, URL>();
+ collectJARs(localContributions, Thread.currentThread().getContextClassLoader());
+ return localContributions;
+ }
+
+ /**
+ * Collect JARs on the classpath of a URLClassLoader
+ * @param urls
+ * @param cl
+ */
+ private static void collectJARs(Map<String, URL> urls, ClassLoader cl) {
+ if (cl == null) {
+ return;
+ }
+
+ // Collect JARs from the URLClassLoader's classpath
+ if (cl instanceof URLClassLoader) {
+ URL[] jarURLs = ((URLClassLoader)cl).getURLs();
+ if (jarURLs != null) {
+ for (URL jarURL : jarURLs) {
+ String file = jarURL.getPath();
+ int i = file.lastIndexOf('/');
+ if (i != -1 && i < file.length() - 1) {
+ file = file.substring(i + 1);
+ urls.put(file, jarURL);
+ }
+ }
+ }
+ }
+
+ // Collect JARs from the parent ClassLoader
+ collectJARs(urls, cl.getParent());
+ }
+
+ public CompositeActivator getCompositeActivator() {
+ return compositeActivator;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java b/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java
new file mode 100644
index 0000000000..5b0e31fd03
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java
@@ -0,0 +1,392 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.node.impl;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.TransformerFactory;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.EndpointFactory;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilderException;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionService;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.ModuleActivator;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.core.assembly.ActivationException;
+import org.apache.tuscany.sca.core.assembly.CompositeActivator;
+import org.apache.tuscany.sca.core.assembly.RuntimeAssemblyFactory;
+import org.apache.tuscany.sca.core.invocation.ExtensibleProxyFactory;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.core.invocation.ProxyFactoryExtensionPoint;
+import org.apache.tuscany.sca.core.scope.ScopeRegistry;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.definitions.impl.SCADefinitionsImpl;
+import org.apache.tuscany.sca.definitions.util.SCADefinitionsUtil;
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl;
+import org.apache.tuscany.sca.policy.DefaultIntentAttachPointTypeFactory;
+import org.apache.tuscany.sca.policy.DefaultPolicyFactory;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.provider.SCADefinitionsProvider;
+import org.apache.tuscany.sca.provider.SCADefinitionsProviderExtensionPoint;
+import org.apache.tuscany.sca.work.WorkScheduler;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class RuntimeBootStrapper {
+ private static final Logger logger = Logger.getLogger(RuntimeBootStrapper.class.getName());
+ private List<ModuleActivator> modules;
+ private ExtensionPointRegistry registry;
+
+ private ClassLoader classLoader;
+ private AssemblyFactory assemblyFactory;
+ private ContributionService contributionService;
+ private CompositeActivator compositeActivator;
+ private CompositeBuilder compositeBuilder;
+ // private DomainBuilder domainBuilder;
+ private WorkScheduler workScheduler;
+ private ScopeRegistry scopeRegistry;
+ private ProxyFactory proxyFactory;
+ private List<SCADefinitions> policyDefinitions;
+ private ModelResolver policyDefinitionsResolver;
+ private Monitor monitor;
+
+ public RuntimeBootStrapper(ClassLoader classLoader) {
+ this.classLoader = classLoader;
+ }
+
+ public void start() throws ActivationException {
+ long start = System.currentTimeMillis();
+
+ // Create our extension point registry
+ registry = new DefaultExtensionPointRegistry();
+ UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
+
+ // Get work scheduler
+ workScheduler = utilities.getUtility(WorkScheduler.class);
+
+ // Create an interface contract mapper
+ InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class);
+
+ // Get factory extension point
+ ModelFactoryExtensionPoint factories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class);
+
+ // Get Message factory
+ MessageFactory messageFactory = factories.getFactory(MessageFactory.class);
+
+ // Get proxy factory
+ ProxyFactoryExtensionPoint proxyFactories = registry.getExtensionPoint(ProxyFactoryExtensionPoint.class);
+ proxyFactory = new ExtensibleProxyFactory(proxyFactories);
+
+ // Create model factories
+ assemblyFactory = new RuntimeAssemblyFactory();
+ factories.addFactory(assemblyFactory);
+ PolicyFactory policyFactory = new DefaultPolicyFactory();
+ factories.addFactory(policyFactory);
+
+ // Load the runtime modules
+ modules = loadModules(registry);
+
+ // Start the runtime modules
+ startModules(registry, modules);
+
+ SCABindingFactory scaBindingFactory = factories.getFactory(SCABindingFactory.class);
+ IntentAttachPointTypeFactory intentAttachPointTypeFactory = new DefaultIntentAttachPointTypeFactory();
+ factories.addFactory(intentAttachPointTypeFactory);
+ ContributionFactory contributionFactory = factories.getFactory(ContributionFactory.class);
+
+ // Create a monitor
+ MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class);
+
+ if (monitorFactory != null) {
+ monitor = monitorFactory.createMonitor();
+ } else {
+ monitorFactory = new DefaultMonitorFactoryImpl();
+ monitor = monitorFactory.createMonitor();
+ utilities.addUtility(monitorFactory);
+ //logger.fine("No MonitorFactory is found on the classpath.");
+ }
+
+ // Create a contribution service
+ policyDefinitions = new ArrayList<SCADefinitions>();
+ policyDefinitionsResolver = new DefaultModelResolver();
+ contributionService =
+ RuntimeBuilder.createContributionService(classLoader,
+ registry,
+ contributionFactory,
+ assemblyFactory,
+ policyFactory,
+ mapper,
+ policyDefinitions,
+ policyDefinitionsResolver,
+ monitor);
+
+ // Create the ScopeRegistry
+ scopeRegistry = RuntimeBuilder.createScopeRegistry(registry);
+
+ // Create a composite activator
+ compositeActivator =
+ RuntimeBuilder.createCompositeActivator(registry,
+ assemblyFactory,
+ messageFactory,
+ scaBindingFactory,
+ mapper,
+ proxyFactory,
+ scopeRegistry,
+ workScheduler);
+
+ // Load the definitions.xml
+ loadSCADefinitions();
+
+ if (logger.isLoggable(Level.FINE)) {
+ long end = System.currentTimeMillis();
+ logger.fine("The tuscany runtime is started in " + (end - start) + " ms.");
+ }
+ }
+
+ public void stop() throws ActivationException {
+ long start = System.currentTimeMillis();
+
+ // Stop the runtime modules
+ stopModules(registry, modules);
+
+ // Stop and destroy the work manager
+ workScheduler.destroy();
+
+ // Cleanup
+ modules = null;
+ registry = null;
+ assemblyFactory = null;
+ contributionService = null;
+ compositeActivator = null;
+ workScheduler = null;
+ scopeRegistry = null;
+
+ if (logger.isLoggable(Level.FINE)) {
+ long end = System.currentTimeMillis();
+ logger.fine("The tuscany runtime is stopped in " + (end - start) + " ms.");
+ }
+ }
+
+ public void buildComposite(Composite composite) throws CompositeBuilderException {
+ //Get factory extension point
+ ModelFactoryExtensionPoint factories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class);
+ SCABindingFactory scaBindingFactory = factories.getFactory(SCABindingFactory.class);
+ IntentAttachPointTypeFactory intentAttachPointTypeFactory =
+ factories.getFactory(IntentAttachPointTypeFactory.class);
+ EndpointFactory endpointFactory = factories.getFactory(EndpointFactory.class);
+ DocumentBuilderFactory documentBuilderFactory = factories.getFactory(DocumentBuilderFactory.class);
+ TransformerFactory transformerFactory = factories.getFactory(TransformerFactory.class);
+ UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
+ InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class);
+
+ //Create a composite builder
+ SCADefinitions aggregatedDefinitions = new SCADefinitionsImpl();
+ for (SCADefinitions definition : ((List<SCADefinitions>)policyDefinitions)) {
+ SCADefinitionsUtil.aggregateSCADefinitions(definition, aggregatedDefinitions);
+ }
+ compositeBuilder =
+ RuntimeBuilder.createCompositeBuilder(monitor,
+ assemblyFactory,
+ scaBindingFactory,
+ endpointFactory,
+ intentAttachPointTypeFactory,
+ documentBuilderFactory,
+ transformerFactory,
+ mapper,
+ aggregatedDefinitions);
+ compositeBuilder.build(composite);
+
+ }
+
+ public ContributionService getContributionService() {
+ return contributionService;
+ }
+
+ public CompositeActivator getCompositeActivator() {
+ return compositeActivator;
+ }
+
+ public CompositeBuilder getCompositeBuilder() {
+ return compositeBuilder;
+ }
+
+ public AssemblyFactory getAssemblyFactory() {
+ return assemblyFactory;
+ }
+
+ private void loadSCADefinitions() throws ActivationException {
+ try {
+ URLArtifactProcessorExtensionPoint documentProcessors =
+ registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+ URLArtifactProcessor<SCADefinitions> definitionsProcessor =
+ documentProcessors.getProcessor(SCADefinitions.class);
+ SCADefinitionsProviderExtensionPoint scaDefnProviders =
+ registry.getExtensionPoint(SCADefinitionsProviderExtensionPoint.class);
+
+ SCADefinitions systemSCADefinitions = new SCADefinitionsImpl();
+ SCADefinitions aSCADefn = null;
+ for (SCADefinitionsProvider aProvider : scaDefnProviders.getSCADefinitionsProviders()) {
+ aSCADefn = aProvider.getSCADefinition();
+ SCADefinitionsUtil.aggregateSCADefinitions(aSCADefn, systemSCADefinitions);
+ }
+
+ policyDefinitions.add(systemSCADefinitions);
+
+ //we cannot expect that providers will add the intents and policysets into the resolver
+ //so we do this here explicitly
+ for (Intent intent : systemSCADefinitions.getPolicyIntents()) {
+ policyDefinitionsResolver.addModel(intent);
+ }
+
+ for (PolicySet policySet : systemSCADefinitions.getPolicySets()) {
+ policyDefinitionsResolver.addModel(policySet);
+ }
+
+ for (IntentAttachPointType attachPoinType : systemSCADefinitions.getBindingTypes()) {
+ policyDefinitionsResolver.addModel(attachPoinType);
+ }
+
+ for (IntentAttachPointType attachPoinType : systemSCADefinitions.getImplementationTypes()) {
+ policyDefinitionsResolver.addModel(attachPoinType);
+ }
+
+ //now that all system sca definitions have been read, lets resolve them right away
+ definitionsProcessor.resolve(systemSCADefinitions, policyDefinitionsResolver);
+ } catch (Exception e) {
+ throw new ActivationException(e);
+ }
+ }
+
+ private List<ModuleActivator> loadModules(ExtensionPointRegistry registry) throws ActivationException {
+
+ // Load and instantiate the modules found on the classpath (or any registered ClassLoaders)
+ modules = new ArrayList<ModuleActivator>();
+ try {
+ Set<ServiceDeclaration> moduleActivators =
+ ServiceDiscovery.getInstance().getServiceDeclarations(ModuleActivator.class);
+ Set<String> moduleClasses = new HashSet<String>();
+ for (ServiceDeclaration moduleDeclarator : moduleActivators) {
+ if (moduleClasses.contains(moduleDeclarator.getClassName())) {
+ continue;
+ }
+ moduleClasses.add(moduleDeclarator.getClassName());
+ Class<?> moduleClass = moduleDeclarator.loadClass();
+ ModuleActivator module = (ModuleActivator)moduleClass.newInstance();
+ modules.add(module);
+ }
+ } catch (IOException e) {
+ throw new ActivationException(e);
+ } catch (ClassNotFoundException e) {
+ throw new ActivationException(e);
+ } catch (InstantiationException e) {
+ throw new ActivationException(e);
+ } catch (IllegalAccessException e) {
+ throw new ActivationException(e);
+ }
+
+ return modules;
+ }
+
+ private void startModules(ExtensionPointRegistry registry, List<ModuleActivator> modules)
+ throws ActivationException {
+ boolean debug = logger.isLoggable(Level.FINE);
+ // Start all the extension modules
+ for (ModuleActivator module : modules) {
+ long start = 0L;
+ if (debug) {
+ logger.fine(module.getClass().getName() + " is starting.");
+ start = System.currentTimeMillis();
+ }
+ try {
+ module.start(registry);
+ if (debug) {
+ long end = System.currentTimeMillis();
+ logger.fine(module.getClass().getName() + " is started in " + (end - start) + " ms.");
+ }
+ } catch (Throwable e) {
+ logger.log(Level.WARNING, "Exception starting module " + module.getClass().getName()
+ + " :"
+ + e.getMessage());
+ logger.log(Level.FINE, "Exception starting module " + module.getClass().getName(), e);
+ }
+ }
+ }
+
+ private void stopModules(final ExtensionPointRegistry registry, List<ModuleActivator> modules) {
+ boolean debug = logger.isLoggable(Level.FINE);
+ for (ModuleActivator module : modules) {
+ long start = 0L;
+ if (debug) {
+ logger.fine(module.getClass().getName() + " is stopping.");
+ start = System.currentTimeMillis();
+ }
+ module.stop(registry);
+ if (debug) {
+ long end = System.currentTimeMillis();
+ logger.fine(module.getClass().getName() + " is stopped in " + (end - start) + " ms.");
+ }
+ }
+ }
+
+ /**
+ * @return the proxyFactory
+ */
+ public ProxyFactory getProxyFactory() {
+ return proxyFactory;
+ }
+
+ /**
+ * @return the registry
+ */
+ public ExtensionPointRegistry getExtensionPointRegistry() {
+ return registry;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBuilder.java b/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBuilder.java
new file mode 100644
index 0000000000..6c93fa7800
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBuilder.java
@@ -0,0 +1,258 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.node.impl;
+
+import java.io.IOException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.List;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.transform.TransformerFactory;
+
+import org.apache.tuscany.sca.assembly.AssemblyFactory;
+import org.apache.tuscany.sca.assembly.Composite;
+import org.apache.tuscany.sca.assembly.EndpointFactory;
+import org.apache.tuscany.sca.assembly.SCABindingFactory;
+import org.apache.tuscany.sca.assembly.builder.CompositeBuilder;
+import org.apache.tuscany.sca.assembly.builder.impl.CompositeBuilderImpl;
+import org.apache.tuscany.sca.assembly.xml.CompositeDocumentProcessor;
+import org.apache.tuscany.sca.context.ContextFactoryExtensionPoint;
+import org.apache.tuscany.sca.context.RequestContextFactory;
+import org.apache.tuscany.sca.contribution.ContributionFactory;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.DefaultValidatingXMLInputFactory;
+import org.apache.tuscany.sca.contribution.processor.DefaultValidationSchemaExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ExtensiblePackageProcessor;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.ExtensibleURLArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.PackageProcessor;
+import org.apache.tuscany.sca.contribution.processor.PackageProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolverExtensionPoint;
+import org.apache.tuscany.sca.contribution.service.ContributionListenerExtensionPoint;
+import org.apache.tuscany.sca.contribution.service.ContributionRepository;
+import org.apache.tuscany.sca.contribution.service.ContributionService;
+import org.apache.tuscany.sca.contribution.service.ExtensibleContributionListener;
+import org.apache.tuscany.sca.contribution.service.TypeDescriber;
+import org.apache.tuscany.sca.contribution.service.impl.ContributionRepositoryImpl;
+import org.apache.tuscany.sca.contribution.service.impl.ContributionServiceImpl;
+import org.apache.tuscany.sca.contribution.service.impl.PackageTypeDescriberImpl;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.core.assembly.ActivationException;
+import org.apache.tuscany.sca.core.assembly.CompositeActivator;
+import org.apache.tuscany.sca.core.assembly.CompositeActivatorImpl;
+import org.apache.tuscany.sca.core.conversation.ConversationManager;
+import org.apache.tuscany.sca.core.invocation.ExtensibleWireProcessor;
+import org.apache.tuscany.sca.core.invocation.ProxyFactory;
+import org.apache.tuscany.sca.core.scope.CompositeScopeContainerFactory;
+import org.apache.tuscany.sca.core.scope.ConversationalScopeContainerFactory;
+import org.apache.tuscany.sca.core.scope.RequestScopeContainerFactory;
+import org.apache.tuscany.sca.core.scope.ScopeContainerFactory;
+import org.apache.tuscany.sca.core.scope.ScopeRegistry;
+import org.apache.tuscany.sca.core.scope.ScopeRegistryImpl;
+import org.apache.tuscany.sca.core.scope.StatelessScopeContainerFactory;
+import org.apache.tuscany.sca.definitions.SCADefinitions;
+import org.apache.tuscany.sca.endpointresolver.EndpointResolverFactoryExtensionPoint;
+import org.apache.tuscany.sca.interfacedef.InterfaceContractMapper;
+import org.apache.tuscany.sca.interfacedef.java.JavaInterfaceFactory;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
+import org.apache.tuscany.sca.runtime.RuntimeWireProcessor;
+import org.apache.tuscany.sca.runtime.RuntimeWireProcessorExtensionPoint;
+import org.apache.tuscany.sca.work.WorkScheduler;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class RuntimeBuilder {
+
+ // private static final Logger logger = Logger.getLogger(RuntimeBuilder.class.getName());
+
+ public static CompositeActivator createCompositeActivator(ExtensionPointRegistry registry,
+ AssemblyFactory assemblyFactory,
+ MessageFactory messageFactory,
+ SCABindingFactory scaBindingFactory,
+ InterfaceContractMapper mapper,
+ ProxyFactory proxyFactory,
+ ScopeRegistry scopeRegistry,
+ WorkScheduler workScheduler) {
+
+ // Create a wire post processor extension point
+ RuntimeWireProcessorExtensionPoint wireProcessors =
+ registry.getExtensionPoint(RuntimeWireProcessorExtensionPoint.class);
+ RuntimeWireProcessor wireProcessor = new ExtensibleWireProcessor(wireProcessors);
+
+ // Retrieve the processors extension point
+ StAXArtifactProcessorExtensionPoint processors =
+ registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+
+ // Create a provider factory extension point
+ ProviderFactoryExtensionPoint providerFactories =
+ registry.getExtensionPoint(ProviderFactoryExtensionPoint.class);
+
+ // Create a endpoint resolver factory extension point
+ EndpointResolverFactoryExtensionPoint endpointResolverFactories =
+ registry.getExtensionPoint(EndpointResolverFactoryExtensionPoint.class);
+
+ JavaInterfaceFactory javaInterfaceFactory =
+ registry.getExtensionPoint(ModelFactoryExtensionPoint.class).getFactory(JavaInterfaceFactory.class);
+ RequestContextFactory requestContextFactory =
+ registry.getExtensionPoint(ContextFactoryExtensionPoint.class).getFactory(RequestContextFactory.class);
+
+ UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class);
+ ConversationManager conversationManager = utilities.getUtility(ConversationManager.class);
+
+ // Create the composite activator
+ CompositeActivator compositeActivator =
+ new CompositeActivatorImpl(assemblyFactory, messageFactory, javaInterfaceFactory, scaBindingFactory,
+ mapper, scopeRegistry, workScheduler, wireProcessor, requestContextFactory,
+ proxyFactory, providerFactories, endpointResolverFactories, processors,
+ conversationManager);
+
+ return compositeActivator;
+ }
+
+ public static CompositeBuilder createCompositeBuilder(Monitor monitor,
+ AssemblyFactory assemblyFactory,
+ SCABindingFactory scaBindingFactory,
+ EndpointFactory endpointFactory,
+ IntentAttachPointTypeFactory intentAttachPointTypeFactory,
+ DocumentBuilderFactory documentBuilderFactory,
+ TransformerFactory transformerFactory,
+ InterfaceContractMapper interfaceContractMapper,
+ SCADefinitions policyDefinitions) {
+
+ return new CompositeBuilderImpl(assemblyFactory, endpointFactory, scaBindingFactory,
+ intentAttachPointTypeFactory, documentBuilderFactory, transformerFactory,
+ interfaceContractMapper, policyDefinitions,
+ monitor);
+ }
+
+ /**
+ * Create the contribution service used by this domain.
+ *
+ * @throws ActivationException
+ */
+ public static ContributionService createContributionService(ClassLoader classLoader,
+ ExtensionPointRegistry registry,
+ ContributionFactory contributionFactory,
+ AssemblyFactory assemblyFactory,
+ PolicyFactory policyFactory,
+ InterfaceContractMapper mapper,
+ List<SCADefinitions> policyDefinitions,
+ ModelResolver policyDefinitionResolver,
+ Monitor monitor) throws ActivationException {
+
+ // Get the model factory extension point
+ ModelFactoryExtensionPoint modelFactories = registry.getExtensionPoint(ModelFactoryExtensionPoint.class);
+
+ // Create a new XML input factory
+ XMLInputFactory inputFactory = modelFactories.getFactory(XMLInputFactory.class);
+
+ // Create a validation XML schema extension point
+ ValidationSchemaExtensionPoint schemas = new DefaultValidationSchemaExtensionPoint();
+
+ // Create a validating XML input factory
+ XMLInputFactory validatingInputFactory = new DefaultValidatingXMLInputFactory(inputFactory, schemas, monitor);
+ modelFactories.addFactory(validatingInputFactory);
+
+ // Create StAX artifact processor extension point
+ StAXArtifactProcessorExtensionPoint staxProcessors =
+ registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+
+ // Create and register StAX processors for SCA assembly XML
+ // Allow privileged access to factory. Requires RuntimePermission in security policy file.
+ XMLOutputFactory outputFactory = modelFactories.getFactory(XMLOutputFactory.class);
+ ExtensibleStAXArtifactProcessor staxProcessor =
+ new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, monitor);
+
+ // Create URL artifact processor extension point
+ URLArtifactProcessorExtensionPoint documentProcessors =
+ registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class);
+
+ // Create and register document processors for SCA assembly XML
+ DocumentBuilderFactory documentBuilderFactory = modelFactories.getFactory(DocumentBuilderFactory.class);
+ documentBuilderFactory.setNamespaceAware(true);
+ documentProcessors.getProcessor(Composite.class);
+ documentProcessors.addArtifactProcessor(new CompositeDocumentProcessor(staxProcessor, validatingInputFactory,
+ documentBuilderFactory, policyDefinitions, monitor));
+
+ // Create Model Resolver extension point
+ ModelResolverExtensionPoint modelResolvers = registry.getExtensionPoint(ModelResolverExtensionPoint.class);
+
+ // Create contribution package processor extension point
+ TypeDescriber describer = new PackageTypeDescriberImpl();
+ PackageProcessor packageProcessor =
+ new ExtensiblePackageProcessor(registry.getExtensionPoint(PackageProcessorExtensionPoint.class), describer,
+ monitor);
+
+ // Create contribution listener
+ ExtensibleContributionListener contributionListener =
+ new ExtensibleContributionListener(registry.getExtensionPoint(ContributionListenerExtensionPoint.class));
+
+ // Create a contribution repository
+ ContributionRepository repository;
+ try {
+ repository = new ContributionRepositoryImpl("target", inputFactory, monitor);
+ } catch (IOException e) {
+ throw new ActivationException(e);
+ }
+
+ ExtensibleURLArtifactProcessor documentProcessor =
+ new ExtensibleURLArtifactProcessor(documentProcessors, monitor);
+
+ // Create the contribution service
+ ContributionService contributionService =
+ new ContributionServiceImpl(repository, packageProcessor, documentProcessor, staxProcessor,
+ contributionListener, policyDefinitionResolver, modelResolvers, modelFactories,
+ assemblyFactory, contributionFactory, inputFactory, policyDefinitions, monitor);
+ return contributionService;
+ }
+
+ public static ScopeRegistry createScopeRegistry(ExtensionPointRegistry registry) {
+ ScopeRegistry scopeRegistry = new ScopeRegistryImpl();
+ ScopeContainerFactory[] factories =
+ new ScopeContainerFactory[] {new CompositeScopeContainerFactory(), new StatelessScopeContainerFactory(),
+ new RequestScopeContainerFactory(),
+ new ConversationalScopeContainerFactory(null),
+ // new HttpSessionScopeContainer(monitor)
+ };
+ for (ScopeContainerFactory f : factories) {
+ scopeRegistry.register(f);
+ }
+
+ //FIXME Pass the scope container differently as it's not an extension point
+ registry.addExtensionPoint(scopeRegistry);
+
+ return scopeRegistry;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.SCANode2Factory b/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.SCANode2Factory
new file mode 100644
index 0000000000..4215855ac9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.SCANode2Factory
@@ -0,0 +1,17 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+org.apache.tuscany.sca.node.impl.Node2FactoryImpl \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.SCANodeFactory b/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.SCANodeFactory
new file mode 100644
index 0000000000..800bdd84cc
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.SCANodeFactory
@@ -0,0 +1,17 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+org.apache.tuscany.sca.node.impl.NodeFactoryImpl \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/node-impl/src/test/java/hello/HelloWorld.java b/sca-java-1.x/branches/sca-android/modules/node-impl/src/test/java/hello/HelloWorld.java
new file mode 100644
index 0000000000..2f519cb81d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-impl/src/test/java/hello/HelloWorld.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 hello;
+
+import org.osoa.sca.annotations.Remotable;
+
+/**
+ * HelloWorld interface
+ */
+@Remotable
+public interface HelloWorld {
+ String hello(String name);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/node-impl/src/test/java/hello/HelloWorldImpl.java b/sca-java-1.x/branches/sca-android/modules/node-impl/src/test/java/hello/HelloWorldImpl.java
new file mode 100644
index 0000000000..c9a7560b12
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-impl/src/test/java/hello/HelloWorldImpl.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 hello;
+
+/**
+ * HelloWorldImpl
+ */
+public class HelloWorldImpl implements HelloWorld {
+ public String hello(String name) {
+ System.out.println("Hello: " + name);
+ return "Hello, " + name;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/Node2ImplTestCase.java b/sca-java-1.x/branches/sca-android/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/Node2ImplTestCase.java
new file mode 100644
index 0000000000..52d96dd72d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/Node2ImplTestCase.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * \"License\"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.node.impl;
+
+import hello.HelloWorld;
+
+import java.io.File;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.node.SCAClient;
+import org.apache.tuscany.sca.node.SCAContribution;
+import org.apache.tuscany.sca.node.SCANode2;
+import org.apache.tuscany.sca.node.SCANode2Factory;
+import org.junit.Test;
+
+/**
+ * Test case for Node2Impl
+ */
+public class Node2ImplTestCase {
+ private static String composite =
+ "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\"" + " xmlns:tuscany=\"http://tuscany.apache.org/xmlns/sca/1.0\""
+ + " targetNamespace=\"http://sample/composite\""
+ + " xmlns:sc=\"http://sample/composite\""
+ + " name=\"HelloWorld\">"
+ + " <component name=\"HelloWorld\">"
+ + " <implementation.java class=\"hello.HelloWorldImpl\"/>"
+ + " </component>"
+ + " </composite>";
+
+ @Test
+ public void testNodeWithCompositeContent() {
+ SCANode2Factory factory = SCANode2Factory.newInstance();
+ SCAContribution contribution = new SCAContribution("c1", new File("target/test-classes").toURI().toString());
+ SCANode2 node = factory.createSCANode("HelloWorld.composite", composite, contribution);
+ testNode(node);
+ }
+
+ @Test
+ public void testNodeWithCompositeContentAndNoContribution() {
+ SCANode2Factory factory = SCANode2Factory.newInstance();
+ SCANode2 node = factory.createSCANode("HelloWorld.composite", composite);
+ testNode(node);
+ }
+
+ @Test
+ public void testNodeWithoutCompositeURI() {
+ SCANode2Factory factory = SCANode2Factory.newInstance();
+ SCAContribution contribution = new SCAContribution("c1", new File("target/test-classes").toURI().toString());
+ SCANode2 node = factory.createSCANode(null, contribution);
+ testNode(node);
+ }
+
+ @Test
+ public void testNodeWithCompositeURI() {
+ SCANode2Factory factory = SCANode2Factory.newInstance();
+ SCAContribution contribution = new SCAContribution("c1", new File("target/test-classes").toURI().toString());
+ String compositeURI = new File("target/test-classes/HelloWorld.composite").toURI().toString();
+ SCANode2 node = factory.createSCANode(compositeURI, contribution);
+ testNode(node);
+ }
+
+ @Test
+ public void testNodeWithRelativeCompositeURI() {
+ SCANode2Factory factory = SCANode2Factory.newInstance();
+ SCAContribution contribution = new SCAContribution("c1", new File("target/test-classes").toURI().toString());
+ String compositeURI = "HelloWorld.composite";
+ SCANode2 node = factory.createSCANode(compositeURI, contribution);
+ testNode(node);
+ }
+
+ @Test
+ public void testNodeWithRelativeCompositeURIAndNoContribution() {
+ SCANode2Factory factory = SCANode2Factory.newInstance();
+ String compositeURI = "HelloWorld.composite";
+ SCANode2 node = factory.createSCANode(compositeURI, new SCAContribution[0]);
+ testNode(node);
+ }
+
+ @Test
+ public void testNodeWithClassLoader() {
+ SCANode2Factory factory = SCANode2Factory.newInstance();
+ String compositeURI = "HelloWorld.composite";
+ SCANode2 node = factory.createSCANodeFromClassLoader(compositeURI, HelloWorld.class.getClassLoader());
+ testNode(node);
+ }
+
+ @Test
+ public void testNodeWithClassLoaderAndNullComposite() {
+ SCANode2Factory factory = SCANode2Factory.newInstance();
+ SCANode2 node = factory.createSCANodeFromClassLoader(null, HelloWorld.class.getClassLoader());
+ testNode(node);
+ }
+
+ private void testNode(SCANode2 node) {
+ node.start();
+ HelloWorld hw = ((SCAClient)node).getService(HelloWorld.class, "HelloWorld");
+ Assert.assertEquals("Hello, Node", hw.hello("Node"));
+ node.stop();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java b/sca-java-1.x/branches/sca-android/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
new file mode 100644
index 0000000000..d620f6b62a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * \"License\"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.node.impl;
+
+import hello.HelloWorld;
+
+import java.io.File;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.node.SCAClient;
+import org.apache.tuscany.sca.node.SCAContribution;
+import org.apache.tuscany.sca.node.SCANode;
+import org.apache.tuscany.sca.node.SCANodeFactory;
+import org.junit.Test;
+
+/**
+ * Test case for NodeImpl
+ */
+public class NodeImplTestCase {
+ private static String composite =
+ "<composite xmlns=\"http://www.osoa.org/xmlns/sca/1.0\"" + " xmlns:tuscany=\"http://tuscany.apache.org/xmlns/sca/1.0\""
+ + " targetNamespace=\"http://sample/composite\""
+ + " xmlns:sc=\"http://sample/composite\""
+ + " name=\"HelloWorld\">"
+ + " <component name=\"HelloWorld\">"
+ + " <implementation.java class=\"hello.HelloWorldImpl\"/>"
+ + " </component>"
+ + " </composite>";
+
+ @Test
+ public void testNodeWithCompositeContent() {
+ SCANodeFactory factory = new NodeFactoryImpl();
+ SCAContribution contribution = new SCAContribution("c1", new File("target/test-classes").toURI().toString());
+ SCANode node = factory.createSCANode("HelloWorld.composite", composite, contribution);
+ testNode(node);
+ }
+
+ @Test
+ public void testNodeWithCompositeContentAndNoContribution() {
+ SCANodeFactory factory = new NodeFactoryImpl();
+ SCANode node = factory.createSCANode("HelloWorld.composite", composite);
+ testNode(node);
+ }
+
+ @Test
+ public void testNodeWithoutCompositeURI() {
+ SCANodeFactory factory = new NodeFactoryImpl();
+ SCAContribution contribution = new SCAContribution("c1", new File("target/test-classes").toURI().toString());
+ SCANode node = factory.createSCANode(null, contribution);
+ testNode(node);
+ }
+
+ @Test
+ public void testNodeWithCompositeURI() {
+ SCANodeFactory factory = new NodeFactoryImpl();
+ SCAContribution contribution = new SCAContribution("c1", new File("target/test-classes").toURI().toString());
+ String compositeURI = new File("target/test-classes/HelloWorld.composite").toURI().toString();
+ SCANode node = factory.createSCANode(compositeURI, contribution);
+ testNode(node);
+ }
+
+ @Test
+ public void testNodeWithRelativeCompositeURI() {
+ SCANodeFactory factory = new NodeFactoryImpl();
+ SCAContribution contribution = new SCAContribution("c1", new File("target/test-classes").toURI().toString());
+ String compositeURI = "HelloWorld.composite";
+ SCANode node = factory.createSCANode(compositeURI, contribution);
+ testNode(node);
+ }
+
+ @Test
+ public void testNodeWithRelativeCompositeURIAndNoContribution() {
+ SCANodeFactory factory = new NodeFactoryImpl();
+ String compositeURI = "HelloWorld.composite";
+ SCANode node = factory.createSCANode(compositeURI, new SCAContribution[0]);
+ testNode(node);
+ }
+
+ @Test
+ public void testNodeWithClassLoader() {
+ SCANodeFactory factory = new NodeFactoryImpl();
+ String compositeURI = "HelloWorld.composite";
+ SCANode node = factory.createSCANodeFromClassLoader(compositeURI, HelloWorld.class.getClassLoader());
+ testNode(node);
+ }
+
+ @Test
+ public void testNodeWithClassLoaderAndNullComposite() {
+ SCANodeFactory factory = new NodeFactoryImpl();
+ SCANode node = factory.createSCANodeFromClassLoader(null, HelloWorld.class.getClassLoader());
+ testNode(node);
+ }
+
+ private void testNode(SCANode node) {
+ node.start();
+ HelloWorld hw = ((SCAClient)node).getService(HelloWorld.class, "HelloWorld");
+ Assert.assertEquals("Hello, Node", hw.hello("Node"));
+ node.stop();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/node-impl/src/test/resources/HelloWorld.composite b/sca-java-1.x/branches/sca-android/modules/node-impl/src/test/resources/HelloWorld.composite
new file mode 100644
index 0000000000..9e3299d691
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-impl/src/test/resources/HelloWorld.composite
@@ -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/1.0"
+ targetNamespace="http://sample/composite"
+ xmlns:sc="http://sample/composite"
+ name="HelloWorld">
+
+ <component name="HelloWorld">
+ <implementation.java class="hello.HelloWorldImpl"/>
+ </component>
+
+</composite>
diff --git a/sca-java-1.x/branches/sca-android/modules/node-impl/src/test/resources/META-INF/sca-contribution.xml b/sca-java-1.x/branches/sca-android/modules/node-impl/src/test/resources/META-INF/sca-contribution.xml
new file mode 100644
index 0000000000..1d37bcebe0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-impl/src/test/resources/META-INF/sca-contribution.xml
@@ -0,0 +1,23 @@
+<?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.
+-->
+
+<contribution xmlns="http://www.osoa.org/xmlns/sca/1.0" xmlns:sc="http://sample/composite">
+ <deployable composite="sc:HelloWorld" />
+</contribution>
diff --git a/sca-java-1.x/branches/sca-android/modules/node-launcher/LICENSE b/sca-java-1.x/branches/sca-android/modules/node-launcher/LICENSE
new file mode 100644
index 0000000000..6e529a25c4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-launcher/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/node-launcher/META-INF/README b/sca-java-1.x/branches/sca-android/modules/node-launcher/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-launcher/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/node-launcher/NOTICE b/sca-java-1.x/branches/sca-android/modules/node-launcher/NOTICE
new file mode 100644
index 0000000000..1325efd8bf
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-launcher/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/node-launcher/pom.xml b/sca-java-1.x/branches/sca-android/modules/node-launcher/pom.xml
new file mode 100644
index 0000000000..606a4f9164
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-launcher/pom.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.
+-->
+<project>
+
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+
+ <artifactId>tuscany-node-launcher</artifactId>
+ <name>Apache Tuscany SCA Node Launcher</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <version>2.4</version> <!-- to keep compatible with older servlet containers -->
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifest>
+ <mainClass>org.apache.tuscany.sca.node.launcher.NodeMain</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.node.launcher</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.node*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/Contribution.java b/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/Contribution.java
new file mode 100644
index 0000000000..4f4f861e2f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/Contribution.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.node.launcher;
+
+/**
+ * Represents an SCA contribution uri + location.
+ *
+ * @version $Rev$ $Date$
+ */
+public final class Contribution {
+ private String uri;
+ private String location;
+
+ /**
+ * Constructs a new SCA contribution.
+ *
+ * @param uri
+ * @param location
+ */
+ public Contribution(String uri, String location) {
+ this.uri = uri;
+ this.location = location;
+ }
+
+ public String getURI() {
+ return uri;
+ }
+
+ public String getLocation() {
+ return location;
+ }
+} \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/DomainManagerLauncher.java b/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/DomainManagerLauncher.java
new file mode 100644
index 0000000000..eb06ad7411
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/DomainManagerLauncher.java
@@ -0,0 +1,179 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.node.launcher;
+
+import static org.apache.tuscany.sca.node.launcher.NodeLauncherUtil.domainManager;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Simple launcher for the SCA domain manager.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DomainManagerLauncher {
+
+ static final Logger logger = Logger.getLogger(DomainManagerLauncher.class.getName());
+
+ /**
+ * Constructs a new DomainManagerLauncher.
+ */
+ private DomainManagerLauncher() {
+ }
+
+ /**
+ * Returns a new launcher instance.
+ *
+ * @return a new launcher instance
+ */
+ public static DomainManagerLauncher newInstance() {
+ return new DomainManagerLauncher();
+ }
+
+ /**
+ * Creates a new DomainManager.
+ *
+ * @return a new DomainManager
+ * @throws LauncherException
+ */
+ public <T> T createDomainManager() throws LauncherException {
+ return (T)domainManager(".");
+ }
+
+ /**
+ * Creates a new DomainManager.
+ *
+ * @param rootDirectory the domain's root configuration directory
+ *
+ * @return a new DomainManager
+ * @throws LauncherException
+ */
+ public <T> T createDomainManager(String rootDirectory) throws LauncherException {
+ return (T)domainManager(rootDirectory);
+ }
+
+ public static void main(String[] args) throws Exception {
+ logger.info("Apache Tuscany SCA Domain Manager is starting...");
+
+ // Create a launcher
+ DomainManagerLauncher launcher = newInstance();
+
+ Object domainManager = null;
+ ShutdownThread shutdown = null;
+ try {
+ while (true) {
+
+ // Start the domain manager
+ domainManager = launcher.createDomainManager();
+ try {
+ domainManager.getClass().getMethod("start").invoke(domainManager);
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "SCA Domain Manager could not be started", e);
+ throw e;
+ }
+ logger.info("SCA Domain Manager is now started.");
+
+ // Install a shutdown hook
+ shutdown = new ShutdownThread(domainManager);
+ Runtime.getRuntime().addShutdownHook(shutdown);
+
+ logger.info("Press 'q' to quit, 'r' to restart.");
+ int k = 0;
+ try {
+ while ((k != 'q') && (k != 'r')) {
+ k = System.in.read();
+ }
+ } catch (IOException e) {
+
+ // Wait forever
+ Object lock = new Object();
+ synchronized(lock) {
+ lock.wait();
+ }
+ }
+
+ // Stop the domain manager
+ if (domainManager != null) {
+ Object dm = domainManager;
+ domainManager = null;
+ stopDomainManager(dm);
+ }
+
+ // Quit
+ if (k == 'q' ) {
+ break;
+ }
+ }
+ } catch (Exception e) {
+ // Stop the domain manager
+ if (domainManager != null) {
+ try {
+ Object dm = domainManager;
+ domainManager = null;
+ stopDomainManager(dm);
+ } catch (Exception e2) {
+ }
+ }
+ throw e;
+
+ } finally {
+
+ // Remove the shutdown hook
+ if (shutdown != null) {
+ Runtime.getRuntime().removeShutdownHook(shutdown);
+ }
+ }
+ }
+
+ /**
+ * Stop the given domain manager.
+ *
+ * @param domainManager
+ * @throws Exception
+ */
+ private static void stopDomainManager(Object domainManager) throws Exception {
+ try {
+ domainManager.getClass().getMethod("stop").invoke(domainManager);
+ logger.info("SCA Domain Manager is now stopped.");
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "SCA Domain Manager could not be stopped", e);
+ throw e;
+ }
+ }
+
+ private static class ShutdownThread extends Thread {
+ private Object domainManager;
+
+ public ShutdownThread(Object domainManager) {
+ super();
+ this.domainManager = domainManager;
+ }
+
+ public void run() {
+ try {
+ stopDomainManager(domainManager);
+ } catch (Exception e) {
+ // Ignore
+ }
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/LauncherException.java b/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/LauncherException.java
new file mode 100644
index 0000000000..39e8d81139
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/LauncherException.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.node.launcher;
+
+
+/**
+ * Denotes an error launching an SCA domain manager or node.
+ *
+ * @version $Rev$ $Date$
+ */
+public class LauncherException extends Exception {
+ private static final long serialVersionUID = 4581189418849190567L;
+
+ public LauncherException() {
+ super();
+ }
+
+ /**
+ * @param message
+ * @param cause
+ */
+ public LauncherException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * @param message
+ */
+ public LauncherException(String message) {
+ super(message);
+ }
+
+ /**
+ * @param cause
+ */
+ public LauncherException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeDaemonLauncher.java b/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeDaemonLauncher.java
new file mode 100644
index 0000000000..7cfabfe265
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeDaemonLauncher.java
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.node.launcher;
+
+import static org.apache.tuscany.sca.node.launcher.NodeLauncherUtil.nodeDaemon;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A launcher for the SCA Node daemon.
+ *
+ * @version $Rev$ $Date$
+ */
+public class NodeDaemonLauncher {
+
+ static final Logger logger = Logger.getLogger(NodeDaemonLauncher.class.getName());
+
+ /**
+ * Constructs a new node daemon launcher.
+ */
+ private NodeDaemonLauncher() {
+ }
+
+ /**
+ * Returns a new launcher instance.
+ *
+ * @return a new launcher instance
+ */
+ public static NodeDaemonLauncher newInstance() {
+ return new NodeDaemonLauncher();
+ }
+
+ /**
+ * Creates a new node daemon.
+ *
+ * @param
+ * @return a new node daemon
+ * @throws LauncherException
+ */
+ public <T> T createNodeDaemon() throws LauncherException {
+ return (T)nodeDaemon();
+ }
+
+ public static void main(String[] args) throws Exception {
+ logger.info("Apache Tuscany SCA Node Daemon is starting...");
+
+ // Create a node launcher
+ NodeDaemonLauncher launcher = newInstance();
+
+ Object node = null;
+ ShutdownThread shutdown = null;
+ try {
+ while (true) {
+
+ // Start the node
+ node = launcher.createNodeDaemon();
+ try {
+ node.getClass().getMethod("start").invoke(node);
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "SCA Node Daemon could not be started", e);
+ throw e;
+ }
+ logger.info("SCA Node Daemon is now started.");
+
+ // Install a shutdown hook
+ shutdown = new ShutdownThread(node);
+ Runtime.getRuntime().addShutdownHook(shutdown);
+
+ logger.info("Press 'q' to quit, 'r' to restart.");
+ int k = 0;
+ try {
+ while ((k != 'q') && (k != 'r')) {
+ k = System.in.read();
+ }
+ } catch (IOException e) {
+
+ // Wait forever
+ Object lock = new Object();
+ synchronized(lock) {
+ lock.wait();
+ }
+ }
+
+ // Stop the node
+ if (node != null) {
+ Object n = node;
+ node = null;
+ stopNode(n);
+ }
+
+ // Quit
+ if (k == 'q' ) {
+ break;
+ }
+ }
+ } catch (Exception e) {
+ // Stop the node
+ if (node != null) {
+ try {
+ Object n = node;
+ node = null;
+ stopNode(n);
+ } catch (Exception e2) {
+ }
+ }
+ throw e;
+
+ } finally {
+
+ // Remove the shutdown hook
+ if (shutdown != null) {
+ Runtime.getRuntime().removeShutdownHook(shutdown);
+ }
+ }
+ }
+
+ /**
+ * Stop the given node.
+ *
+ * @param node
+ * @throws Exception
+ */
+ private static void stopNode(Object node) throws Exception {
+ try {
+ node.getClass().getMethod("stop").invoke(node);
+ logger.info("SCA Node Daemon is now stopped.");
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "SCA Node Daemon could not be stopped", e);
+ throw e;
+ }
+ }
+
+ private static class ShutdownThread extends Thread {
+ private Object node;
+
+ public ShutdownThread(Object node) {
+ super();
+ this.node = node;
+ }
+
+ public void run() {
+ try {
+ stopNode(node);
+ } catch (Exception e) {
+ // Ignore
+ }
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java b/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java
new file mode 100644
index 0000000000..be9bdb15c4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.node.launcher;
+
+import static org.apache.tuscany.sca.node.launcher.NodeLauncherUtil.node;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * A launcher for SCA nodes.
+ *
+ * @version $Rev$ $Date$
+ */
+public class NodeLauncher {
+
+ static final Logger logger = Logger.getLogger(NodeLauncher.class.getName());
+
+ /**
+ * Constructs a new node launcher.
+ */
+ private NodeLauncher() {
+ }
+
+ /**
+ * Returns a new launcher instance.
+ *
+ * @return a new launcher instance
+ */
+ public static NodeLauncher newInstance() {
+ return new NodeLauncher();
+ }
+
+ /**
+ * Creates a new SCA node from the configuration URL
+ *
+ * @param configurationURL the URL of the node configuration which is the ATOM feed
+ * that contains the URI of the composite and a collection of URLs for the contributions
+ *
+ * @return a new SCA node.
+ * @throws LauncherException
+ */
+ public <T> T createNodeFromURL(String configurationURL) throws LauncherException {
+ return (T)node(configurationURL, null, null, null, null);
+ }
+
+ /**
+ * Creates a new SCA Node.
+ *
+ * @param compositeURI the URI of the composite to use
+ * @param contributions the URI of the contributions that provides the composites and related
+ * artifacts. If the list is empty, then we will use the thread context classloader to discover
+ * the contribution on the classpath
+ *
+ * @return a new SCA node.
+ * @throws LauncherException
+ */
+ public <T> T createNode(String compositeURI, Contribution...contributions) throws LauncherException {
+ return (T)node(null, compositeURI, null, contributions, null);
+ }
+
+ /**
+ * Creates a new SCA Node.
+ *
+ * @param compositeURI the URI of the composite to use
+ * @param compositeContent the XML content of the composite to use
+ * @param contributions the URI of the contributions that provides the composites and related artifacts
+ * @return a new SCA node.
+ * @throws LauncherException
+ */
+ public <T> T createNode(String compositeURI, String compositeContent, Contribution...contributions) throws LauncherException {
+ return (T)node(null, compositeURI, compositeContent, contributions, null);
+ }
+
+ /**
+ * Create a SCA node based on the discovery of the contribution on the classpath for the
+ * given classloader. This method should be treated a convenient shortcut with the following
+ * assumptions:
+ * <ul>
+ * <li>This is a standalone application and there is a deployable composite file on the classpath.
+ * <li>There is only one contribution which contains the deployable composite file physically in its packaging hierarchy.
+ * </ul>
+ *
+ * @param compositeURI The URI of the composite file relative to the root of the enclosing contribution
+ * @param classLoader The ClassLoader used to load the composite file as a resource. If the value is null,
+ * then thread context classloader will be used
+ * @return A newly created SCA node
+ */
+ public <T> T createNodeFromClassLoader(String compositeURI, ClassLoader classLoader) throws LauncherException {
+ return (T)node(null, compositeURI, null, null, classLoader);
+ }
+
+ public static void main(String[] args) throws Exception {
+ logger.info("Apache Tuscany SCA Node is starting...");
+
+ // Create a node launcher
+ NodeLauncher launcher = newInstance();
+
+ Object node = null;
+ ShutdownThread shutdown = null;
+ try {
+ while (true) {
+ if (args.length ==1) {
+
+ // Create a node from a configuration URI
+ String configurationURI = args[0];
+ logger.info("SCA Node configuration: " + configurationURI);
+ node = launcher.createNodeFromURL(configurationURI);
+ } else {
+
+ // Create a node from a composite URI and a contribution location
+ String compositeURI = args[0];
+ String contributionLocation = args[1];
+ logger.info("SCA composite: " + compositeURI);
+ logger.info("SCA contribution: " + contributionLocation);
+ node = launcher.createNode(compositeURI, new Contribution("default", contributionLocation));
+ }
+
+ // Start the node
+ try {
+ node.getClass().getMethod("start").invoke(node);
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "SCA Node could not be started", e);
+ throw e;
+ }
+ logger.info("SCA Node is now started.");
+
+ // Install a shutdown hook
+ shutdown = new ShutdownThread(node);
+ Runtime.getRuntime().addShutdownHook(shutdown);
+
+ logger.info("Press 'q' to quit, 'r' to restart.");
+ int k = 0;
+ try {
+ while ((k != 'q') && (k != 'r')) {
+ k = System.in.read();
+ }
+ } catch (IOException e) {
+
+ // Wait forever
+ Object lock = new Object();
+ synchronized(lock) {
+ lock.wait();
+ }
+ }
+
+ // Stop the node
+ if (node != null) {
+ Object n = node;
+ node = null;
+ stopNode(n);
+ }
+
+ // Quit
+ if (k == 'q' ) {
+ break;
+ }
+ }
+ } catch (Exception e) {
+ // Stop the node
+ if (node != null) {
+ try {
+ Object n = node;
+ node = null;
+ stopNode(n);
+ } catch (Exception e2) {
+ }
+ }
+ throw e;
+
+ } finally {
+
+ // Remove the shutdown hook
+ if (shutdown != null) {
+ Runtime.getRuntime().removeShutdownHook(shutdown);
+ }
+ }
+ }
+
+ /**
+ * Stop the given node.
+ *
+ * @param node
+ * @throws Exception
+ */
+ private static void stopNode(Object node) throws Exception {
+ try {
+ node.getClass().getMethod("stop").invoke(node);
+ logger.info("SCA Node is now stopped.");
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "SCA Node could not be stopped", e);
+ throw e;
+ }
+ }
+
+ private static class ShutdownThread extends Thread {
+ private Object node;
+
+ public ShutdownThread(Object node) {
+ super();
+ this.node = node;
+ }
+
+ public void run() {
+ try {
+ stopNode(node);
+ } catch (Exception e) {
+ // Ignore
+ }
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java b/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
new file mode 100644
index 0000000000..7be1e14988
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java
@@ -0,0 +1,535 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.node.launcher;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.net.MalformedURLException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Common functions and constants used by the admin components.
+ *
+ * @version $Rev$ $Date$
+ */
+final class NodeLauncherUtil {
+ private static final Logger logger = Logger.getLogger(NodeLauncherUtil.class.getName());
+
+ private static final String TUSCANY_HOME = "TUSCANY_HOME";
+ private static final String TUSCANY_PATH = "TUSCANY_PATH";
+
+
+ /**
+ * Returns a ClassLoader for the Tuscany runtime JARs for use in a standalone
+ * J2SE environment.
+ *
+ * @param parentClassLoader
+ *
+ * @return
+ */
+ static ClassLoader standAloneRuntimeClassLoader(ClassLoader parentClassLoader) throws FileNotFoundException, URISyntaxException, MalformedURLException {
+ return runtimeClassLoader(parentClassLoader, new StandAloneJARFileNameFilter());
+ }
+
+ /**
+ * Returns a ClassLoader for the Tuscany runtime JARs for use in a Webapp
+ * environment.
+ *
+ * @param parentClassLoader
+ *
+ * @return
+ */
+ static ClassLoader webAppRuntimeClassLoader(ClassLoader parentClassLoader) throws FileNotFoundException, URISyntaxException, MalformedURLException {
+ return runtimeClassLoader(parentClassLoader, new WebAppJARFileNameFilter());
+ }
+
+ /**
+ * Returns a ClassLoader for the Tuscany runtime JARs.
+ *
+ * @param parentClassLoader
+ * @param filter
+ *
+ * @return
+ */
+ private static ClassLoader runtimeClassLoader(ClassLoader parentClassLoader, FilenameFilter filter) throws FileNotFoundException, URISyntaxException, MalformedURLException {
+
+ // Build list of runtime JARs
+ Set<URL> jarDirectoryURLs = new HashSet<URL>();
+ List<URL> jarURLs = new ArrayList<URL>();
+
+ // First determine the path to the launcher class
+ String resource = NodeLauncherUtil.class.getName().replace('.', '/') + ".class";
+ URL url = NodeLauncherUtil.class.getClassLoader().getResource(resource);
+ if (url == null) {
+ throw new FileNotFoundException(resource);
+ }
+ URI uri = url.toURI();
+
+ // If the launcher class is in a JAR, add all runtime JARs from directory containing
+ // that JAR (e.g. the Tuscany modules directory) as well as the ../modules and
+ // ../lib directories
+ String scheme = uri.getScheme();
+ if (scheme.equals("jar")) {
+ String path = uri.toString().substring(4);
+ int i = path.indexOf("!/");
+ if (i != -1) {
+ path = path.substring(0, i);
+ uri = URI.create(path);
+ }
+
+ File file = new File(uri);
+ if (file.exists()) {
+ File jarDirectory = file.getParentFile();
+ if (jarDirectory != null && jarDirectory.exists()) {
+
+ // Collect JAR files from the directory containing the input JAR
+ // (e.g. the Tuscany modules directory)
+ URL jarDirectoryURL = jarDirectory.toURI().toURL();
+ jarDirectoryURLs.add(jarDirectoryURL);
+ collectJARFiles(jarDirectory, jarURLs, filter);
+
+ File homeDirectory = jarDirectory.getParentFile();
+ if (homeDirectory != null && homeDirectory.exists()) {
+
+ // Collect JARs from the ../modules directory
+ File modulesDirectory = new File(homeDirectory, "modules");
+ URL modulesDirectoryURL = modulesDirectory.toURI().toURL();
+ if (!jarDirectoryURLs.contains(modulesDirectoryURL) && modulesDirectory.exists()) {
+ jarDirectoryURLs.add(modulesDirectoryURL);
+ collectJARFiles(modulesDirectory, jarURLs, filter);
+ }
+
+ // Collect JARs from the ../lib directory
+ File libDirectory = new File(homeDirectory, "lib");
+ URL libDirectoryURL = libDirectory.toURI().toURL();
+ if (!jarDirectoryURLs.contains(libDirectoryURL) && libDirectory.exists()) {
+ jarDirectoryURLs.add(libDirectoryURL);
+ collectJARFiles(libDirectory, jarURLs, filter);
+ }
+ }
+ }
+ }
+ }
+
+ // Look for a TUSCANY_HOME system property or environment variable
+ // Add all the JARs found under $TUSCANY_HOME, $TUSCANY_HOME/modules
+ // and $TUSCANY_HOME/lib
+ String home = System.getProperty(TUSCANY_HOME);
+ if (home == null || home.length() == 0) {
+ home = System.getenv(TUSCANY_HOME);
+ }
+ if (home != null && home.length() != 0) {
+ logger.fine(TUSCANY_HOME + ": " + home);
+ collectJARFiles(home, jarDirectoryURLs, jarURLs, filter);
+ }
+
+ // Look for a TUSCANY_PATH system property or environment variable
+ // Add all the JARs found under $TUSCANY_PATH, $TUSCANY_PATH/modules
+ // and $TUSCANY_PATH/lib
+ String ext = System.getProperty(TUSCANY_PATH);
+ if (ext == null || ext.length() == 0) {
+ ext = System.getenv(TUSCANY_PATH);
+ }
+ if (ext != null && ext.length() != 0) {
+ logger.fine(TUSCANY_PATH + ": " + ext);
+ String separator = System.getProperty("path.separator");
+ for (StringTokenizer tokens = new StringTokenizer(ext, separator); tokens.hasMoreTokens(); ) {
+ collectJARFiles(tokens.nextToken(), jarDirectoryURLs, jarURLs, filter);
+ }
+ }
+
+ // Return the runtime class loader
+ if (!jarURLs.isEmpty()) {
+
+ // Return a ClassLoader configured with the runtime JARs
+ ClassLoader classLoader = new RuntimeClassLoader(jarURLs.toArray(new URL[jarURLs.size()]), parentClassLoader);
+ return classLoader;
+
+ } else {
+ return null;
+ }
+ }
+
+ /**
+ * Collect JAR files under the given directory.
+ *
+ * @param directory
+ * @param jarDirectoryURLs
+ * @param jarURLs
+ * @param filter
+ * @throws MalformedURLException
+ */
+ private static void collectJARFiles(String directory, Set<URL> jarDirectoryURLs, List<URL> jarURLs, FilenameFilter filter)
+ throws MalformedURLException {
+ File directoryFile = new File(directory);
+ URL directoryURL = directoryFile.toURI().toURL();
+ if (!jarDirectoryURLs.contains(directoryURL) && directoryFile.exists()) {
+
+ // Collect files under $TUSCANY_HOME
+ jarDirectoryURLs.add(directoryURL);
+ collectJARFiles(directoryFile, jarURLs, filter);
+
+ // Collect files under $TUSCANY_HOME/modules
+ File modulesDirectory = new File(directoryFile, "modules");
+ URL modulesDirectoryURL = modulesDirectory.toURI().toURL();
+ if (!jarDirectoryURLs.contains(modulesDirectoryURL) && modulesDirectory.exists()) {
+ jarDirectoryURLs.add(modulesDirectoryURL);
+ collectJARFiles(modulesDirectory, jarURLs, filter);
+ }
+
+ // Collect files under $TUSCANY_HOME/lib
+ File libDirectory = new File(directoryFile, "lib");
+ URL libDirectoryURL = libDirectory.toURI().toURL();
+ if (!jarDirectoryURLs.contains(libDirectoryURL) && libDirectory.exists()) {
+ jarDirectoryURLs.add(libDirectoryURL);
+ collectJARFiles(libDirectory, jarURLs, filter);
+ }
+ }
+ }
+
+ /**
+ * Collect JAR files in the given directory
+ * @param directory
+ * @param urls
+ * @param filter
+ * @throws MalformedURLException
+ */
+ private static void collectJARFiles(File directory, List<URL> urls, FilenameFilter filter) throws MalformedURLException {
+ String[] files = directory.list(filter);
+ if (files != null) {
+ URL directoryURL = new URL(directory.toURI().toString() + "/");
+ int count = 0;
+ for (String file: files) {
+ URL url = new URL(directoryURL, file);
+ urls.add(url);
+ count++;
+ }
+ if (count != 0) {
+ logger.fine("Runtime classpath: "+ count + " JAR" + (count > 1? "s":"")+ " from " + directory.toString());
+ }
+ }
+ }
+
+ /**
+ * A file name filter used to filter JAR files.
+ */
+ private static class StandAloneJARFileNameFilter implements FilenameFilter {
+
+ public boolean accept(File dir, String name) {
+ name = name.toLowerCase();
+
+ // Exclude tuscany-sca-all and tuscany-sca-manifest as they duplicate
+ // code in the individual runtime module JARs
+ if (name.startsWith("tuscany-sca-all")) {
+ return false;
+ }
+ if (name.startsWith("tuscany-sca-manifest")) {
+ return false;
+ }
+
+ // Filter out the Tomcat and Webapp hosts
+ if (name.startsWith("tuscany-host-tomcat") ||
+ name.startsWith("tuscany-host-webapp")) {
+ //FIXME This is temporary
+ return false;
+ }
+
+ // Include JAR and MAR files
+ if (name.endsWith(".jar")) {
+ return true;
+ }
+ if (name.endsWith(".mar")) {
+ return true;
+ }
+ return false;
+ }
+ }
+
+ /**
+ * A file name filter used to filter JAR files.
+ */
+ private static class WebAppJARFileNameFilter extends StandAloneJARFileNameFilter {
+
+ @Override
+ public boolean accept(File dir, String name) {
+ if (!super.accept(dir, name)) {
+ return false;
+ }
+ name = name.toLowerCase();
+
+ // Exclude servlet-api JARs
+ if (name.startsWith("servlet-api")) {
+ return false;
+ }
+
+ // Exclude the Tomcat and Jetty hosts
+ if (name.startsWith("tuscany-host-tomcat") || name.startsWith("tuscany-host-jetty")) {
+ //FIXME This is temporary
+ return false;
+ }
+
+ return true;
+ }
+ }
+
+
+ /**
+ * Creates a new node.
+ *
+ * @param compositeURI
+ * @param contributions
+ * @throws LauncherException
+ */
+ static Object node(String configurationURI, String compositeURI, String compositeContent, Contribution[] contributions, ClassLoader contributionClassLoader) throws LauncherException {
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ try {
+
+ // Set up runtime ClassLoader
+ ClassLoader runtimeClassLoader = runtimeClassLoader(Thread.currentThread().getContextClassLoader(),
+ new StandAloneJARFileNameFilter());
+ if (runtimeClassLoader != null) {
+ Thread.currentThread().setContextClassLoader(runtimeClassLoader);
+ }
+
+ // Use Java reflection to create the node as only the runtime class
+ // loader knows the runtime classes required by the node
+ String className = "org.apache.tuscany.sca.implementation.node.launcher.NodeImplementationLauncherBootstrap";
+ Class<?> bootstrapClass;
+ if (runtimeClassLoader != null) {
+ bootstrapClass = Class.forName(className, true, runtimeClassLoader);
+ } else {
+ bootstrapClass = Class.forName(className);
+ }
+
+ Object bootstrap;
+ if (configurationURI != null) {
+
+ // Construct the node with a configuration URI
+ bootstrap = bootstrapClass.getConstructor(String.class).newInstance(configurationURI);
+
+ } else if (contributionClassLoader != null) {
+
+ // Construct the node with a compositeURI and a classloader
+ Constructor<?> constructor = bootstrapClass.getConstructor(String.class, ClassLoader.class);
+ bootstrap = constructor.newInstance(compositeURI, contributionClassLoader);
+
+ } else if (compositeContent != null) {
+
+ // Construct the node with a composite URI, the composite content and
+ // the URIs and locations of a list of contributions
+ Constructor<?> constructor = bootstrapClass.getConstructor(String.class, String.class, String[].class, String[].class);
+ String[] uris = new String[contributions.length];
+ String[] locations = new String[contributions.length];
+ for (int i = 0; i < contributions.length; i++) {
+ uris[i] = contributions[i].getURI();
+ locations[i] = contributions[i].getLocation();
+ }
+ bootstrap = constructor.newInstance(compositeURI, compositeContent, uris, locations);
+
+ } else {
+
+ // Construct the node with a composite URI and the URIs and
+ // locations of a list of contributions
+ Constructor<?> constructor = bootstrapClass.getConstructor(String.class, String[].class, String[].class);
+ String[] uris = new String[contributions.length];
+ String[] locations = new String[contributions.length];
+ for (int i = 0; i < contributions.length; i++) {
+ uris[i] = contributions[i].getURI();
+ locations[i] = contributions[i].getLocation();
+ }
+ bootstrap = constructor.newInstance(compositeURI, uris, locations);
+ }
+
+ Object node = bootstrapClass.getMethod("getNode").invoke(bootstrap);
+ return node;
+
+ } catch (Exception e) {
+ NodeLauncher.logger.log(Level.SEVERE, "SCA Node could not be created", e);
+ throw new LauncherException(e);
+ } finally {
+ Thread.currentThread().setContextClassLoader(tccl);
+ }
+ }
+
+ /**
+ * Creates a new node daemon.
+ *
+ * @throws LauncherException
+ */
+ static Object nodeDaemon() throws LauncherException {
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ try {
+ // Set up runtime ClassLoader
+ ClassLoader runtimeClassLoader = runtimeClassLoader(Thread.currentThread().getContextClassLoader(),
+ new StandAloneJARFileNameFilter());
+ if (runtimeClassLoader != null) {
+ Thread.currentThread().setContextClassLoader(runtimeClassLoader);
+ }
+
+ // Use Java reflection to create the node daemon as only the runtime class
+ // loader knows the runtime classes required by the node
+ String className = "org.apache.tuscany.sca.implementation.node.launcher.NodeImplementationDaemonBootstrap";
+ Class<?> bootstrapClass;
+ if (runtimeClassLoader != null) {
+ bootstrapClass = Class.forName(className, true, runtimeClassLoader);
+ } else {
+ bootstrapClass = Class.forName(className);
+ }
+ Object bootstrap = bootstrapClass.getConstructor().newInstance();
+
+ Object nodeDaemon = bootstrapClass.getMethod("getNode").invoke(bootstrap);
+ return nodeDaemon;
+
+ } catch (Exception e) {
+ NodeDaemonLauncher.logger.log(Level.SEVERE, "SCA Node Daemon could not be created", e);
+ throw new LauncherException(e);
+ } finally {
+ Thread.currentThread().setContextClassLoader(tccl);
+ }
+ }
+
+ /**
+ * Creates a new domain manager.
+ *
+ * @throws LauncherException
+ */
+ static Object domainManager(String rootDirectory) throws LauncherException {
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ try {
+ // Set up runtime ClassLoader
+ ClassLoader runtimeClassLoader = runtimeClassLoader(Thread.currentThread().getContextClassLoader(),
+ new StandAloneJARFileNameFilter());
+ if (runtimeClassLoader != null) {
+ Thread.currentThread().setContextClassLoader(runtimeClassLoader);
+ }
+
+ // Use Java reflection to create the node daemon as only the runtime class
+ // loader knows the runtime classes required by the node
+ String className = "org.apache.tuscany.sca.domain.manager.launcher.DomainManagerLauncherBootstrap";
+ Class<?> bootstrapClass;
+ if (runtimeClassLoader != null) {
+ bootstrapClass = Class.forName(className, true, runtimeClassLoader);
+ } else {
+ bootstrapClass = Class.forName(className);
+ }
+ Constructor<?> constructor = bootstrapClass.getConstructor(String.class);
+ Object bootstrap = constructor.newInstance(rootDirectory);
+
+ Object domainManager = bootstrapClass.getMethod("getNode").invoke(bootstrap);
+ return domainManager;
+
+ } catch (Exception e) {
+ DomainManagerLauncher.logger.log(Level.SEVERE, "SCA Domain Manager could not be created", e);
+ throw new LauncherException(e);
+ } finally {
+ Thread.currentThread().setContextClassLoader(tccl);
+ }
+ }
+
+ /**
+ * Simple URL class loader for the runtime JARs
+ */
+ private static class RuntimeClassLoader extends URLClassLoader {
+ private static final ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
+ private ClassLoader parent;
+
+ /**
+ * Constructs a new class loader.
+ * @param urls
+ * @param parent
+ */
+ private RuntimeClassLoader(URL[] urls, ClassLoader parent) {
+ super(urls);
+ this.parent = parent;
+ }
+
+ @Override
+ public URL findResource(String name) {
+ URL url = super.findResource(name);
+ if (url == null) {
+ url = parent.getResource(name);
+ }
+ return url;
+ }
+
+ @Override
+ public Enumeration<URL> findResources(String name) throws IOException {
+ Enumeration<URL> resources = super.findResources(name);
+ Enumeration<URL> parentResources = parent.getResources(name);
+ List<URL> allResources = new ArrayList<URL>();
+ for (; resources.hasMoreElements(); ) {
+ allResources.add(resources.nextElement());
+ }
+ for (; parentResources.hasMoreElements(); ) {
+ allResources.add(parentResources.nextElement());
+ }
+ return Collections.enumeration(allResources);
+ }
+
+ @Override
+ protected Class<?> findClass(String name) throws ClassNotFoundException {
+ Class<?> cl;
+
+ // First try to load the class using the parent classloader
+ try {
+ cl = parent.loadClass(name);
+ ClassLoader loadedBy = cl.getClassLoader();
+
+ // If the class was not loaded directly by the parent classloader
+ // or the system classloader try to load a local version of the class
+ // using our RuntimeClassloader instead
+ if (loadedBy != parent &&
+ loadedBy != systemClassLoader &&
+ loadedBy != null) {
+
+ try {
+ cl = super.findClass(name);
+ } catch (ClassNotFoundException e) {
+ // No class alternative was found in our RuntimeClassloader,
+ // use the class found in the parent classloader hierarchy
+ }
+ }
+ } catch (ClassNotFoundException e) {
+
+ // The class was not found by the parent class loader, try
+ // to load it using our RuntimeClassloader
+ cl = super.findClass(name);
+ }
+
+ return cl;
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeMain.java b/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeMain.java
new file mode 100644
index 0000000000..eafe4ddaa0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeMain.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.node.launcher;
+
+
+/**
+ * Main class for this JAR.
+ * With no arguments this class launches the SCA Node Daemon.
+ * With a "domain" argument it launches the SCA domain admin node.
+ * With any other argument it launches an SCA Node.
+ *
+ * @version $Rev$ $Date$
+ */
+public class NodeMain {
+
+ public static void main(String[] args) throws Exception {
+ if (args.length != 0) {
+ if (args[0].equals("domain")) {
+ DomainManagerLauncher.main(args);
+ } else {
+ NodeLauncher.main(args);
+ }
+ } else {
+ NodeDaemonLauncher.main(args);
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.java b/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.java
new file mode 100644
index 0000000000..5345363031
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.java
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.node.launcher;
+
+import static org.apache.tuscany.sca.node.launcher.NodeLauncherUtil.webAppRuntimeClassLoader;
+
+import java.io.IOException;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.servlet.Filter;
+import javax.servlet.FilterConfig;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+/**
+ * A Servlet filter that forwards service requests to the Servlets registered with
+ * the Tuscany ServletHost.
+ *
+ * @version $Rev$ $Date$
+ */
+public class NodeServletFilter implements Filter {
+ private static final long serialVersionUID = 1L;
+
+ private static final String NODE_WEB_APP_SERVLET_HOST = "org.apache.tuscany.sca.implementation.node.webapp.NodeWebAppServletHost";
+
+ private static final Logger logger = Logger.getLogger(NodeServletFilter.class.getName());
+
+ private ClassLoader runtimeClassLoader;
+ private Class<?> servletHostClass;
+ private Object servletHost;
+ private Filter filter;
+
+ public void init(FilterConfig filterConfig) throws ServletException {
+ logger.info("Apache Tuscany SCA WebApp Node is starting...");
+
+ try {
+ // Get the Tuscany runtime ClassLoader
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ runtimeClassLoader = webAppRuntimeClassLoader(getClass().getClassLoader());
+
+ try {
+ if (runtimeClassLoader != null) {
+ Thread.currentThread().setContextClassLoader(runtimeClassLoader);
+ }
+
+ // Load the Tuscany WebApp Servlet host and get the host instance
+ // for the current webapp
+ String className = NODE_WEB_APP_SERVLET_HOST;
+ if (runtimeClassLoader != null) {
+ servletHostClass = Class.forName(className, true, runtimeClassLoader);
+ } else {
+ servletHostClass = Class.forName(className);
+ }
+ servletHost = servletHostClass.getMethod("servletHost").invoke(null);
+
+ // Initialize the Servlet host
+ servletHostClass.getMethod("init", FilterConfig.class).invoke(servletHost, filterConfig);
+
+ // The Servlet host also implements the filter interface
+ filter = (Filter)servletHost;
+
+ } finally {
+ Thread.currentThread().setContextClassLoader(tccl);
+ }
+
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "Error Starting SCA WebApp Node", e);
+ throw new ServletException(e);
+ }
+
+ logger.info("SCA WebApp Node started.");
+ }
+
+ public void destroy() {
+ logger.info("Apache Tuscany WebApp Node stopping...");
+ if (servletHost != null) {
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ try {
+ if (runtimeClassLoader != null) {
+ Thread.currentThread().setContextClassLoader(runtimeClassLoader);
+ }
+
+ servletHostClass.getMethod("destroy").invoke(servletHost);
+
+ } catch (Exception e) {
+ logger.log(Level.SEVERE, "Error Stopping SCA WebApp Node", e);
+ } finally {
+ Thread.currentThread().setContextClassLoader(tccl);
+ }
+ }
+ logger.info("SCA WebApp Node stopped.");
+ }
+
+ public void doFilter(ServletRequest request, ServletResponse response, javax.servlet.FilterChain chain)
+ throws IOException, ServletException {
+
+ // Delegate to the Servlet host filter
+ ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+ try {
+ if (runtimeClassLoader != null) {
+ Thread.currentThread().setContextClassLoader(runtimeClassLoader);
+ }
+
+ filter.doFilter(request, response, chain);
+
+ } finally {
+ Thread.currentThread().setContextClassLoader(tccl);
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy-xml/LICENSE b/sca-java-1.x/branches/sca-android/modules/policy-xml/LICENSE
new file mode 100644
index 0000000000..6e529a25c4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy-xml/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/policy-xml/META-INF/README b/sca-java-1.x/branches/sca-android/modules/policy-xml/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy-xml/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/policy-xml/NOTICE b/sca-java-1.x/branches/sca-android/modules/policy-xml/NOTICE
new file mode 100644
index 0000000000..1325efd8bf
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy-xml/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/policy-xml/pom.xml b/sca-java-1.x/branches/sca-android/modules/policy-xml/pom.xml
new file mode 100644
index 0000000000..178648c7a3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy-xml/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>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-policy-xml</artifactId>
+ <name>Apache Tuscany SCA Policy XML Model</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-policy</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-contribution</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.codehaus.woodstox</groupId>
+ <artifactId>wstx-asl</artifactId>
+ <version>3.2.1</version>
+ <scope>runtime</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>stax</groupId>
+ <artifactId>stax-api</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.policy.xml</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.policy.xml*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java
new file mode 100644
index 0000000000..d47cbd7dbe
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.xml;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.impl.BindingTypeImpl;
+
+
+/**
+ * Processor for handling XML models of BindingType meta data definitions
+ *
+ * @version $Rev$ $Date$
+ */
+public class BindingTypeProcessor extends IntentAttachPointTypeProcessor {
+
+ public BindingTypeProcessor(PolicyFactory policyFactory, IntentAttachPointTypeFactory intentAttachPointTypeFactory,
+ StAXArtifactProcessor<Object> extensionProcessor, Monitor monitor) {
+ super(policyFactory, intentAttachPointTypeFactory, extensionProcessor, monitor);
+ }
+
+ public BindingTypeProcessor(ModelFactoryExtensionPoint modelFactories,
+ StAXArtifactProcessor<Object> extensionProcessor,
+ Monitor monitor) {
+ super(modelFactories.getFactory(PolicyFactory.class),
+ modelFactories.getFactory(IntentAttachPointTypeFactory.class), extensionProcessor, monitor);
+ }
+
+ public QName getArtifactType() {
+ return BINDING_TYPE_QNAME;
+ }
+
+ @Override
+ protected IntentAttachPointType resolveExtensionType(IntentAttachPointType extnType, ModelResolver resolver) throws ContributionResolveException {
+ if ( extnType instanceof BindingTypeImpl ) {
+ BindingTypeImpl bindingType = (BindingTypeImpl)extnType;
+ return resolver.resolveModel(BindingTypeImpl.class, bindingType);
+ } else {
+ return extnType;
+ }
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java
new file mode 100644
index 0000000000..119afa3473
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.xml;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.impl.ImplementationTypeImpl;
+
+
+/**
+ * Processor for handling XML models of ImplementationType meta data definitions
+ *
+ * @version $Rev$ $Date$
+ */
+public class ImplementationTypeProcessor extends IntentAttachPointTypeProcessor {
+
+ public ImplementationTypeProcessor(PolicyFactory policyFactory, IntentAttachPointTypeFactory intentAttachPointTypeFactory,
+ StAXArtifactProcessor<Object> extensionProcessor, Monitor monitor) {
+ super(policyFactory, intentAttachPointTypeFactory, extensionProcessor, monitor);
+ }
+
+ public ImplementationTypeProcessor(ModelFactoryExtensionPoint modelFactories,
+ StAXArtifactProcessor<Object> extensionProcessor,
+ Monitor monitor) {
+ super(modelFactories.getFactory(PolicyFactory.class),
+ modelFactories.getFactory(IntentAttachPointTypeFactory.class), extensionProcessor, monitor);
+ }
+
+ public QName getArtifactType() {
+ return IMPLEMENTATION_TYPE_QNAME;
+ }
+
+ @Override
+ protected IntentAttachPointType resolveExtensionType(IntentAttachPointType extnType, ModelResolver resolver) throws ContributionResolveException {
+ if ( extnType instanceof ImplementationTypeImpl ) {
+ ImplementationTypeImpl implType = (ImplementationTypeImpl)extnType;
+ return resolver.resolveModel(ImplementationTypeImpl.class, implType);
+ } else {
+ return extnType;
+ }
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentAttachPointTypeProcessor.java b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentAttachPointTypeProcessor.java
new file mode 100644
index 0000000000..ec357aea93
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentAttachPointTypeProcessor.java
@@ -0,0 +1,248 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.xml;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.impl.BindingTypeImpl;
+import org.apache.tuscany.sca.policy.impl.ImplementationTypeImpl;
+
+
+/**
+ * Processor for handling XML models of ExtensionType meta data definitions
+ *
+ * @version $Rev$ $Date$
+ */
+abstract class IntentAttachPointTypeProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<IntentAttachPointType>, PolicyConstants {
+
+ private IntentAttachPointTypeFactory attachPointTypeFactory;
+ private PolicyFactory policyFactory;
+ private Monitor monitor;
+
+ protected abstract IntentAttachPointType resolveExtensionType(IntentAttachPointType extnType, ModelResolver resolver) throws ContributionResolveException;
+
+ public IntentAttachPointTypeProcessor(PolicyFactory policyFactory,
+ IntentAttachPointTypeFactory attachPointTypeFactory,
+ StAXArtifactProcessor<Object> extensionProcessor,
+ Monitor monitor) {
+ this.policyFactory = policyFactory;
+ this.attachPointTypeFactory = attachPointTypeFactory;
+ this.monitor = monitor;
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "policy-xml-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ public IntentAttachPointType read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ QName type = getQName(reader, TYPE);
+
+ if ( type != null ) {
+ if ( type.getLocalPart().startsWith(BINDING) ) {
+ IntentAttachPointType bindingType = attachPointTypeFactory.createBindingType();
+ bindingType.setName(type);
+ bindingType.setUnresolved(true);
+
+ readAlwaysProvidedIntents(bindingType, reader);
+ readMayProvideIntents(bindingType, reader);
+ return bindingType;
+ } else if ( type.getLocalPart().startsWith(IMPLEMENTATION) ) {
+ IntentAttachPointType implType = attachPointTypeFactory.createImplementationType();
+ implType.setName(type);
+ implType.setUnresolved(true);
+
+ readAlwaysProvidedIntents(implType, reader);
+ readMayProvideIntents(implType, reader);
+ return implType;
+ } else {
+ error("UnrecognizedIntentAttachPointType", reader, type);
+ //throw new ContributionReadException("Unrecognized IntentAttachPointType - " + type);
+ }
+ } else {
+ error("RequiredAttributeMissing", reader, TYPE);
+ //throw new ContributionReadException("Required attribute '" + TYPE +
+ //"' missing from BindingType Definition");
+ }
+ return null;
+ }
+
+ private void readAlwaysProvidedIntents(IntentAttachPointType extnType, XMLStreamReader reader) {
+ String value = reader.getAttributeValue(null, ALWAYS_PROVIDES);
+ if (value != null) {
+ List<Intent> alwaysProvided = extnType.getAlwaysProvidedIntents();
+ for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
+ QName qname = getQNameValue(reader, tokens.nextToken());
+ Intent intent = policyFactory.createIntent();
+ intent.setName(qname);
+ alwaysProvided.add(intent);
+ }
+ }
+ }
+
+ private void readMayProvideIntents(IntentAttachPointType extnType, XMLStreamReader reader) {
+ String value = reader.getAttributeValue(null, MAY_PROVIDE);
+ if (value != null) {
+ List<Intent> mayProvide = extnType.getMayProvideIntents();
+ for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
+ QName qname = getQNameValue(reader, tokens.nextToken());
+ Intent intent = policyFactory.createIntent();
+ intent.setName(qname);
+ mayProvide.add(intent);
+ }
+ }
+ }
+
+ public void write(IntentAttachPointType extnType, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+
+ // Write an <sca:bindingType or sca:implementationType>
+ if ( extnType instanceof BindingTypeImpl ) {
+ writer.writeStartElement(SCA10_NS, BINDING_TYPE);
+ } else if ( extnType instanceof ImplementationTypeImpl ) {
+ writer.writeStartElement(SCA10_NS, IMPLEMENTATION_TYPE);
+ }
+
+ writeAlwaysProvidesIntentsAttribute(extnType, writer);
+ writeMayProvideIntentsAttribute(extnType, writer);
+
+ writer.writeEndElement();
+ }
+
+ private void writeMayProvideIntentsAttribute(IntentAttachPointType extnType, XMLStreamWriter writer) throws XMLStreamException {
+ StringBuffer sb = new StringBuffer();
+ for ( Intent intent : extnType.getMayProvideIntents() ) {
+ writer.writeNamespace(intent.getName().getPrefix(), intent.getName().getNamespaceURI());
+ sb.append(intent.getName().getPrefix() + COLON + intent.getName().getLocalPart());
+ sb.append(WHITE_SPACE);
+ }
+
+ if ( sb.length() > 0 ) {
+ writer.writeAttribute(MAY_PROVIDE, sb.toString());
+ }
+ }
+
+ private void writeAlwaysProvidesIntentsAttribute(IntentAttachPointType extnType, XMLStreamWriter writer) throws XMLStreamException {
+ StringBuffer sb = new StringBuffer();
+ for ( Intent intent : extnType.getAlwaysProvidedIntents() ) {
+ writer.writeNamespace(intent.getName().getPrefix(), intent.getName().getNamespaceURI());
+ sb.append(intent.getName().getPrefix() + COLON + intent.getName().getLocalPart());
+ sb.append(WHITE_SPACE);
+ }
+
+ if ( sb.length() > 0 ) {
+ writer.writeAttribute(ALWAYS_PROVIDES, sb.toString());
+
+ }
+ }
+
+ public void resolve(IntentAttachPointType extnType, ModelResolver resolver) throws ContributionResolveException {
+
+ if (extnType != null && extnType.isUnresolved()) {
+ resolveAlwaysProvidedIntents(extnType, resolver);
+ resolveMayProvideIntents(extnType, resolver);
+ extnType.setUnresolved(false);
+ //resolveExtensionType(extnType, resolver);
+ }
+ }
+
+ private void resolveAlwaysProvidedIntents(IntentAttachPointType extensionType,
+ ModelResolver resolver) throws ContributionResolveException {
+ if (extensionType != null) {
+ // resolve all provided intents
+ List<Intent> alwaysProvided = new ArrayList<Intent>();
+ for (Intent providedIntent : extensionType.getAlwaysProvidedIntents()) {
+ if (providedIntent.isUnresolved()) {
+ providedIntent = resolver.resolveModel(Intent.class, providedIntent);
+ if (!providedIntent.isUnresolved()) {
+ alwaysProvided.add(providedIntent);
+ } else {
+ error("AlwaysProvidedIntentNotFound", resolver, providedIntent, extensionType);
+ //throw new ContributionResolveException("Always Provided Intent - " + providedIntent
+ //+ " not found for ExtensionType "
+ //+ extensionType);
+ }
+ } else {
+ alwaysProvided.add(providedIntent);
+ }
+ }
+ extensionType.getAlwaysProvidedIntents().clear();
+ extensionType.getAlwaysProvidedIntents().addAll(alwaysProvided);
+ }
+ }
+
+ private void resolveMayProvideIntents(IntentAttachPointType extensionType,
+ ModelResolver resolver) throws ContributionResolveException {
+ if (extensionType != null) {
+ // resolve all provided intents
+ List<Intent> mayProvide = new ArrayList<Intent>();
+ for (Intent providedIntent : extensionType.getMayProvideIntents()) {
+ if (providedIntent.isUnresolved()) {
+ providedIntent = resolver.resolveModel(Intent.class, providedIntent);
+ if (!providedIntent.isUnresolved()) {
+ mayProvide.add(providedIntent);
+ } else {
+ error("MayProvideIntentNotFound", resolver, providedIntent, extensionType);
+ //throw new ContributionResolveException("May Provide Intent - " + providedIntent
+ //+ " not found for ExtensionType "
+ //+ extensionType);
+ }
+ } else {
+ mayProvide.add(providedIntent);
+ }
+ }
+ extensionType.getMayProvideIntents().clear();
+ extensionType.getMayProvideIntents().addAll(mayProvide);
+ }
+ }
+
+ public Class<IntentAttachPointType> getModelType() {
+ return IntentAttachPointType.class;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java
new file mode 100644
index 0000000000..3f1008e9a8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy.xml;
+
+import javax.xml.namespace.QName;
+
+/**
+ * constants related to policy framework
+ *
+ * @version $Rev$ $Date$
+ */
+public interface PolicyConstants {
+ String WHITE_SPACE = " ";
+ String COLON = ":";
+ String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0";
+ String TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.0";
+ String INTENT = "intent";
+ String POLICY_SET = "policySet";
+ String POLICY_SET_REFERENCE = "policySetReference";
+ String INTENT_MAP = "intentMap";
+ String NAME = "name";
+ String TARGET_NAMESPACE = "targetNamespace";
+ String SCA_DEFINITIONS = "definitions";
+ String CONSTRAINS = "constrains";
+ String DESCRIPTION = "description";
+ String PROVIDES = "provides";
+ String APPLIES_TO = "appliesTo";
+ String ALWAYS_APPLIES_TO = "alwaysAppliesTo";
+ String QUALIFIER = ".";
+ String INTENT_MAP_QUALIFIER = "qualifier";
+ String REQUIRES = "requires";
+ String EXCLUDES = "excludes";
+ String DEFAULT = "default";
+
+ String ALWAYS_PROVIDES = "alwaysProvides";
+ String MAY_PROVIDE = "mayProvide";
+ String TYPE = "type";
+ String IMPLEMENTATION_TYPE = "implementationType";
+ String BINDING_TYPE = "bindingType";
+ QName IMPLEMENTATION_TYPE_QNAME = new QName(SCA10_NS, IMPLEMENTATION_TYPE);
+ QName BINDING_TYPE_QNAME = new QName(SCA10_NS, BINDING_TYPE);
+ String BINDING = "binding";
+ String IMPLEMENTATION = "implementation";
+
+ QName POLICY_INTENT_QNAME = new QName(SCA10_NS, INTENT);
+ QName POLICY_SET_QNAME = new QName(SCA10_NS, POLICY_SET);
+ QName POLICY_INTENT_MAP_QNAME = new QName(SCA10_NS, INTENT_MAP);
+ QName SCA_DEFINITIONS_QNAME = new QName(SCA10_NS, SCA_DEFINITIONS);
+ QName DESCRIPTION_QNAME = new QName(SCA10_NS, DESCRIPTION);
+ QName POLICY_INTENT_MAP_QUALIFIER_QNAME = new QName(SCA10_NS, INTENT_MAP_QUALIFIER);
+ QName POLICY_SET_REFERENCE_QNAME = new QName(SCA10_NS, POLICY_SET_REFERENCE);
+
+ String QUALIFIED_INTENT_CONSTRAINS_ERROR = " - Qualified Intents must not specify 'constrains' attribute";
+
+
+
+
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyIntentProcessor.java b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyIntentProcessor.java
new file mode 100644
index 0000000000..76ef8df298
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyIntentProcessor.java
@@ -0,0 +1,417 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.xml;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.ProfileIntent;
+import org.apache.tuscany.sca.policy.QualifiedIntent;
+
+/**
+ * Processor for handling XML models of PolicyIntent definitions
+ *
+ * @version $Rev$ $Date$
+ */
+abstract class PolicyIntentProcessor<T extends Intent> extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<T>, PolicyConstants {
+
+ private PolicyFactory policyFactory;
+ private Monitor monitor;
+
+ public PolicyIntentProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
+ this.policyFactory = modelFactories.getFactory(PolicyFactory.class);
+ this.monitor = monitor;
+ }
+
+ public PolicyIntentProcessor(PolicyFactory policyFactory, Monitor monitor) {
+ this.policyFactory = policyFactory;
+ this.monitor = monitor;
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "policy-xml-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ public T read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ Intent policyIntent = null;
+ String policyIntentName = reader.getAttributeValue(null, NAME);
+ if (policyIntentName == null) {
+ error("IntentNameMissing", reader);
+ return (T)policyIntent;
+ }
+
+ // Read an <sca:intent>
+ if (reader.getAttributeValue(null, REQUIRES) != null) {
+ policyIntent = policyFactory.createProfileIntent();
+ } else if ( policyIntentName != null && policyIntentName.indexOf(QUALIFIER) != -1) {
+ policyIntent = policyFactory.createQualifiedIntent();
+
+ int qualifierIndex = policyIntentName.lastIndexOf(QUALIFIER);
+ Intent qualifiableIntent = policyFactory.createIntent();
+ qualifiableIntent.setUnresolved(true);
+ qualifiableIntent.setName(new QName(policyIntentName.substring(0, qualifierIndex)));
+
+ ((QualifiedIntent)policyIntent).setQualifiableIntent(qualifiableIntent);
+ } else {
+ policyIntent = policyFactory.createIntent();
+ }
+ policyIntent.setName(new QName(policyIntentName));
+
+ if ( policyIntent instanceof ProfileIntent ) {
+ readRequiredIntents((ProfileIntent)policyIntent, reader);
+ }
+ else {
+ readExcludedIntents(policyIntent, reader);
+ }
+
+ readConstrainedArtifacts(policyIntent, reader);
+
+ int event = reader.getEventType();
+ QName name = null;
+ while (reader.hasNext()) {
+ event = reader.getEventType();
+ switch (event) {
+ case START_ELEMENT : {
+ name = reader.getName();
+ if (DESCRIPTION_QNAME.equals(name)) {
+ policyIntent.setDescription(reader.getElementText());
+ }
+ break;
+ }
+ }
+ if (event == END_ELEMENT && POLICY_INTENT_QNAME.equals(reader.getName())) {
+ break;
+ }
+
+ //Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
+ }
+ return (T)policyIntent;
+ }
+
+ public void write(T policyIntent, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+ // Write an <sca:intent>
+ writer.writeStartElement(PolicyConstants.SCA10_NS, INTENT);
+ writer.writeNamespace(policyIntent.getName().getPrefix(), policyIntent.getName().getNamespaceURI());
+ writer.writeAttribute(PolicyConstants.NAME,
+ policyIntent.getName().getPrefix() + COLON + policyIntent.getName().getLocalPart());
+ if (policyIntent instanceof ProfileIntent) {
+ ProfileIntent profileIntent = (ProfileIntent)policyIntent;
+ if (profileIntent.getRequiredIntents() != null &&
+ profileIntent.getRequiredIntents().size() > 0) {
+ StringBuffer sb = new StringBuffer();
+ for (Intent requiredIntents : profileIntent.getRequiredIntents()) {
+ sb.append(requiredIntents.getName());
+ sb.append(" ");
+ }
+ writer.writeAttribute(PolicyConstants.REQUIRES, sb.toString());
+ }
+ }
+ else {
+ if (policyIntent.getExcludedIntents() != null &&
+ policyIntent.getExcludedIntents().size() > 0) {
+ StringBuffer sb = new StringBuffer();
+ for (Intent excludedIntents : policyIntent.getExcludedIntents()) {
+ sb.append(excludedIntents.getName());
+ sb.append(" ");
+ }
+ writer.writeAttribute(PolicyConstants.EXCLUDES, sb.toString());
+ }
+ }
+
+ if (!(policyIntent instanceof QualifiedIntent) ) {
+ if (policyIntent.getConstrains() != null &&
+ policyIntent.getConstrains().size() > 0) {
+ StringBuffer sb = new StringBuffer();
+ for (QName contrainedArtifact : policyIntent.getConstrains()) {
+ sb.append(contrainedArtifact.toString());
+ sb.append(" ");
+ }
+ writer.writeAttribute(CONSTRAINS, sb.toString());
+ } else {
+ error("ContrainsAttributeMissing", policyIntent, policyIntent.getName());
+ //throw new ContributionWriteException("Contrains attribute missing from " +
+ //"Policy Intent Definition" + policyIntent.getName());
+ }
+ }
+
+ if ( policyIntent.getDescription() != null && policyIntent.getDescription().length() > 0) {
+ writer.writeStartElement(PolicyConstants.SCA10_NS, DESCRIPTION);
+ writer.writeCData(policyIntent.getDescription());
+ writer.writeEndElement();
+ }
+
+ writer.writeEndElement();
+ }
+
+ //FIXME This method is never used
+// private Intent resolveRequiredIntents(ProfileIntent policyIntent, ModelResolver resolver) throws ContributionResolveException {
+// boolean isUnresolved = false;
+// //FIXME: Need to check for cyclic references first i.e an A requiring B and then B requiring A...
+// if (policyIntent != null && policyIntent.isUnresolved()) {
+//
+// //resolve all required intents
+// List<Intent> requiredIntents = new ArrayList<Intent>();
+// for (Intent requiredIntent : policyIntent.getRequiredIntents()) {
+// if ( requiredIntent.isUnresolved() ) {
+// //policyIntent.getRequiredIntents().remove(requiredIntent);
+// requiredIntent = resolver.resolveModel(Intent.class, requiredIntent);
+// requiredIntents.add(requiredIntent);
+// if (requiredIntent.isUnresolved()) {
+// isUnresolved = true;
+// }
+// }
+// }
+// policyIntent.getRequiredIntents().clear();
+// policyIntent.getRequiredIntents().addAll(requiredIntents);
+// }
+// policyIntent.setUnresolved(isUnresolved);
+//
+// return policyIntent;
+// }
+
+ //FIXME This method is never used
+// private Intent resolveQualifiableIntent(QualifiedIntent policyIntent, ModelResolver resolver) throws ContributionResolveException {
+// boolean isUnresolved = false;
+//
+// if (policyIntent != null && policyIntent.isUnresolved()) {
+// //resolve the qualifiable intent
+// Intent qualifiableIntent =
+// resolver.resolveModel(Intent.class, policyIntent.getQualifiableIntent());
+// policyIntent.setQualifiableIntent(qualifiableIntent);
+// isUnresolved = qualifiableIntent.isUnresolved();
+// }
+// policyIntent.setUnresolved(isUnresolved);
+//
+// return policyIntent;
+// }
+
+ private void resolveContrainedArtifacts(Intent policyIntent, ModelResolver resolver) {
+ //FIXME : need to figure out this resolution.
+ policyIntent.setUnresolved(false);
+ }
+
+ private void resolveProfileIntent(ProfileIntent policyIntent, ModelResolver resolver)
+ throws ContributionResolveException {
+ // FIXME: Need to check for cyclic references first i.e an A requiring B
+ // and then B requiring A...
+ if (policyIntent != null) {
+ // resolve all required intents
+ List<Intent> requiredIntents = new ArrayList<Intent>();
+ for (Intent requiredIntent : policyIntent.getRequiredIntents()) {
+ if (requiredIntent.isUnresolved()) {
+ Intent resolvedRequiredIntent = resolver.resolveModel(Intent.class, requiredIntent);
+ // At this point, when the required intent is not resolved, it does not mean
+ // its undeclared, chances are that their dependency are not resolved yet.
+ // Lets try to resolve them first.
+ if (resolvedRequiredIntent.isUnresolved()) {
+ if (resolvedRequiredIntent instanceof ProfileIntent) {
+ if ((((ProfileIntent)resolvedRequiredIntent).getRequiredIntents()).contains(policyIntent)) {
+ error("CyclicReferenceFound", resolver, requiredIntent, policyIntent);
+ return;
+ }
+ resolveDependent(resolvedRequiredIntent, resolver);
+ }
+ }
+
+ if (!resolvedRequiredIntent.isUnresolved()) {
+ requiredIntents.add(resolvedRequiredIntent);
+ } else {
+ error("RequiredIntentNotFound", resolver, requiredIntent, policyIntent);
+ return;
+ //throw new ContributionResolveException("Required Intent - " + requiredIntent
+ //+ " not found for ProfileIntent " + policyIntent);
+ }
+ } else {
+ requiredIntents.add(requiredIntent);
+ }
+ }
+ policyIntent.getRequiredIntents().clear();
+ policyIntent.getRequiredIntents().addAll(requiredIntents);
+ }
+ }
+
+ private void resolveQualifiedIntent(QualifiedIntent policyIntent, ModelResolver resolver)
+ throws ContributionResolveException {
+ if (policyIntent != null) {
+ //resolve the qualifiable intent
+ Intent qualifiableIntent = policyIntent.getQualifiableIntent();
+ if (qualifiableIntent.isUnresolved()) {
+ Intent resolvedQualifiableIntent = resolver.resolveModel(Intent.class, qualifiableIntent);
+ // At this point, when the qualifiable intent is not resolved, it does not mean
+ // its undeclared, chances are that their dependency are not resolved yet.
+ // Lets try to resolve them first.
+ if (resolvedQualifiableIntent.isUnresolved()) {
+ if (resolvedQualifiableIntent instanceof QualifiedIntent) {
+ resolveDependent(resolvedQualifiableIntent, resolver);
+ }
+ }
+
+ if (!resolvedQualifiableIntent.isUnresolved()) {
+ policyIntent.setQualifiableIntent(resolvedQualifiableIntent);
+ } else {
+ error("QualifiableIntentNotFound", resolver, qualifiableIntent, policyIntent);
+ //throw new ContributionResolveException("Qualifiable Intent - " + qualifiableIntent
+ //+ " not found for QualifiedIntent " + policyIntent);
+ }
+ }
+ }
+ }
+
+ public void resolveDependent(Intent policyIntent, ModelResolver resolver) throws ContributionResolveException {
+ if (policyIntent instanceof ProfileIntent)
+ resolveProfileIntent((ProfileIntent)policyIntent, resolver);
+
+ if (policyIntent instanceof QualifiedIntent)
+ resolveQualifiedIntent((QualifiedIntent)policyIntent, resolver);
+
+ resolveContrainedArtifacts(policyIntent, resolver);
+ }
+
+ public void resolve(T policyIntent, ModelResolver resolver) throws ContributionResolveException {
+ if (policyIntent instanceof ProfileIntent) {
+ resolveProfileIntent((ProfileIntent)policyIntent, resolver);
+ }
+ else {
+ resolveExcludedIntents(policyIntent, resolver);
+ }
+
+ if (policyIntent instanceof QualifiedIntent) {
+ resolveQualifiedIntent((QualifiedIntent)policyIntent, resolver);
+ }
+
+ resolveContrainedArtifacts(policyIntent, resolver);
+
+ /* This is too late in the processing
+ if ( !policyIntent.isUnresolved() ) {
+ resolver.addModel(policyIntent);
+ }
+ */
+ }
+
+ public QName getArtifactType() {
+ return POLICY_INTENT_QNAME;
+ }
+
+ private void readConstrainedArtifacts(Intent policyIntent, XMLStreamReader reader) throws ContributionReadException {
+ String value = reader.getAttributeValue(null, CONSTRAINS);
+ if ( policyIntent instanceof QualifiedIntent && value != null) {
+ error("ErrorInPolicyIntentDefinition", policyIntent, policyIntent.getName(), QUALIFIED_INTENT_CONSTRAINS_ERROR);
+ //String errorMsg = "Error in PolicyIntent Definition - " + policyIntent.getName() + QUALIFIED_INTENT_CONSTRAINS_ERROR;
+ //throw new ContributionReadException(errorMsg);
+ } else {
+ if (value != null) {
+ List<QName> constrainedArtifacts = policyIntent.getConstrains();
+ for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
+ QName qname = getQNameValue(reader, tokens.nextToken());
+ constrainedArtifacts.add(qname);
+ }
+ }
+ }
+ }
+
+ private void readRequiredIntents(ProfileIntent policyIntent, XMLStreamReader reader) {
+ String value = reader.getAttributeValue(null, REQUIRES);
+ if (value != null) {
+ List<Intent> requiredIntents = policyIntent.getRequiredIntents();
+ for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
+ QName qname = getQNameValue(reader, tokens.nextToken());
+ Intent intent = policyFactory.createIntent();
+ intent.setName(qname);
+ intent.setUnresolved(true);
+ requiredIntents.add(intent);
+ }
+ }
+ }
+
+ private void readExcludedIntents(Intent policyIntent, XMLStreamReader reader) {
+ String value = reader.getAttributeValue(null, "excludes");
+ if (value != null) {
+ List<Intent> excludedIntents = policyIntent.getExcludedIntents();
+ for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
+ QName qname = getQNameValue(reader, tokens.nextToken());
+ Intent intent = policyFactory.createIntent();
+ intent.setName(qname);
+ intent.setUnresolved(true);
+ excludedIntents.add(intent);
+ }
+ }
+ }
+
+ private void resolveExcludedIntents(Intent policyIntent, ModelResolver resolver)
+ throws ContributionResolveException {
+ if (policyIntent != null) {
+ // resolve all excluded intents
+ List<Intent> excludedIntents = new ArrayList<Intent>();
+ for (Intent excludedIntent : policyIntent.getExcludedIntents()) {
+ if (excludedIntent.isUnresolved()) {
+ Intent resolvedExcludedIntent = resolver.resolveModel(Intent.class, excludedIntent);
+ if (!resolvedExcludedIntent.isUnresolved()) {
+ excludedIntents.add(resolvedExcludedIntent);
+ } else {
+ error("ExcludedIntentNotFound", resolver, excludedIntent, policyIntent);
+ return;
+ //throw new ContributionResolveException("Excluded Intent " + excludedIntent
+ //+ " not found for intent " + policyIntent);
+ }
+ } else {
+ excludedIntents.add(excludedIntent);
+ }
+ }
+ policyIntent.getExcludedIntents().clear();
+ policyIntent.getExcludedIntents().addAll(excludedIntents);
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java
new file mode 100644
index 0000000000..81ca27a085
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java
@@ -0,0 +1,487 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.xml;
+
+import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.StringTokenizer;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+
+import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl;
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.Problem;
+import org.apache.tuscany.sca.monitor.Problem.Severity;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.PolicySet;
+
+
+/**
+ * Processor for handling XML models of PolicySet definitions
+ *
+ * @version $Rev$ $Date$
+ */
+public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<PolicySet>, PolicyConstants {
+
+ private PolicyFactory policyFactory;
+ private StAXArtifactProcessor<Object> extensionProcessor;
+ private XPathFactory xpathFactory = XPathFactory.newInstance();
+ private Monitor monitor;
+
+ public PolicySetProcessor(ModelFactoryExtensionPoint modelFactories,
+ StAXArtifactProcessor<Object> extensionProcessor,
+ Monitor monitor) {
+ this.policyFactory = modelFactories.getFactory(PolicyFactory.class);
+ this.extensionProcessor = extensionProcessor;
+ this.monitor = monitor;
+ }
+
+ public PolicySetProcessor(PolicyFactory policyFactory,
+ StAXArtifactProcessor<Object> extensionProcessor,
+ Monitor monitor) {
+ this.policyFactory = policyFactory;
+ this.extensionProcessor = extensionProcessor;
+ this.monitor = monitor;
+ }
+
+ /**
+ * Report a exception.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Exception ex) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "policy-xml-validation-messages", Severity.ERROR, model, message, ex);
+ monitor.problem(problem);
+ }
+ }
+
+ /**
+ * Report a error.
+ *
+ * @param problems
+ * @param message
+ * @param model
+ */
+ private void error(String message, Object model, Object... messageParameters) {
+ if (monitor != null) {
+ Problem problem = new ProblemImpl(this.getClass().getName(), "policy-xml-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
+ monitor.problem(problem);
+ }
+ }
+
+ public PolicySet read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
+ PolicySet policySet = null;
+
+ String policySetName = reader.getAttributeValue(null, NAME);
+ String appliesTo = reader.getAttributeValue(null, APPLIES_TO);
+ if (policySetName == null || appliesTo == null) {
+ if (policySetName == null)
+ error("PolicySetNameMissing", reader);
+ if (appliesTo == null)
+ error("PolicySetAppliesToMissing", reader);
+ return policySet;
+ }
+
+ policySet = policyFactory.createPolicySet();
+ policySet.setName(new QName(policySetName));
+ String alwaysAppliesTo = reader.getAttributeValue(TUSCANY_NS, ALWAYS_APPLIES_TO);
+
+ //TODO: with 1.0 version of specs the applies to xpath is given related to the immediate
+ //parent whereas the runtime evaluates the xpath aginst the composite element. What the runtime
+ //is doing is what the future version of the specs could be tending towards. When that happens
+ //this 'if' must be deleted
+ if ( appliesTo != null && !appliesTo.startsWith("/") ) {
+ appliesTo = "//" + appliesTo;
+ }
+
+ if ( alwaysAppliesTo != null && !alwaysAppliesTo.startsWith("/") ) {
+ alwaysAppliesTo = "//" + alwaysAppliesTo;
+ }
+
+ policySet.setAppliesTo(appliesTo);
+ policySet.setAlwaysAppliesTo(alwaysAppliesTo);
+
+ XPath path = xpathFactory.newXPath();
+ path.setNamespaceContext(reader.getNamespaceContext());
+ try {
+ if (appliesTo != null) {
+ policySet.setAppliesToXPathExpression(path.compile(appliesTo));
+ }
+ if (alwaysAppliesTo != null) {
+ policySet.setAlwaysAppliesToXPathExpression(path.compile(alwaysAppliesTo));
+ }
+ } catch (XPathExpressionException e) {
+ ContributionReadException ce = new ContributionReadException(e);
+ error("ContributionReadException", policySet, ce);
+ //throw ce;
+ }
+
+ readProvidedIntents(policySet, reader);
+
+ int event = reader.getEventType();
+ QName name = null;
+ reader.next();
+ while (reader.hasNext()) {
+ event = reader.getEventType();
+ switch (event) {
+ case START_ELEMENT : {
+ name = reader.getName();
+ if ( POLICY_INTENT_MAP_QNAME.equals(name) ) {
+ Intent mappedIntent = policyFactory.createIntent();
+ String provides = reader.getAttributeValue(null, PROVIDES);
+ if (provides != null) {
+ mappedIntent.setName(getQName(reader, PROVIDES));
+ if ( policySet.getProvidedIntents().contains(mappedIntent) ) {
+ readIntentMap(reader, policySet, mappedIntent);
+ } else {
+ error("IntentNotSpecified", policySet, policySetName);
+ //throw new ContributionReadException("Intent Map provides for Intent not specified as provided by parent PolicySet - " + policySetName);
+ }
+ } else {
+ error("IntentMapProvidesMissing", reader, policySetName);
+ }
+ } else if ( POLICY_SET_REFERENCE_QNAME.equals(name) ) {
+ PolicySet referredPolicySet = policyFactory.createPolicySet();
+ String referencename = reader.getAttributeValue(null, NAME);
+ if (referencename != null) {
+ referredPolicySet.setName(getQName(reader, NAME));
+ policySet.getReferencedPolicySets().add(referredPolicySet);
+ } else {
+ error("PolicySetReferenceNameMissing", reader, policySetName);
+ }
+ } /*else if ( WS_POLICY_QNAME.equals(name) ) {
+ OMElement policyElement = loadElement(reader);
+ org.apache.neethi.Policy wsPolicy = PolicyEngine.getPolicy(policyElement);
+ policySet.getPolicies().add(wsPolicy);
+ } */ else {
+ Object extension = extensionProcessor.read(reader);
+ if ( extension != null ) {
+ policySet.getPolicies().add(extension);
+ }
+ }
+ break;
+ }
+ }
+ if ( event == END_ELEMENT ) {
+ if ( POLICY_SET_QNAME.equals(reader.getName()) ) {
+ break;
+ }
+ }
+
+ //Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
+ }
+ return policySet;
+ }
+
+
+ public void readIntentMap(XMLStreamReader reader, PolicySet policySet, Intent mappedIntent) throws ContributionReadException {
+ QName name = reader.getName();
+ Map<Intent, List<Object>> mappedPolicies = policySet.getMappedPolicies();
+ if ( POLICY_INTENT_MAP_QNAME.equals(name) ) {
+ //Intent mappedIntent = policyFactory.createIntent();
+ //mappedIntent.setName(getQName(reader, PROVIDES));
+ String defaultQualifier = getString(reader, DEFAULT);
+
+ String qualifierName = null;
+ String qualfiedIntentName = null;
+ Intent qualifiedIntent = null;
+
+ int event = reader.getEventType();
+ try {
+ reader.next();
+ while (reader.hasNext()) {
+ event = reader.getEventType();
+ switch (event) {
+ case START_ELEMENT : {
+ name = reader.getName();
+ if ( POLICY_INTENT_MAP_QUALIFIER_QNAME.equals(name)) {
+ qualifierName = getString(reader, NAME);
+ if (qualifierName != null) {
+ qualfiedIntentName = mappedIntent.getName().getLocalPart() +
+ QUALIFIER + qualifierName;
+ qualifiedIntent = policyFactory.createIntent();
+ qualifiedIntent.setName(new QName(mappedIntent.getName().getNamespaceURI(),
+ qualfiedIntentName));
+ } else {
+ error("QualifierNameMissing", reader, policySet.getName());
+ }
+ } else if ( POLICY_INTENT_MAP_QNAME.equals(name) ) {
+ QName providedIntent = getQName(reader, PROVIDES);
+ if ( qualifierName.equals(providedIntent.getLocalPart()) ) {
+ readIntentMap(reader, policySet, qualifiedIntent);
+ } else {
+ error("IntentMapDoesNotMatch", providedIntent, providedIntent, qualifierName, policySet);
+ //throw new ContributionReadException("Intent provided by IntentMap " +
+ //providedIntent + " does not match parent qualifier " + qualifierName +
+ //" in policyset - " + policySet);
+ }
+ }/* else if ( WS_POLICY_QNAME.equals(name) ) {
+ OMElement policyElement = loadElement(reader);
+ Policy wsPolicy = PolicyEngine.getPolicy(policyElement);
+ policySet.getPolicies().add(wsPolicy);
+
+ List<Object> policyList = mappedPolicies.get(qualifiedIntent);
+ if ( policyList == null ) {
+ policyList = new ArrayList<Object>();
+ mappedPolicies.put(qualifiedIntent, policyList);
+
+ if (qualifierName.equals(defaultQualifier)) {
+ mappedPolicies.put(mappedIntent, policyList);
+ }
+ }
+ policyList.add((Policy)wsPolicy);
+ }*/ else {
+ Object extension = extensionProcessor.read(reader);
+ if ( extension != null && qualifiedIntent != null) {
+ List<Object> policyList = mappedPolicies.get(qualifiedIntent);
+ if ( policyList == null ) {
+ policyList = new ArrayList<Object>();
+ mappedPolicies.put(qualifiedIntent, policyList);
+
+ if (qualifierName.equals(defaultQualifier)) {
+ mappedPolicies.put(mappedIntent, policyList);
+ }
+ }
+ policyList.add(extension);
+ }
+ }
+ break;
+ }
+ case END_ELEMENT : {
+ if ( POLICY_INTENT_MAP_QNAME.equals(reader.getName()) ) {
+ if ( defaultQualifier != null ) {
+ String qualifiedIntentName = mappedIntent.getName().getLocalPart() + QUALIFIER + defaultQualifier;
+ Intent defaultQualifiedIntent = policyFactory.createIntent();
+ defaultQualifiedIntent.setName(new QName(mappedIntent.getName().getNamespaceURI(),
+ qualifiedIntentName));
+ List<Object> policyList = mappedPolicies.get(defaultQualifiedIntent);
+ if ( policyList != null ) {
+ mappedPolicies.put(mappedIntent, policyList);
+ } else {
+ error("UnableToMapPolicies", mappedPolicies, mappedIntent, policySet);
+ //throw new ContributionReadException("Unable to map policies for default qualifier in IntentMap for - " +
+ //mappedIntent + " in policy set - " + policySet);
+ }
+ defaultQualifier = null;
+ }
+ }
+ break;
+ }
+ }
+ if ( event == END_ELEMENT && POLICY_INTENT_MAP_QNAME.equals(reader.getName()) ) {
+ break;
+ }
+ //Read the next element
+ if (reader.hasNext()) {
+ reader.next();
+ }
+ }
+ } catch (XMLStreamException e) {
+ ContributionReadException ce = new ContributionReadException(e);
+ error("ContributionReadException", reader, ce);
+ throw ce;
+ }
+ }
+ }
+
+ public void write(PolicySet policySet, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException {
+
+ // Write an <sca:policySet>
+ writer.writeStartElement(SCA10_NS, POLICY_SET);
+ writer.writeNamespace(policySet.getName().getPrefix(), policySet.getName().getNamespaceURI());
+ writer.writeAttribute(NAME,
+ policySet.getName().getPrefix() + COLON + policySet.getName().getLocalPart());
+ writer.writeAttribute(APPLIES_TO, policySet.getAppliesTo());
+ writer.writeAttribute(TUSCANY_NS, ALWAYS_APPLIES_TO, policySet.getAlwaysAppliesTo());
+
+ writeProvidedIntents(policySet, writer);
+
+ writer.writeEndElement();
+ }
+
+ private void readProvidedIntents(PolicySet policySet, XMLStreamReader reader) {
+ String value = reader.getAttributeValue(null, PROVIDES);
+ if (value != null) {
+ List<Intent> providedIntents = policySet.getProvidedIntents();
+ for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
+ QName qname = getQNameValue(reader, tokens.nextToken());
+ Intent intent = policyFactory.createIntent();
+ intent.setName(qname);
+ providedIntents.add(intent);
+ }
+ }
+ }
+
+ private void writeProvidedIntents(PolicySet policySet, XMLStreamWriter writer) throws XMLStreamException {
+ if (policySet.getProvidedIntents() != null &&
+ policySet.getProvidedIntents().size() > 0) {
+ StringBuffer sb = new StringBuffer();
+ for (Intent providedIntents : policySet.getProvidedIntents()) {
+ sb.append(providedIntents.getName());
+ sb.append(" ");
+ }
+ writer.writeAttribute(PolicyConstants.PROVIDES, sb.toString());
+ }
+ }
+
+ private void resolvePolicies(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException {
+ boolean unresolved = false;
+ if (policySet != null) {
+ for ( Object o : policySet.getPolicies() ) {
+ extensionProcessor.resolve(o, resolver);
+ /*if ( o instanceof Policy && ((Policy)o).isUnresolved() ) {
+ unresolved = true;
+ }*/
+ }
+ policySet.setUnresolved(unresolved);
+ }
+ }
+
+
+
+ public QName getArtifactType() {
+ return POLICY_SET_QNAME;
+ }
+
+ public Class<PolicySet> getModelType() {
+ return PolicySet.class;
+ }
+
+ private void resolveProvidedIntents(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException {
+ if (policySet != null) {
+ //resolve all provided intents
+ List<Intent> providedIntents = new ArrayList<Intent>();
+ for (Intent providedIntent : policySet.getProvidedIntents()) {
+ if (providedIntent.isUnresolved()) {
+ Intent resolvedProvidedIntent = resolver.resolveModel(Intent.class, providedIntent);
+ if (!resolvedProvidedIntent.isUnresolved()) {
+ providedIntents.add(resolvedProvidedIntent);
+ } else {
+ error("ProvidedIntentNotFound", policySet, providedIntent, policySet);
+ return;
+ //throw new ContributionResolveException("Provided Intent - " + providedIntent
+ //+ " not found for PolicySet " + policySet);
+ }
+ } else {
+ providedIntents.add(providedIntent);
+ }
+ }
+ policySet.getProvidedIntents().clear();
+ policySet.getProvidedIntents().addAll(providedIntents);
+ }
+ }
+
+ private void resolveIntentsInMappedPolicies(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException {
+ Map<Intent, List<Object>> mappedPolicies = new Hashtable<Intent, List<Object>>();
+ for (Map.Entry<Intent, List<Object>> entry : policySet.getMappedPolicies().entrySet()) {
+ Intent mappedIntent = entry.getKey();
+ if (mappedIntent.isUnresolved()) {
+ Intent resolvedMappedIntent = resolver.resolveModel(Intent.class, mappedIntent);
+ if (!resolvedMappedIntent.isUnresolved()) {
+ mappedPolicies.put(resolvedMappedIntent, entry.getValue());
+ } else {
+ error("MappedIntentNotFound", policySet, mappedIntent, policySet);
+ return;
+ //throw new ContributionResolveException("Mapped Intent - " + mappedIntent
+ //+ " not found for PolicySet " + policySet);
+ }
+ } else {
+ mappedPolicies.put(mappedIntent, entry.getValue());
+ }
+ }
+
+ policySet.getMappedPolicies().clear();
+ policySet.getMappedPolicies().putAll(mappedPolicies);
+ }
+
+ private void resolveReferredPolicySets(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException {
+
+ List<PolicySet> referredPolicySets = new ArrayList<PolicySet>();
+ for (PolicySet referredPolicySet : policySet.getReferencedPolicySets()) {
+ if (referredPolicySet.isUnresolved()) {
+ PolicySet resolvedReferredPolicySet = resolver.resolveModel(PolicySet.class, referredPolicySet);
+ if (!resolvedReferredPolicySet.isUnresolved()) {
+ referredPolicySets.add(resolvedReferredPolicySet);
+ } else {
+ error("ReferredPolicySetNotFound", policySet, referredPolicySet, policySet);
+ return;
+ //throw new ContributionResolveException("Referred PolicySet - " + referredPolicySet
+ //+ "not found for PolicySet - " + policySet);
+ }
+ } else {
+ referredPolicySets.add(referredPolicySet);
+ }
+ }
+ policySet.getReferencedPolicySets().clear();
+ policySet.getReferencedPolicySets().addAll(referredPolicySets);
+ }
+
+ private void includeReferredPolicySets(PolicySet policySet, PolicySet referredPolicySet) {
+ for (PolicySet furtherReferredPolicySet : referredPolicySet.getReferencedPolicySets()) {
+ includeReferredPolicySets(referredPolicySet, furtherReferredPolicySet);
+ }
+ policySet.getPolicies().addAll(referredPolicySet.getPolicies());
+ policySet.getMappedPolicies().putAll(referredPolicySet.getMappedPolicies());
+ }
+
+ public void resolve(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException {
+ resolveProvidedIntents(policySet, resolver);
+ resolveIntentsInMappedPolicies(policySet, resolver);
+ resolveReferredPolicySets(policySet, resolver);
+
+ for (PolicySet referredPolicySet : policySet.getReferencedPolicySets()) {
+ includeReferredPolicySets(policySet, referredPolicySet);
+ }
+
+ if ( policySet.isUnresolved() ) {
+ //resolve the policy attachments
+ resolvePolicies(policySet, resolver);
+
+ /*if ( !policySet.isUnresolved() ) {
+ resolver.addModel(policySet);
+ }*/
+ }
+ }
+ }
diff --git a/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ProfileIntentProcessor.java b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ProfileIntentProcessor.java
new file mode 100644
index 0000000000..7c205292b0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ProfileIntentProcessor.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.xml;
+
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.ProfileIntent;
+
+/**
+ * Processor for handling XML models of PolicyIntent definitions that are ProfileIntents
+ *
+ * @version $Rev$ $Date$
+ */
+public class ProfileIntentProcessor extends PolicyIntentProcessor<ProfileIntent> {
+
+ public ProfileIntentProcessor(PolicyFactory policyFactory, Monitor monitor) {
+ super(policyFactory, monitor);
+ }
+
+ public ProfileIntentProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
+ super(modelFactories, monitor);
+ }
+
+ public Class<ProfileIntent> getModelType() {
+ return ProfileIntent.class;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/QualifiedIntentProcessor.java b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/QualifiedIntentProcessor.java
new file mode 100644
index 0000000000..abe80e2a54
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/QualifiedIntentProcessor.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.xml;
+
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.QualifiedIntent;
+
+/**
+ * Processor for handling XML models of PolicyIntent definitions that are QualifiedIntents
+ *
+ * @version $Rev$ $Date$
+ */
+public class QualifiedIntentProcessor extends PolicyIntentProcessor<QualifiedIntent> {
+
+ public QualifiedIntentProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
+ super(modelFactories, monitor);
+ }
+
+ public QualifiedIntentProcessor(PolicyFactory policyFactory, Monitor monitor) {
+ super(policyFactory, monitor);
+ }
+
+ public Class<QualifiedIntent> getModelType() {
+ return QualifiedIntent.class;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SimpleIntentProcessor.java b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SimpleIntentProcessor.java
new file mode 100644
index 0000000000..73795349c1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SimpleIntentProcessor.java
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.xml;
+
+import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+
+/**
+ * Processor for handling XML models of PolicyIntent definitions
+ *
+ * @version $Rev$ $Date$
+ */
+public class SimpleIntentProcessor extends PolicyIntentProcessor<Intent> {
+
+ public SimpleIntentProcessor(PolicyFactory policyFactory, Monitor monitor) {
+ super(policyFactory, monitor);
+ }
+
+ public SimpleIntentProcessor(ModelFactoryExtensionPoint modelFactories, Monitor monitor) {
+ super(modelFactories, monitor);
+ }
+
+ public Class<Intent> getModelType() {
+ return Intent.class;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
new file mode 100644
index 0000000000..c41a0cd01f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor
@@ -0,0 +1,24 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Implementation class for the artifact processor extension
+org.apache.tuscany.sca.policy.xml.BindingTypeProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#bindingType,model=org.apache.tuscany.sca.policy.IntentAttachPointType
+org.apache.tuscany.sca.policy.xml.ImplementationTypeProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#implementationType,model=org.apache.tuscany.sca.policy.IntentAttachPointType
+org.apache.tuscany.sca.policy.xml.SimpleIntentProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#intent,model=org.apache.tuscany.sca.policy.Intent
+org.apache.tuscany.sca.policy.xml.PolicySetProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#policySet,model=org.apache.tuscany.sca.policy.PolicySet
+org.apache.tuscany.sca.policy.xml.ProfileIntentProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#intent,model=org.apache.tuscany.sca.policy.ProfileIntent
+org.apache.tuscany.sca.policy.xml.QualifiedIntentProcessor;qname=http://www.osoa.org/xmlns/sca/1.0#intent,model=org.apache.tuscany.sca.policy.QualifiedIntent
diff --git a/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/resources/policy-xml-validation-messages.properties b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/resources/policy-xml-validation-messages.properties
new file mode 100644
index 0000000000..40107bb11e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/main/resources/policy-xml-validation-messages.properties
@@ -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.
+#
+#
+ReferredPolicySetNotFound = Referred PolicySet - {0} not found for PolicySet - {1}
+MappedIntentNotFound = Mapped Intent - {0} not found for PolicySet {1}
+ProvidedIntentNotFound = Provided Intent - {0} not found for PolicySet {1}
+UnableToMapPolicies = Unable to map policies for default qualifier in IntentMap for - {0} in policy set - {1}
+IntentMapDoesNotMatch = Intent provided by IntentMap {0} does not match parent qualifier {1} in policyset - {2}
+IntentNotSpecified = Intent Map provides for Intent not specified as provided by parent PolicySet - {0}
+ContrainsAttributeMissing = Constrains attribute missing from Policy Intent Definition {0}
+RequiredIntentNotFound = Required Intent - {0} not found for ProfileIntent {1}
+QualifiableIntentNotFound = Qualifiable Intent - {0} not found for QualifiedIntent {1}
+ErrorInPolicyIntentDefinition = Error in PolicyIntent Definition - {0} {1}
+ExcludedIntentNotFound = Excluded Intent {0} not found for intent {1}
+UnrecognizedIntentAttachPointType = Unrecognized IntentAttachPointType - {0}
+RequiredAttributeMissing = Required attribute {0} missing from BindingType Definition
+AlwaysProvidedIntentNotFound = Always Provided Intent - {0} not found for ExtensionType {1}
+MayProvideIntentNotFound = May Provide Intent - {0} not found for ExtensionType {1}
+ContributionReadException = ContributionReadException occurred due to: {0}
+CyclicReferenceFound = Cyclic reference detected in required attributes of ProfileIntents {0} and {1}
+IntentNameMissing = Required attribute "name" missing for Intent Definition
+PolicySetReferenceNameMissing = Required attribute "name" missing for PolicySetReference in PolicySet : {0}
+PolicySetNameMissing = Required attribute "name" missing for PolicySet Definition
+PolicySetAppliesToMissing = Required attribute "appliesTo" missing for PolicySet Definition
+IntentMapProvidesMissing = Required attribute "provides" missing for IntentMap in PolicySet : {0}
+QualifierNameMissing = Required attribute "name" missing for qualifier definition in PolicySet : {0}
+
diff --git a/sca-java-1.x/branches/sca-android/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java
new file mode 100644
index 0000000000..c9fad18157
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/ReadDocumentTestCase.java
@@ -0,0 +1,280 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.xml;
+
+import static javax.xml.stream.XMLStreamConstants.START_ELEMENT;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint;
+import org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry;
+import org.apache.tuscany.sca.core.UtilityExtensionPoint;
+import org.apache.tuscany.sca.monitor.MonitorFactory;
+import org.apache.tuscany.sca.monitor.Monitor;
+import org.apache.tuscany.sca.monitor.impl.DefaultMonitorFactoryImpl;
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.ProfileIntent;
+import org.apache.tuscany.sca.policy.QualifiedIntent;
+import org.apache.tuscany.sca.policy.impl.BindingTypeImpl;
+import org.apache.tuscany.sca.policy.impl.ImplementationTypeImpl;
+
+/**
+ * Test reading SCA XML assembly documents.
+ *
+ * @version $Rev: 551296 $ $Date: 2007-06-28 01:18:35 +0530 (Thu, 28 Jun 2007) $
+ */
+public class ReadDocumentTestCase extends TestCase {
+
+ private ModelResolver resolver;
+ private StAXArtifactProcessor<Object> staxProcessor;
+ private Monitor monitor;
+
+ private static final QName elementToProcess = new QName("http://www.osoa.org/xmlns/sca/1.0", "implementationType");
+
+ private Map<QName, Intent> intentTable = new Hashtable<QName, Intent>();
+ private Map<QName, PolicySet> policySetTable = new Hashtable<QName, PolicySet>();
+ private Map<QName, IntentAttachPointType> bindingTypesTable = new Hashtable<QName, IntentAttachPointType>();
+ private Map<QName, IntentAttachPointType> implTypesTable = new Hashtable<QName, IntentAttachPointType>();
+ private static final String scaNamespace = "http://www.osoa.org/xmlns/sca/1.0";
+ private static final String namespace = "http://test";
+
+ private static final QName confidentiality = new QName(namespace, "confidentiality");
+ private static final QName integrity = new QName(namespace, "integrity");
+ private static final QName messageProtection = new QName(namespace, "messageProtection");
+ private static final QName confidentiality_transport = new QName(namespace, "confidentiality.transport");
+ private static final QName confidentiality_message = new QName(namespace, "confidentiality.message");
+ private static final QName secureReliablePolicy = new QName(namespace, "SecureReliablePolicy");
+ private static final QName secureMessagingPolicies = new QName(namespace, "SecureMessagingPolicies");
+ private static final QName securityPolicy = new QName(namespace, "SecurityPolicy");
+ private static final QName basicAuthMsgProtSecurity = new QName(namespace, "BasicAuthMsgProtSecurity");
+ private static final QName wsBinding = new QName(scaNamespace, "binding.ws");
+ private static final QName javaImpl = new QName(scaNamespace, "implementation.java");
+
+
+ @Override
+ public void setUp() throws Exception {
+ DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry();
+ resolver = new DefaultModelResolver();
+ XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+ // Create a monitor
+ UtilityExtensionPoint utilities = extensionPoints.getExtensionPoint(UtilityExtensionPoint.class);
+ MonitorFactory monitorFactory = new DefaultMonitorFactoryImpl();
+ if (monitorFactory != null) {
+ monitor = monitorFactory.createMonitor();
+ utilities.addUtility(monitorFactory);
+ }
+ StAXArtifactProcessorExtensionPoint staxProcessors = extensionPoints.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
+ staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null, monitor);
+ staxProcessors.addArtifactProcessor(new TestPolicyProcessor());
+
+ URL url = getClass().getResource("test_definitions.xml");
+ InputStream urlStream = url.openStream();
+ XMLStreamReader reader = inputFactory.createXMLStreamReader(urlStream);
+ reader.next();
+
+ //position on the right element qname to get processed
+ while(reader.hasNext()) {
+ reader.next();
+ int event = reader.getEventType();
+ if(event == START_ELEMENT && reader.getName().equals(elementToProcess)) {
+ break;
+ }
+ }
+ while ( true ) {
+ int event = reader.getEventType();
+ switch (event) {
+ case START_ELEMENT: {
+ Object artifact = staxProcessor.read(reader);
+ if ( artifact instanceof PolicySet ) {
+ PolicySet policySet = (PolicySet)artifact;
+ policySet.setName(new QName(namespace, policySet.getName().getLocalPart()));
+ policySetTable.put(policySet.getName(), policySet);
+ } else if ( artifact instanceof Intent ) {
+ Intent intent = (Intent)artifact;
+ intent.setName(new QName(namespace, intent.getName().getLocalPart()));
+ if ( intent instanceof QualifiedIntent ) {
+ ((QualifiedIntent)intent).getQualifiableIntent().
+ setName(new QName(namespace,
+ ((QualifiedIntent)intent).getQualifiableIntent().getName().getLocalPart()));
+ }
+ intentTable.put(intent.getName(), intent);
+ } else if ( artifact instanceof BindingTypeImpl ) {
+ IntentAttachPointType bindingType = (IntentAttachPointType)artifact;
+ bindingTypesTable.put(bindingType.getName(), bindingType);
+ } else if ( artifact instanceof ImplementationTypeImpl ) {
+ IntentAttachPointType implType = (IntentAttachPointType)artifact;
+ implTypesTable.put(implType.getName(), implType);
+ }
+
+ if ( artifact != null ) {
+ resolver.addModel(artifact);
+ }
+
+ break;
+ }
+ }
+ if ( reader.hasNext() ) {
+ reader.next();
+ } else {
+ break;
+ }
+ }
+ urlStream.close();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ }
+
+ public void testReadSCADefinitions() throws Exception {
+ assertNotNull(intentTable.get(confidentiality));
+ assertNotNull(intentTable.get(messageProtection));
+ assertNotNull(intentTable.get(confidentiality_transport));
+ assertTrue(intentTable.get(confidentiality).getDescription().length() > 0 );
+
+ assertNotNull(policySetTable.get(secureReliablePolicy));
+ assertTrue(policySetTable.get(secureReliablePolicy).getProvidedIntents().size() == 2);
+ assertTrue(policySetTable.get(secureReliablePolicy).getPolicies().size() == 2);
+
+ assertNotNull(policySetTable.get(secureMessagingPolicies));
+ assertEquals(policySetTable.get(secureMessagingPolicies).getMappedPolicies().size(), 3);
+
+ assertEquals(bindingTypesTable.size(), 1);
+ assertNotNull(bindingTypesTable.get(wsBinding));
+ assertEquals(implTypesTable.size(), 1);
+ assertNotNull(implTypesTable.get(javaImpl));
+ }
+
+ public void testResolution() throws Exception {
+ assertTrue(intentTable.get(messageProtection) instanceof ProfileIntent);
+ ProfileIntent profileIntent = (ProfileIntent)intentTable.get(new QName(namespace, "messageProtection"));
+ assertNull(profileIntent.getRequiredIntents().get(0).getDescription());
+
+ QName confidentiality_transport = new QName(namespace, "confidentiality.transport");
+ assertTrue(intentTable.get(confidentiality_transport) instanceof QualifiedIntent);
+ QualifiedIntent qualifiedIntent = (QualifiedIntent)intentTable.get(new QName(namespace, "confidentiality.transport"));
+ assertNull(qualifiedIntent.getQualifiableIntent().getDescription());
+
+ PolicySet secureReliablePolicySet = policySetTable.get(secureReliablePolicy);
+ PolicySet secureMessagingPolicySet = policySetTable.get(secureMessagingPolicies);
+ PolicySet securityPolicySet = policySetTable.get(securityPolicy);
+
+ assertEquals(secureReliablePolicySet.getProvidedIntents().get(1).getName(), integrity);
+ assertNull(secureReliablePolicySet.getProvidedIntents().get(1).getDescription());
+ assertTrue(secureMessagingPolicySet.isUnresolved());
+ assertEquals(securityPolicySet.getMappedPolicies().size(), 5);
+
+ //testing to ensure that inclusion of referred policy sets has not happened
+ PolicySet basicAuthMsgProtSecurityPolicySet = policySetTable.get(basicAuthMsgProtSecurity);
+ assertTrue(basicAuthMsgProtSecurityPolicySet.getPolicies().isEmpty());
+ assertTrue(basicAuthMsgProtSecurityPolicySet.getMappedPolicies().isEmpty());
+
+ IntentAttachPointType wsBindingType = bindingTypesTable.get(wsBinding);
+ assertNull(wsBindingType.getAlwaysProvidedIntents().get(0).getDescription());
+ assertNull(wsBindingType.getMayProvideIntents().get(0).getDescription());
+
+ IntentAttachPointType javaImplType = implTypesTable.get(javaImpl);
+ assertNull(javaImplType.getAlwaysProvidedIntents().get(0).getDescription());
+ assertNull(javaImplType.getMayProvideIntents().get(0).getDescription());
+
+ List<Intent> simpleIntents = new ArrayList<Intent>();
+ List<ProfileIntent> profileIntents = new ArrayList<ProfileIntent>();
+ List<QualifiedIntent> qualifiedIntents = new ArrayList<QualifiedIntent>();
+
+ for (Intent intent : intentTable.values()) {
+ if (intent instanceof ProfileIntent)
+ profileIntents.add((ProfileIntent)intent);
+ else if (intent instanceof QualifiedIntent)
+ qualifiedIntents.add((QualifiedIntent)intent);
+ else simpleIntents.add(intent);
+ }
+
+ for (Intent intent : simpleIntents)
+ staxProcessor.resolve(intent, resolver);
+
+ for (ProfileIntent intent : profileIntents)
+ staxProcessor.resolve(intent, resolver);
+
+ for (QualifiedIntent intent : qualifiedIntents)
+ staxProcessor.resolve(intent, resolver);
+
+ for ( PolicySet policySet : policySetTable.values() ) {
+ if (policySet.getReferencedPolicySets().isEmpty())
+ staxProcessor.resolve(policySet, resolver);
+ }
+
+ for ( PolicySet policySet : policySetTable.values() ) {
+ if (!policySet.getReferencedPolicySets().isEmpty())
+ staxProcessor.resolve(policySet, resolver);
+ }
+
+ for ( IntentAttachPointType bindingType : bindingTypesTable.values() ) {
+ staxProcessor.resolve(bindingType, resolver);
+ }
+
+ for ( IntentAttachPointType implType : implTypesTable.values() ) {
+ staxProcessor.resolve(implType, resolver);
+ }
+
+ //testing if policy intents have been linked have property been linked up
+ assertNotNull(profileIntent.getRequiredIntents().get(0).getDescription());
+ assertNotNull(qualifiedIntent.getQualifiableIntent().getDescription());
+ assertEquals(secureReliablePolicySet.getProvidedIntents().get(1).getName(), integrity);
+ assertNotNull(secureReliablePolicySet.getProvidedIntents().get(1).getDescription());
+
+ //testing if policysets have been properly linked up with intents
+ assertFalse(secureMessagingPolicySet.isUnresolved());
+ assertNotNull(secureMessagingPolicySet.getMappedPolicies().get(intentTable.get(confidentiality)));
+ assertNotNull(secureMessagingPolicySet.getMappedPolicies().get(intentTable.get(confidentiality_transport)));
+
+ //testing if intent maps have been properly mapped to policies
+ assertFalse(securityPolicySet.isUnresolved());
+ assertNotNull(securityPolicySet.getMappedPolicies().get(intentTable.get(confidentiality)));
+ assertNotNull(securityPolicySet.getMappedPolicies().get(intentTable.get(confidentiality_message)));
+
+ //testing for inclusion of referred policysets
+ assertFalse(basicAuthMsgProtSecurityPolicySet.getPolicies().isEmpty());
+ assertFalse(basicAuthMsgProtSecurityPolicySet.getMappedPolicies().isEmpty());
+ assertNotNull(basicAuthMsgProtSecurityPolicySet.getMappedPolicies().get(intentTable.get(confidentiality_transport)));
+
+ assertNotNull(wsBindingType.getAlwaysProvidedIntents().get(0).getDescription());
+ assertNotNull(wsBindingType.getMayProvideIntents().get(0).getDescription());
+
+ assertNotNull(javaImplType.getAlwaysProvidedIntents().get(0).getDescription());
+ assertNotNull(javaImplType.getMayProvideIntents().get(0).getDescription());
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/TestPolicyProcessor.java b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/TestPolicyProcessor.java
new file mode 100644
index 0000000000..ce5b204787
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/test/java/org/apache/tuscany/sca/policy/xml/TestPolicyProcessor.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy.xml;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.stream.XMLStreamWriter;
+
+import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
+import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
+import org.apache.tuscany.sca.contribution.service.ContributionReadException;
+import org.apache.tuscany.sca.contribution.service.ContributionResolveException;
+import org.apache.tuscany.sca.contribution.service.ContributionWriteException;
+import org.apache.tuscany.sca.policy.Policy;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class TestPolicyProcessor implements StAXArtifactProcessor<Policy> {
+
+ public QName getArtifactType() {
+ return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment");
+ }
+
+ public Policy read(XMLStreamReader arg0) throws ContributionReadException, XMLStreamException {
+ return new MockPolicyImplOne();
+ }
+
+ public void write(Policy arg0, XMLStreamWriter arg1) throws ContributionWriteException,
+ XMLStreamException {
+ }
+
+ public Class<Policy> getModelType() {
+ // TODO Auto-generated method stub
+ return Policy.class;
+ }
+
+ public void resolve(Policy arg0, ModelResolver arg1) throws ContributionResolveException {
+
+ }
+
+
+ public class MockPolicyImplOne implements Policy {
+ public QName getSchemaName() {
+ return new QName("http://schemas.xmlsoap.org/ws/2004/09/policy", "PolicyAttachment");
+ }
+
+ public boolean isUnresolved() {
+ return false;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ }
+
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/test_definitions.xml b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/test_definitions.xml
new file mode 100644
index 0000000000..b51a6fba98
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy-xml/src/test/resources/org/apache/tuscany/sca/policy/xml/test_definitions.xml
@@ -0,0 +1,255 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT 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 xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ targetNamespace="http://test"
+ xmlns:test="http://test"
+ xmlns:sca="http://www.osoa.org/xmlns/sca/1.0">
+
+<!-- Extension Types Metadata -->
+<implementationType type="sca:implementation.java" alwaysProvides="test:logging"
+ mayProvide="test:tracing"/>
+<bindingType type="sca:binding.ws" alwaysProvides="test:confidentiality"
+ mayProvide="test:integrity"/>
+
+<!-- Intents and Policysets to assume targetnamespace -->
+<intent name="TestIntentOne"
+ constrains="sca:binding">
+ <description>
+ Test Intent
+ </description>
+ </intent>
+
+ <intent name="TestIntentTwo"
+ constrains="sca:binding"
+ requires="test:TestIntentOne">
+ <description>
+ Protect messages from unauthorized reading or modification
+ </description>
+ </intent>
+
+ <policySet name="TestPolicySetOne"
+ provides="test:TestIntentOne"
+ appliesTo="sca:binding.ws"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for
+ "basic authentication" -->
+ </wsp:PolicyAttachment>
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for
+ "reliability" -->
+ </wsp:PolicyAttachment>
+ </policySet>
+
+
+ <!-- qualified intents -->
+ <intent name="confidentiality.transport" />
+ <intent name="confidentiality.message" />
+ <intent name="confidentiality.message.whole" />
+ <intent name="confidentiality.message.body" />
+
+ <!-- POLICY SETS -->
+ <policySet name="SecureReliablePolicy"
+ provides="test:confidentiality.transport test:integrity"
+ appliesTo="sca:binding.ws"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for
+ "basic authentication" -->
+ </wsp:PolicyAttachment>
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for
+ "reliability" -->
+ </wsp:PolicyAttachment>
+ </policySet>
+
+ <policySet name="SecureMessagingPolicies"
+ provides="test:confidentiality"
+ appliesTo="binding.ws"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <intentMap provides="test:confidentiality" default="transport">
+ <qualifier name="transport">
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for "transport" alternative -->
+ </wsp:PolicyAttachment>
+ <wsp:PolicyAttachment>...</wsp:PolicyAttachment>
+ </qualifier>
+ <qualifier name="message">
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for "message" alternative" -->
+ </wsp:PolicyAttachment>
+ </qualifier>
+ </intentMap>
+</policySet>
+
+<policySet name="SecurityPolicy"
+ provides="test:confidentiality"
+ appliesTo="binding.ws"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" >
+ <intentMap provides="test:confidentiality" default="message">
+ <qualifier name="message">
+ <intentMap provides="message" default="whole">
+ <qualifier name="body">
+ <wsp:PolicyAttachment>
+ <!-- policy attachment for body encryption -->
+ </wsp:PolicyAttachment>
+ </qualifier>
+ <qualifier name="whole">
+ <wsp:PolicyAttachment>
+ <!-- policy attachment for whole message encryption -->
+ </wsp:PolicyAttachment>
+ </qualifier>
+ </intentMap>
+ </qualifier>
+ <qualifier name="transport">
+ <wsp:PolicyAttachment>
+ <!-- policy attachment for transport encryption -->
+ </wsp:PolicyAttachment>
+ </qualifier>
+ </intentMap>
+</policySet>
+
+<policySet name="BasicAuthMsgProtSecurity"
+ provides="test:authentication test:confidentiality"
+ appliesTo="binding.ws"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0">
+ <policySetReference name="test:AuthenticationPolicies"/>
+ <policySetReference name="test:ConfidentialityPolicies"/>
+</policySet>
+
+<policySet name="AuthenticationPolicies"
+ provides="test:authentication"
+ appliesTo="binding.ws"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for "basic
+ authentication" -->
+ </wsp:PolicyAttachment>
+</policySet>
+
+<policySet name="ConfidentialityPolicies"
+ provides="test:confidentiality"
+ appliesTo="binding.ws"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <intentMap provides="test:confidentiality" default="transport">
+ <qualifier name="transport">
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for "transport"
+ alternative -->
+ </wsp:PolicyAttachment>
+ <wsp:PolicyAttachment>...</wsp:PolicyAttachment>
+ </qualifier>
+ <qualifier name="message">
+ <wsp:PolicyAttachment>
+ <!-- policy expression and policy subject for "message"
+ alternative" -->...
+ </wsp:PolicyAttachment>
+ </qualifier>
+ </intentMap>
+</policySet>
+
+<policySet name="SecureWSPolicy"
+ provides="test:confidentiality"
+ appliesTo="sca:binding.ws"
+ xmlns="http://www.osoa.org/xmlns/sca/1.0"
+ xmlns:sp="http://schemas.xmlsoap.org/ws/2002/12/secext"
+ xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy">
+ <wsp:Policy>
+ <wsp:ExactlyOne>
+ <wsp:All>
+ <sp:SecurityToken>
+ <sp:TokenType>sp:X509v3</sp:TokenType>
+ </sp:SecurityToken>
+ <sp:UsernameToken />
+ <sp:SignedParts />
+ <sp:EncryptedParts>
+ <sp:Body />
+ </sp:EncryptedParts>
+ <sp:TransportBinding>
+ <sp:IncludeTimeStamp />
+ </sp:TransportBinding>
+ </wsp:All>
+ </wsp:ExactlyOne>
+ </wsp:Policy>
+ </policySet>
+
+<!-- profile intent -->
+ <intent name="reliableMessageProtection"
+ constrains="sca:binding"
+ requires="test:messageProtection">
+ <description>
+ Protect messages from unauthorized reading or modification
+ </description>
+ </intent>
+
+ <intent name="messageProtection"
+ constrains="sca:binding"
+ requires="test:confidentiality test:integrity">
+ <description>
+ Protect messages from unauthorized reading or modification
+ </description>
+ </intent>
+
+<!-- simple intent -->
+ <intent name="confidentiality"
+ constrains="sca:binding">
+ <description>
+ Communitcation thro this binding must prevent
+ unauthorized users from reading the messages.
+ </description>
+ </intent>
+
+ <intent name="integrity"
+ constrains="sca:binding">
+ <description>
+ Communitcation thro this binding must prevent
+ unauthorized modification of the messages.
+ </description>
+ </intent>
+
+ <intent name="authentication"
+ constrains="sca:binding">
+ <description>
+ Communitcation thro this binding required
+ Authentication.
+ </description>
+ </intent>
+
+ <intent name="logging"
+ constrains="sca:implementation">
+ <description>
+ All messages to and from this implementation must be logged
+ </description>
+ </intent>
+
+ <intent name="tracing"
+ constrains="sca:implementation.java">
+ <description>
+ Need to figure out some description for this
+ </description>
+ </intent>
+
+</definitions> \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/LICENSE b/sca-java-1.x/branches/sca-android/modules/policy/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/META-INF/README b/sca-java-1.x/branches/sca-android/modules/policy/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/NOTICE b/sca-java-1.x/branches/sca-android/modules/policy/NOTICE
new file mode 100644
index 0000000000..b3e4797aaa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/NOTICE
@@ -0,0 +1,5 @@
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/pom.xml b/sca-java-1.x/branches/sca-android/modules/policy/pom.xml
new file mode 100644
index 0000000000..2c76db7f89
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/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>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-policy</artifactId>
+ <name>Apache Tuscany SCA Policy Model</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-extensibility</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>${tuscany.version}</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.policy</Bundle-SymbolicName>
+ <Bundle-Description>${pom.name}</Bundle-Description>
+ <Export-Package>org.apache.tuscany.sca.policy*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/DefaultIntentAttachPointTypeFactory.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/DefaultIntentAttachPointTypeFactory.java
new file mode 100644
index 0000000000..6ca4fe72ec
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/DefaultIntentAttachPointTypeFactory.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy;
+
+import org.apache.tuscany.sca.policy.impl.IntentAttachPointTypeFactoryImpl;
+
+/**
+ * Default implementation for IntentAttachPointTypeFactory
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultIntentAttachPointTypeFactory extends IntentAttachPointTypeFactoryImpl implements IntentAttachPointTypeFactory{
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/DefaultPolicyFactory.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/DefaultPolicyFactory.java
new file mode 100644
index 0000000000..2da41675a1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/DefaultPolicyFactory.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy;
+
+import org.apache.tuscany.sca.policy.impl.PolicyFactoryImpl;
+
+/**
+ * A factory for the policy model.
+ *
+ * @version $Rev$ $Date$
+ */
+public class DefaultPolicyFactory extends PolicyFactoryImpl implements PolicyFactory {
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Intent.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Intent.java
new file mode 100644
index 0000000000..22f328f643
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Intent.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Represents a policy intent. See the Policy Framework specification for a
+ * description of this element.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Intent {
+
+ /**
+ * Returns the intent name.
+ *
+ * @return the intent name
+ */
+ QName getName();
+
+ /**
+ * Sets the intent name
+ *
+ * @param name the intent name
+ */
+ void setName(QName name);
+
+ /**
+ * Get the intent domain (the root intent name before any qualifiers)
+ * @return the domain
+ */
+ String getDomain();
+
+ /**
+ * Get the intent qualifiers
+ * @return the domain
+ */
+ String[] getQualifiedNames();
+
+ /**
+ * Returns the list of operations that this intent applies to.
+ *
+ * @return
+ */
+ //List<Operation> getOperations();
+
+ /**
+ * Returns the list of SCA constructs that this intent is meant to
+ * configure.
+ *
+ * @return the list of SCA constructs that this intent is meant to configure
+ */
+ List<QName> getConstrains();
+
+ /**
+ * Returns the list of intents which are mutually exclusive with this intent.
+ *
+ * @return the list of mutually exclusive intents.
+ */
+ List<Intent> getExcludedIntents();
+
+ /**
+ * Returns the list of children qualified intents.
+ *
+ * @return the list of children qualified intents.
+ */
+ List<Intent> getQualifiedIntents();
+
+ /**
+ * Returns the intent description.
+ *
+ * @return the intent description
+ */
+ String getDescription();
+
+ /**
+ * Sets the intent description.
+ *
+ * @param description the intent description
+ */
+ void setDescription(String description);
+
+ /**
+ * Returns true if the model element is unresolved.
+ *
+ * @return true if the model element is unresolved.
+ */
+ boolean isUnresolved();
+
+ /**
+ * Sets whether the model element is unresolved.
+ *
+ * @param unresolved whether the model element is unresolved
+ */
+ void setUnresolved(boolean unresolved);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentAttachPoint.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentAttachPoint.java
new file mode 100644
index 0000000000..bf2cfca924
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentAttachPoint.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.policy;
+
+import java.util.List;
+
+/**
+ * Base interface for all assembly model objects that can be have policy intents
+ * attached to them.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface IntentAttachPoint {
+
+ /**
+ * Returns a list of policy intents. See the Policy Framework specification
+ * for a description of this attribute.
+ *
+ * @return a list of policy intents.
+ */
+ List<Intent> getRequiredIntents();
+
+
+ /**
+ * Returns the type of the attach point such as a BindingType or an ImplementationType and so on
+ * @return
+ */
+ IntentAttachPointType getType();
+
+ /**
+ *
+ * Sets the type of the attach point such as a BindingType or an ImplementationType and so on
+ * @param type
+ */
+ void setType(IntentAttachPointType type);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentAttachPointType.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentAttachPointType.java
new file mode 100644
index 0000000000..6db529c7f0
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentAttachPointType.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Base interface for representing the model type of assembly model objects that can be have policy intents
+ * attached to them.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface IntentAttachPointType {
+
+ /**
+ * Returns the name of the extension type defined by this instance e.g. implementation.java, binding.ws
+ * @return the extension type QName
+ */
+ QName getName();
+
+ /**
+ * Sets the name of the extension type
+ * @param type the name of the extension type
+ */
+ void setName(QName type);
+
+ /**
+ * Returns the list of names of policy intents that will always be provided by this Extension Type
+ * @return list of Policy Intent names
+ */
+ List<Intent> getAlwaysProvidedIntents();
+
+ /**
+ * Returns the list of names of policy intents that may be provided by this Extension Type thro
+ * appropriate configuration
+ * @return list of Policy Intent names
+ */
+ List<Intent> getMayProvideIntents();
+
+ /**
+ * Returns true if the model element is unresolved.
+ *
+ * @return true if the model element is unresolved.
+ */
+ boolean isUnresolved();
+
+ /**
+ * Sets whether the model element is unresolved.
+ *
+ * @param unresolved whether the model element is unresolved
+ */
+ void setUnresolved(boolean unresolved);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentAttachPointTypeFactory.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentAttachPointTypeFactory.java
new file mode 100644
index 0000000000..ee67006875
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentAttachPointTypeFactory.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy;
+
+/**
+ * Factory interface for creating extension types meta data
+ *
+ * @version $Rev$ $Date$
+ */
+public interface IntentAttachPointTypeFactory {
+
+ /**
+ * Creates an ImplementationTypeImpl instance to hold metadata related to
+ * a particular implementation extension in the SCA Domain
+ *
+ * @return an instance of IntentAttachPointType
+ */
+ IntentAttachPointType createImplementationType();
+
+ /**
+ * Creates an BindingTypeImpl instance to hold metadata related to
+ * a particular binding extension in the SCA Domain
+ *
+ * @return an instance of IntentAttachPointType
+ */
+ IntentAttachPointType createBindingType();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentMap.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentMap.java
new file mode 100644
index 0000000000..1b225bc918
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/IntentMap.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy;
+
+import java.util.List;
+
+/**
+ * Represents a policy intent map. See the Policy Framework specification for a
+ * description of this element.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface IntentMap {
+
+ /**
+ * Returns the intent realized by this intent map.
+ *
+ * @return the intent realized by this intent map
+ */
+ Intent getProvidedIntent();
+
+ /**
+ * Sets the intent realized by this intent map.
+ *
+ * @param providedIntent the intent realized by this intent map
+ */
+ void setProvidedIntent(Intent providedIntent);
+
+ /**
+ * Returns the default qualified intent map.
+ *
+ * @return the default qualified intent map
+ */
+ IntentMap getDefaultQualifiedIntentMap();
+
+ /**
+ * Sets the default qualified intent map.
+ *
+ * @param defaultQualifiedIntentMap the default qualified intent map
+ */
+ void setDefaultQualifiedIntentMap(IntentMap defaultQualifiedIntentMap);
+
+ /**
+ * Returns the list of children qualified intent maps.
+ *
+ * @return
+ */
+ List<IntentMap> getQualifiedIntentMaps();
+
+ /**
+ * Returns the list of concrete policies, either WS-Policy policy
+ * attachments, policy references, or policies expressed in another policy
+ * language.
+ *
+ * @return the list of concrete policies
+ */
+ List<Object> getPolicies();
+
+ /**
+ * Returns true if the model element is unresolved.
+ *
+ * @return true if the model element is unresolved.
+ */
+ boolean isUnresolved();
+
+ /**
+ * Sets whether the model element is unresolved.
+ *
+ * @param unresolved whether the model element is unresolved
+ */
+ void setUnresolved(boolean unresolved);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Policy.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Policy.java
new file mode 100644
index 0000000000..c6393e2ada
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/Policy.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.policy;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Interface that will abstract various types of policy specifications
+ * and attachments for example WS-Policy
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Policy {
+ QName getSchemaName();
+ void setUnresolved(boolean unresolved);
+ boolean isUnresolved();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicyContext.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicyContext.java
new file mode 100644
index 0000000000..65c39803d2
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicyContext.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy;
+
+import java.util.List;
+
+/**
+ * A context container for policies.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface PolicyContext {
+ List<Intent> getIntents(Object key);
+ List<PolicySet> getPolicySets(Object key);
+ void addIntents(Object key, List<Intent> intents);
+ void addPolicySets(Object key, List<PolicySet> policySets);
+ void addIntent(Object key, Intent intent);
+ void addPolicySet(Object key, PolicySet policySet);
+ void clearIntents(Object key);
+ void clearPolicySets(Object key);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicyFactory.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicyFactory.java
new file mode 100644
index 0000000000..49bcbae1ae
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicyFactory.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy;
+
+/**
+ * A factory for the policy model.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface PolicyFactory {
+
+ /**
+ * Create a new intent.
+ *
+ * @return a new intent
+ */
+ Intent createIntent();
+
+ /**
+ * Create a new policy set.
+ *
+ * @return a new policy set
+ */
+ PolicySet createPolicySet();
+
+ /**
+ * Create a new intent map.
+ *
+ * @return a new intent map
+ */
+ IntentMap createIntentMap();
+
+ /**
+ * create a new Profile Intent
+ *
+ * @return a ProfileIntent instance
+ */
+ ProfileIntent createProfileIntent();
+
+ /**
+ * create a new QualifiedIntent
+ *
+ * @return a QualifiedIntent instance
+ */
+ QualifiedIntent createQualifiedIntent();
+
+ /**
+ * create a new PolicySetReference
+ *
+ * @return a PolicySetReference instance
+ */
+ PolicySetReference createPolicySetReference();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySet.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySet.java
new file mode 100644
index 0000000000..b16072c214
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySet.java
@@ -0,0 +1,155 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.xpath.XPathExpression;
+
+/**
+ * Represents a policy set. See the Policy Framework specification for a
+ * description of this element.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface PolicySet {
+
+ /**
+ * Returns the intent name.
+ *
+ * @return the intent name
+ */
+ QName getName();
+
+ /**
+ * Sets the intent name
+ *
+ * @param name the intent name
+ */
+ void setName(QName name);
+
+ /**
+ * Returns the list of operations that this policy set applies to.
+ *
+ * @return
+ */
+ //List<Operation> getOperations();
+ /**
+ * Returns the list of
+ *
+ * @return
+ */
+ List<PolicySet> getReferencedPolicySets();
+
+ /**
+ * Returns the list of provided intents
+ *
+ * @return
+ */
+ List<Intent> getProvidedIntents();
+
+ /**
+ * Returns the list of concrete policies, either WS-Policy policy
+ * attachments, policy references, or policies expressed in another policy
+ * language.
+ *
+ * @return the list of concrete policies
+ */
+ List<Object> getPolicies();
+
+ /**
+ * Returns true if the model element is unresolved.
+ *
+ * @return true if the model element is unresolved.
+ */
+ boolean isUnresolved();
+
+ /**
+ * Sets whether the model element is unresolved.
+ *
+ * @param unresolved whether the model element is unresolved
+ */
+ void setUnresolved(boolean unresolved);
+
+ /**
+ * Returns the XPath expression that is to be used to evaluate
+ * if this PolicySet applies to specific attachment point
+ *
+ * @return the XPath expression
+ */
+ String getAppliesTo();
+
+ /**
+ * Sets the XPath expression that is to be used to evaluate
+ * if this PolicySet applies to specific attachment point
+ *
+ */
+ void setAppliesTo(String xpath);
+
+ /**
+ * Returns the policies / policy attachments provided thro intent maps
+ *
+ * @return
+ */
+ Map<Intent, List<Object>> getMappedPolicies();
+
+ /**
+ * Gets the XPath expression that is to be used to evaluate
+ * the SCA Artifacts that this policyset will always apply to
+ * immaterial of an intent declared on the SCA Artifact
+ *
+ * @return the XPath expression
+ */
+ String getAlwaysAppliesTo();
+
+ /**
+ * Sets the XPath expression that is to be used to evaluate
+ * the SCA Artifacts that this policyset will always apply to
+ * immaterial of an intent declared on the SCA Artifact
+ *
+ */
+ void setAlwaysAppliesTo(String xpath);
+
+ /**
+ * Get the XPath expression for the appliesTo attribute
+ * @return the XPath expression for the appliesTo attribute
+ */
+ XPathExpression getAppliesToXPathExpression();
+
+ /**
+ * Set the XPath expression for the appliesTo attribute
+ * @param xpathExpression the XPath expression for the appliesTo attribute
+ */
+ void setAppliesToXPathExpression(XPathExpression xpathExpression);
+
+ /**
+ * Get the XPath expression for the alwaysAppliesTo attribute
+ * @return the XPath expression for the alwaysAppliesTo attribute
+ */
+ XPathExpression getAlwaysAppliesToXPathExpression();
+
+ /**
+ * Set the XPath expression for the alwaysAppliesTo attribute
+ * @param xpathExpression the XPath expression for the alwaysAppliesTo attribute
+ */
+ void setAlwaysAppliesToXPathExpression(XPathExpression xpathExpression);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySetAttachPoint.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySetAttachPoint.java
new file mode 100644
index 0000000000..f4156fc2e6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySetAttachPoint.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy;
+
+import java.util.List;
+
+/**
+ * Base interface for all assembly model objects that can have policy sets
+ * attached to them.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface PolicySetAttachPoint extends IntentAttachPoint {
+
+ /**
+ * Returns a list of policy sets. See the Policy Framework specification for
+ * a description of this attribute.
+ *
+ * @return a list of policy sets.
+ */
+ List<PolicySet> getPolicySets();
+
+
+ /**
+ * Returns a list of policy sets defined in the domain, that are applicable to this
+ * PolicySetAttachPoint. An applicable PolicySet is one that include this PolicySetAttachPoint
+ * as part of its 'appliesTo' XPath attribute.
+ *
+ * @return a list of policy sets applicable to this PolicySetAttachPoint
+ */
+ List<PolicySet> getApplicablePolicySets();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySetReference.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySetReference.java
new file mode 100644
index 0000000000..caa0d04fe3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/PolicySetReference.java
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy;
+
+import javax.xml.namespace.QName;
+
+/**
+ * Interface that abstracts a PolicySet Reference
+ *
+ * @version $Rev$ $Date$
+ */
+public interface PolicySetReference {
+
+ /**
+ * Returns the name of the policyset being referred to
+ *
+ * @return the QName of the referred policyset
+ */
+ QName getReferredPolicySetName();
+
+ /**
+ * @param refPolicySetName the name of the policyset being referred to
+ *
+ */
+ void setReferredPolicySetName(QName refPolicySetName);
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/ProfileIntent.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/ProfileIntent.java
new file mode 100644
index 0000000000..28ff9d09d3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/ProfileIntent.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy;
+
+import java.util.List;
+
+/**
+ * Interface that abstracts a profile intent
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ProfileIntent extends Intent {
+ /**
+ * Returns the list of required intents.
+ *
+ * @return the list of required intents
+ */
+ List<Intent> getRequiredIntents();
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/QualifiedIntent.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/QualifiedIntent.java
new file mode 100644
index 0000000000..0f43221dd6
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/QualifiedIntent.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy;
+
+/**
+ * Abstracts a qualified policy intent
+ *
+ * @version $Rev$ $Date$
+ */
+public interface QualifiedIntent extends Intent {
+
+ /**
+ * Returns the intent qualified by this intent
+ *
+ * @return
+ */
+ Intent getQualifiableIntent();
+
+ /**
+ * sets the qualifiable intent for this Qualified intent instance
+ *
+ * @param qualifiableIntent
+ */
+ void setQualifiableIntent(Intent qualifiableIntent);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/BindingTypeImpl.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/BindingTypeImpl.java
new file mode 100644
index 0000000000..dbdef38324
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/BindingTypeImpl.java
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+
+/**
+ * Concrete implementation for a BindingType
+ *
+ * @version $Rev$ $Date$
+ */
+public class BindingTypeImpl implements IntentAttachPointType {
+
+ private List<Intent> alwaysProvides = new ArrayList<Intent>();
+ private List<Intent> mayProvides = new ArrayList<Intent>();
+ private QName typeName;
+ private boolean unResolved = true;
+
+ public List<Intent> getAlwaysProvidedIntents() {
+ return alwaysProvides;
+ }
+
+ public List<Intent> getMayProvideIntents() {
+ return mayProvides;
+ }
+
+ public QName getName() {
+ return typeName;
+ }
+
+ public void setName(QName type) {
+ this.typeName = type;
+ }
+
+ public boolean isUnresolved() {
+ return unResolved;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ this.unResolved = unresolved;
+ }
+
+ @Override
+ public int hashCode() {
+ return String.valueOf(getName()).hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ } else if (obj instanceof BindingTypeImpl ) {
+ if (getName() != null) {
+ return getName().equals(((BindingTypeImpl)obj).getName());
+ } else {
+ return ((BindingTypeImpl)obj).getName() == null;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return getName().toString();
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/ImplementationTypeImpl.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/ImplementationTypeImpl.java
new file mode 100644
index 0000000000..fa95d84c4e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/ImplementationTypeImpl.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.policy.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+
+/**
+ * Concrete implementation for a Implementation Type
+ *
+ * @version $Rev$ $Date$
+ */
+public class ImplementationTypeImpl implements IntentAttachPointType {
+ private List<Intent> alwaysProvides = new ArrayList<Intent>();
+ private List<Intent> mayProvides = new ArrayList<Intent>();
+ private QName typeName;
+ private boolean unResolved = true;
+
+ public List<Intent> getAlwaysProvidedIntents() {
+ return alwaysProvides;
+ }
+
+ public List<Intent> getMayProvideIntents() {
+ return mayProvides;
+ }
+
+ public QName getName() {
+ return typeName;
+ }
+
+ public void setName(QName type) {
+ this.typeName = type;
+ }
+
+ public boolean isUnresolved() {
+ return unResolved;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ this.unResolved = unresolved;
+ }
+
+ @Override
+ public int hashCode() {
+ return String.valueOf(getName()).hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ } else if (obj instanceof ImplementationTypeImpl ) {
+ if (getName() != null) {
+ return getName().equals(((ImplementationTypeImpl)obj).getName());
+ } else {
+ return ((ImplementationTypeImpl)obj).getName() == null;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return getName().toString();
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentAttachPointTypeFactoryImpl.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentAttachPointTypeFactoryImpl.java
new file mode 100644
index 0000000000..aa6e27c240
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentAttachPointTypeFactoryImpl.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy.impl;
+
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory;
+
+/**
+ * Default implementation for IntentAttachPointTypeFactory
+ *
+ * @version $Rev$ $Date$
+ */
+public class IntentAttachPointTypeFactoryImpl implements IntentAttachPointTypeFactory {
+
+ public IntentAttachPointType createBindingType() {
+ return new BindingTypeImpl();
+ }
+
+ public IntentAttachPointType createImplementationType() {
+ return new ImplementationTypeImpl();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentImpl.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentImpl.java
new file mode 100644
index 0000000000..2d6bd0eb6f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentImpl.java
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.policy.Intent;
+
+/**
+ * Represents a policy intent.
+ *
+ * @version $Rev$ $Date$
+ */
+public class IntentImpl implements Intent {
+
+ private static final String QUALIFIED_SEPARATOR = ".";
+ private static final String DOMAIN_SEPARATOR = ".";
+ private QName name;
+ //private List<Operation> operations = new ArrayList<Operation>();
+ private List<QName> constrains = new ArrayList<QName>();
+ private String description;
+ private List<Intent> qualifiedIntents = new ArrayList<Intent>();
+ // private List<Intent> requiredIntents = new ArrayList<Intent>();
+ private List<Intent> excludedIntents = new ArrayList<Intent>();
+ private boolean unresolved = true;
+ private String domain;
+ private String[] qualifiedNames;
+
+ protected IntentImpl() {
+ }
+
+ public QName getName() {
+ return name;
+ }
+
+ public void setName(QName name) {
+ this.name = name;
+ String iname = name.getLocalPart();
+ int domainIdx = iname.indexOf(DOMAIN_SEPARATOR);
+ if (domainIdx > -1) {
+ domain = iname.substring(0, domainIdx);
+ String qualifNamesStr = iname.substring(domainIdx + 1);
+ String pattern = "\\" + QUALIFIED_SEPARATOR;
+ qualifiedNames = qualifNamesStr.split(pattern);
+ } else
+ domain = iname;
+ }
+
+ public String getDomain() {
+ return domain;
+ }
+
+ public String[] getQualifiedNames() {
+ String[] results = new String[qualifiedNames.length];
+ System.arraycopy(qualifiedNames, 0, results, 0, qualifiedNames.length);
+ return results;
+ }
+
+ /*public List<Operation> getOperations() {
+ return operations;
+ }*/
+
+ public List<QName> getConstrains() {
+ return constrains;
+ }
+
+ public String getDescription() {
+ return description;
+ }
+
+ public void setDescription(String description) {
+ this.description = description;
+ }
+
+ public List<Intent> getQualifiedIntents() {
+ return qualifiedIntents;
+ }
+
+ public List<Intent> getExcludedIntents() {
+ return excludedIntents;
+ }
+
+ public boolean isUnresolved() {
+ return unresolved;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ this.unresolved = unresolved;
+ }
+
+ /**
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ QName intentName = getName();
+ result = prime * result + ((intentName == null) ? 0 : intentName.hashCode());
+ return result;
+ }
+
+ /**
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof IntentImpl)) {
+ return false;
+ }
+ final IntentImpl other = (IntentImpl)obj;
+ if (getName() == null) {
+ if (other.getName() != null) {
+ return false;
+ }
+ } else if (!getName().equals(other.getName())) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return String.valueOf(getName());
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentMapImpl.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentMapImpl.java
new file mode 100644
index 0000000000..aab03281ba
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/IntentMapImpl.java
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy.impl;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentMap;
+
+/**
+ * Represents an intent map.
+ *
+ * @version $Rev$ $Date$
+ */
+public class IntentMapImpl implements IntentMap {
+
+ private boolean unresolved;
+ private IntentMap defaultQualifiedIntentMap;
+ private List<Object> policies;
+ private Intent providedIntent;
+ private List<IntentMap> qualifiedIntentMaps;
+
+ protected IntentMapImpl() {
+ }
+
+ public IntentMap getDefaultQualifiedIntentMap() {
+ return defaultQualifiedIntentMap;
+ }
+
+ public List<Object> getPolicies() {
+ return policies;
+ }
+
+ public Intent getProvidedIntent() {
+ return providedIntent;
+ }
+
+ public List<IntentMap> getQualifiedIntentMaps() {
+ return qualifiedIntentMaps;
+ }
+
+ public void setDefaultQualifiedIntentMap(IntentMap defaultQualifiedIntentMap) {
+ this.defaultQualifiedIntentMap = defaultQualifiedIntentMap;
+ }
+
+ public void setProvidedIntent(Intent providedIntent) {
+ this.providedIntent = providedIntent;
+ }
+
+ public boolean isUnresolved() {
+ return unresolved;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ this.unresolved = unresolved;
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyContextImpl.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyContextImpl.java
new file mode 100644
index 0000000000..a0e2f10f56
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyContextImpl.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.impl;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.PolicyContext;
+import org.apache.tuscany.sca.policy.PolicySet;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class PolicyContextImpl implements PolicyContext {
+ private Map<Object, List<Intent>> intents = new Hashtable<Object , List<Intent>>();
+ private Map<Object, List<PolicySet>> policySets = new Hashtable<Object, List<PolicySet>>();
+
+ public void addIntent(Object key, Intent intent) {
+ if ( intents.get(key) == null ) {
+ intents.put(key, new ArrayList<Intent>());
+ }
+ intents.get(key).add(intent);
+ }
+
+ public void addIntents(Object key, List<Intent> intents) {
+ if ( this.intents.get(key) == null ) {
+ this.intents.put(key, new ArrayList<Intent>());
+ }
+ this.intents.get(key).addAll(intents);
+ }
+
+ public void addPolicySet(Object key, PolicySet policySet) {
+ if ( policySets.get(key) == null ) {
+ policySets.put(key, new ArrayList<PolicySet>());
+ }
+ policySets.get(key).add(policySet);
+ }
+
+ public void addPolicySets(Object key, List<PolicySet> policySets) {
+ if ( this.policySets.get(key) == null ) {
+ this.policySets.put(key, new ArrayList<PolicySet>());
+ }
+ this.policySets.get(key).addAll(policySets);
+ }
+
+ public List<Intent> getIntents(Object key) {
+ if ( intents.get(key) == null ) {
+ intents.put(key, new ArrayList<Intent>());
+ }
+ return intents.get(key);
+ }
+
+ public List<PolicySet> getPolicySets(Object key) {
+ if ( policySets.get(key) == null ) {
+ policySets.put(key, new ArrayList<PolicySet>());
+ }
+ return policySets.get(key);
+ }
+
+ public void clearIntents(Object key) {
+ if ( intents.get(key) != null ) {
+ intents.clear();
+ }
+ }
+
+ public void clearPolicySets(Object key) {
+ if ( policySets.get(key) != null ) {
+ policySets.clear();
+ }
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyFactoryImpl.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyFactoryImpl.java
new file mode 100644
index 0000000000..1db29b835e
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicyFactoryImpl.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy.impl;
+
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentMap;
+import org.apache.tuscany.sca.policy.PolicyFactory;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.PolicySetReference;
+import org.apache.tuscany.sca.policy.ProfileIntent;
+import org.apache.tuscany.sca.policy.QualifiedIntent;
+
+/**
+ * A factory for the policy model.
+ *
+ * @version $Rev$ $Date$
+ */
+public abstract class PolicyFactoryImpl implements PolicyFactory {
+
+ public Intent createIntent() {
+ return new IntentImpl();
+ }
+
+ public PolicySetReference createPolicySetReference() {
+ return new PolicySetReferenceImpl();
+ }
+
+ public PolicySet createPolicySet() {
+ return new PolicySetImpl();
+ }
+
+ public IntentMap createIntentMap() {
+ return new IntentMapImpl();
+ }
+
+ public ProfileIntent createProfileIntent() {
+ return new ProfileIntentImpl();
+ }
+
+ public QualifiedIntent createQualifiedIntent() {
+ return new QualifiedIntentImpl();
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicySetImpl.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicySetImpl.java
new file mode 100644
index 0000000000..4bd9d5b7c7
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicySetImpl.java
@@ -0,0 +1,149 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy.impl;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+import javax.xml.xpath.XPathExpression;
+
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.PolicySet;
+
+/**
+ * Represents a policy set.
+ *
+ * @version $Rev$ $Date$
+ */
+public class PolicySetImpl implements PolicySet {
+
+ private QName name;
+ //private List<Operation> operations = new ArrayList<Operation>();
+ //private List<QName> appliesTo;
+ private String appliesTo;
+ private List<Intent> providedIntents = new ArrayList<Intent>();
+ private List<PolicySet> referencedPolicySets = new ArrayList<PolicySet>();
+ private List<Object> policies = new ArrayList<Object>();
+ Map<Intent, List<Object>> mappedPolicies = new Hashtable<Intent, List<Object>>();
+ private boolean unresolved = true;
+ private String alwaysAppliesTo;
+
+ private XPathExpression appliesToXPathExpression;
+ private XPathExpression alwaysAppliesToXPathExpression;
+
+ public String getAlwaysAppliesTo() {
+ return alwaysAppliesTo;
+ }
+
+ public void setAlwaysAppliesTo(String alwaysAppliesTo) {
+ this.alwaysAppliesTo = alwaysAppliesTo;
+ }
+
+ protected PolicySetImpl() {
+ }
+
+ public QName getName() {
+ return name;
+ }
+
+ public void setName(QName name) {
+ this.name = name;
+ }
+
+ /*public List<Operation> getOperations() {
+ return operations;
+ }*/
+
+ public String getAppliesTo() {
+ return appliesTo;
+ }
+
+ public void setAppliesTo(String appliesTo) {
+ this.appliesTo = appliesTo;
+ }
+
+ public List<Intent> getProvidedIntents() {
+ return providedIntents;
+ }
+
+ public List<PolicySet> getReferencedPolicySets() {
+ return referencedPolicySets;
+ }
+
+ public List<Object> getPolicies() {
+ return policies;
+ }
+
+ public boolean isUnresolved() {
+ return unresolved;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ this.unresolved = unresolved;
+ }
+
+ public Map<Intent, List<Object>> getMappedPolicies() {
+ return mappedPolicies;
+ }
+
+ @Override
+ public int hashCode() {
+ return String.valueOf(getName()).hashCode();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ } else if (obj instanceof PolicySet) {
+ if (getName() != null) {
+ return getName().equals(((PolicySet)obj).getName());
+ } else {
+ return ((PolicySet)obj).getName() == null;
+ }
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public String toString() {
+ return getName().toString();
+ }
+
+ public XPathExpression getAppliesToXPathExpression() {
+ return appliesToXPathExpression;
+ }
+
+ public void setAppliesToXPathExpression(XPathExpression appliesToXPathExpression) {
+ this.appliesToXPathExpression = appliesToXPathExpression;
+ }
+
+ public XPathExpression getAlwaysAppliesToXPathExpression() {
+ return alwaysAppliesToXPathExpression;
+ }
+
+ public void setAlwaysAppliesToXPathExpression(XPathExpression alwaysAppliesToXPathExpression) {
+ this.alwaysAppliesToXPathExpression = alwaysAppliesToXPathExpression;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicySetReferenceImpl.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicySetReferenceImpl.java
new file mode 100644
index 0000000000..98a116fe7b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/PolicySetReferenceImpl.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy.impl;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.policy.PolicySetReference;
+
+/**
+ * Concrete implementation for a PolicySetReference
+ *
+ * @version $Rev$ $Date$
+ */
+public class PolicySetReferenceImpl implements PolicySetReference {
+
+ private QName referredPolicySetName = null;
+
+ /*
+ * @see org.apache.tuscany.sca.policy.PolicySetReference#getReferredPolicySetName()
+ */
+ public QName getReferredPolicySetName() {
+ return referredPolicySetName;
+ }
+
+ /*
+ * @see org.apache.tuscany.sca.policy.PolicySetReference#setReferredPolicySetName(javax.xml.namespace.QName)
+ */
+ public void setReferredPolicySetName(QName refPolicySetName) {
+ referredPolicySetName = refPolicySetName;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/ProfileIntentImpl.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/ProfileIntentImpl.java
new file mode 100644
index 0000000000..e5002d2cdc
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/ProfileIntentImpl.java
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.policy.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.ProfileIntent;
+
+/**
+ * Concrete implementation for Profile Intent
+ *
+ * @version $Rev$ $Date$
+ */
+public class ProfileIntentImpl extends IntentImpl implements ProfileIntent {
+ private List<Intent> requiredIntents = new ArrayList<Intent>();
+
+ public List<Intent> getRequiredIntents() {
+ return requiredIntents;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/QualifiedIntentImpl.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/QualifiedIntentImpl.java
new file mode 100644
index 0000000000..d6f65b1788
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/impl/QualifiedIntentImpl.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.policy.impl;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.QualifiedIntent;
+
+/**
+ * Models a concrete implementation of a Qualified Intent
+ *
+ * @version $Rev$ $Date$
+ */
+public class QualifiedIntentImpl extends IntentImpl implements QualifiedIntent {
+ private Intent qualifiableIntent = null;
+
+ public Intent getQualifiableIntent() {
+ return qualifiableIntent;
+ }
+
+ public void setQualifiableIntent(Intent qualifiableIntent) {
+ this.qualifiableIntent = qualifiableIntent;
+ }
+
+ @Override
+ public List<QName> getConstrains() {
+ return getQualifiableIntent().getConstrains();
+ }
+
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyComputationUtils.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyComputationUtils.java
new file mode 100644
index 0000000000..2e4c6a9d78
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyComputationUtils.java
@@ -0,0 +1,418 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.util;
+
+import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI;
+
+import java.io.InputStream;
+import java.io.StringWriter;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Result;
+import javax.xml.transform.Source;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpression;
+import javax.xml.xpath.XPathExpressionException;
+
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.ProfileIntent;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * Utility methods used during computation of PolicyIntents and PolicySets sets
+ *
+ * @version $Rev$ $Date$
+ */
+public class PolicyComputationUtils {
+ private static final String POLICYSET_PREFIX = "tp_";
+ private static final String APPLICABLE_POLICYSET_ATTR_NS = "http://tuscany.apache.org/xmlns/sca/1.0";
+ private static final String APPLICABLE_POLICYSET_ATTR = "applicablePolicySets";
+ private static final String POLICY_SETS_ATTR = "policySets";
+ private static final String APPLICABLE_POLICYSET_ATTR_PREFIX = "tuscany";
+ private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0";
+
+ /**
+ * This method unconditionally adds intents from the source list to the target list.
+ * It is used for intermediate intent inheritance between promotion levels
+ * (e.g. between a composite service and a component service). It does not check
+ * whether there are conflicting (mutually exclusive) intents. This is because
+ * promotion cannot override intents. If the resulting target list has conflicting
+ * intents, this will be detected later during policy computation.
+ */
+ public static void addInheritedIntents(List<Intent> sourceList, List<Intent> targetList) {
+ if (sourceList != null) {
+ targetList.addAll(sourceList);
+ }
+ }
+
+ public static void addInheritedPolicySets(List<PolicySet> sourceList,
+ List<PolicySet> targetList,
+ boolean checkOverrides) {
+ // check overrides is true when policysets are to be copied from
+ // componentType to component level
+ if (checkOverrides) {
+ // aggregate all the provided intents present in the target
+ List<Intent> targetProvidedIntents = new ArrayList<Intent>();
+ for (PolicySet policySet : targetList) {
+ targetProvidedIntents.addAll(policySet.getProvidedIntents());
+ }
+
+ // for every policy set in the source check if it provides one of
+ // the intents that is
+ // already provided by the policysets in the destination and do not
+ // copy them.
+ for (PolicySet policySet : sourceList) {
+ for (Intent sourceProvidedIntent : policySet.getProvidedIntents()) {
+ if (!targetProvidedIntents.contains(sourceProvidedIntent)) {
+ targetList.add(policySet);
+ }
+ }
+ }
+ } else {
+ targetList.addAll(sourceList);
+ }
+ }
+
+ /**
+ * This method is used to inherit intents and policy sets between hierarchical levels
+ * within the same composite (e.g. between a component and its services and references).
+ * In this case the source intents and policy sets provide defaults which are inherited
+ * into the target lists only when there is no conflict. For example consider a component
+ * with 3 references. The component level requires intent 'propagatesTransaction'.
+ * Reference 1 and 2 do not specify an intent, but reference 3 requires 'suspendsTransaction'.
+ * In this case the 'propagatesTransaction' intent is inherited by reference 1 and 2
+ * but not by reference 3.
+ */
+ public static void addDefaultPolicies(List<Intent> sourceIntents,
+ List<PolicySet> sourcePolicySets,
+ List<Intent> targetIntents,
+ List<PolicySet> targetPolicySets)
+ {
+ // form a list of all intents required by the target
+ List<Intent> combinedTargetIntents = new ArrayList<Intent>();
+ combinedTargetIntents.addAll(findAndExpandProfileIntents(targetIntents));
+ for (PolicySet targetPolicySet : targetPolicySets) {
+ combinedTargetIntents.addAll(findAndExpandProfileIntents(targetPolicySet.getProvidedIntents()));
+ }
+
+ // inherit intents in the source list that do not conflict with intents already in the target list
+ for (Intent sourceIntent : findAndExpandProfileIntents(sourceIntents)) {
+ boolean conflict = false;
+ for (Intent excluded : sourceIntent.getExcludedIntents()) {
+ if (combinedTargetIntents.contains(excluded)) {
+ conflict = true;
+ break;
+ }
+ }
+ if (!conflict) {
+ targetIntents.add(sourceIntent);
+ }
+ }
+
+ // inherit policy sets in the source list that do not conflict with policy sets or intents
+ // in the target list
+ for (PolicySet sourcePolicySet : sourcePolicySets) {
+ boolean conflict = false;
+ List<Intent> providedIntents = findAndExpandProfileIntents(sourcePolicySet.getProvidedIntents());
+ checkConflict: for (Intent intent : providedIntents) {
+ for (Intent excluded : intent.getExcludedIntents()) {
+ if (combinedTargetIntents.contains(excluded)) {
+ conflict = true;
+ break checkConflict;
+ }
+ }
+ }
+ if (!conflict)
+ targetPolicySets.add(sourcePolicySet);
+ }
+
+ }
+
+ public static void checkForMutuallyExclusiveIntents(
+ List<Intent> intents,
+ List<PolicySet> policySets,
+ IntentAttachPointType intentAttachPointType,
+ String id) throws PolicyValidationException
+ {
+ // gather all intents (keeping track of where they come from)
+ Map<Intent, PolicySet> combinedIntents = new HashMap<Intent,PolicySet>();
+ for (PolicySet policySet : policySets) {
+ for (Intent providedIntent : findAndExpandProfileIntents(policySet.getProvidedIntents())) {
+ combinedIntents.put(providedIntent, policySet);
+ }
+ }
+ for (Intent intent : intents) {
+ combinedIntents.put(intent, null);
+ }
+
+ // check for conflicts
+ for (Intent intent : combinedIntents.keySet()) {
+ for (Intent excluded : intent.getExcludedIntents()) {
+ if (combinedIntents.keySet().contains(excluded)) {
+ String sIntent1, sIntent2;
+ if (combinedIntents.get(intent) == null)
+ sIntent1 = intent.getName().toString();
+ else
+ sIntent1 = intent.getName().toString() + " in policy set " + combinedIntents.get(intent).getName().toString();
+ if (combinedIntents.get(excluded) == null)
+ sIntent2 = excluded.getName().toString();
+ else
+ sIntent2 = excluded.getName().toString() + " in policy set " + combinedIntents.get(excluded).getName().toString();
+ throw new PolicyValidationException(
+ intentAttachPointType.getName() + " for " + id +
+ " uses mutually-exclusive intents " + sIntent1 + " and " + sIntent2);
+ }
+ }
+ }
+ }
+
+ public static void expandProfileIntents(List<Intent> intents) {
+ List<Intent> expandedIntents = null;
+ if ( intents.size() > 0 ) {
+ expandedIntents = findAndExpandProfileIntents(intents);
+ intents.clear();
+ intents.addAll(expandedIntents);
+ }
+ }
+
+ public static List<Intent> findAndExpandProfileIntents(List<Intent> intents) {
+ List<Intent> expandedIntents = new ArrayList<Intent>();
+ for ( Intent intent : intents ) {
+ if ( intent instanceof ProfileIntent ) {
+ ProfileIntent profileIntent = (ProfileIntent)intent;
+ List<Intent> requiredIntents = profileIntent.getRequiredIntents();
+ expandedIntents.addAll(findAndExpandProfileIntents(requiredIntents));
+ } else {
+ expandedIntents.add(intent);
+ }
+ }
+ return expandedIntents;
+ }
+
+ private static byte[] addApplicablePolicySets(Document doc, Collection<PolicySet> policySets)
+ throws XPathExpressionException, TransformerConfigurationException, TransformerException {
+
+ for (PolicySet policySet : policySets) {
+ if (policySet.getAppliesTo() != null) {
+ addApplicablePolicySets(policySet, doc);
+ }
+
+ if (policySet.getAlwaysAppliesTo() != null) {
+ addAlwaysApplicablePolicySets(policySet, doc);
+ }
+ }
+
+ StringWriter sw = new StringWriter();
+ final Source domSource = new DOMSource(doc);
+ final Result finalResult = new StreamResult(sw);
+ final Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ // transformer.setOutputProperty("omit-xml-declaration", "yes");
+ // Allow priviledged access to let transformers read property files. Requires
+ // PropertyPermission in security policy.
+ try {
+ AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
+ public Object run() throws TransformerException {
+ transformer.transform(domSource, finalResult);
+ return null;
+ }
+ });
+ } catch (PrivilegedActionException e) {
+ throw (TransformerException)e.getException();
+ }
+
+ return sw.toString().getBytes();
+ }
+
+ private static void addAlwaysApplicablePolicySets(PolicySet policySet,
+ Document doc) throws XPathExpressionException {
+ XPathExpression expression = policySet.getAlwaysAppliesToXPathExpression();
+ NodeList result = (NodeList)expression.evaluate(doc, XPathConstants.NODESET);
+
+ if (result != null) {
+ for (int counter = 0; counter < result.getLength(); ++counter) {
+ Node aResultNode = result.item(counter);
+
+ String alwaysApplicablePolicySets = null;
+
+ String policySetPrefix =
+ declareNamespace((Element)aResultNode, policySet.getName().getNamespaceURI());
+ String policySetsAttrPrefix =
+ declareNamespace((Element)aResultNode, SCA10_NS);
+ if (aResultNode.getAttributes().getNamedItem(POLICY_SETS_ATTR) != null) {
+ alwaysApplicablePolicySets =
+ aResultNode.getAttributes().getNamedItem(POLICY_SETS_ATTR).getNodeValue();
+ }
+
+ if (alwaysApplicablePolicySets != null && alwaysApplicablePolicySets.length() > 0) {
+ alwaysApplicablePolicySets =
+ alwaysApplicablePolicySets + " "
+ + policySetPrefix
+ + ":"
+ + policySet.getName().getLocalPart();
+ } else {
+ alwaysApplicablePolicySets =
+ policySetPrefix + ":" + policySet.getName().getLocalPart();
+ }
+
+ ((Element)aResultNode).setAttribute(POLICY_SETS_ATTR, alwaysApplicablePolicySets);
+ }
+ }
+ }
+
+ private static void addApplicablePolicySets(PolicySet policySet,
+ Document doc) throws XPathExpressionException {
+ XPathExpression expression = policySet.getAppliesToXPathExpression();
+ NodeList result = (NodeList)expression.evaluate(doc, XPathConstants.NODESET);
+
+ if (result != null) {
+ for (int counter = 0; counter < result.getLength(); ++counter) {
+ Node aResultNode = result.item(counter);
+
+ String applicablePolicySets = null;
+
+ String policySetPrefix =
+ declareNamespace((Element)aResultNode, policySet.getName().getNamespaceURI());
+ String appPolicyAttrPrefix =
+ declareNamespace((Element)aResultNode,
+ APPLICABLE_POLICYSET_ATTR_NS);
+ if (aResultNode.getAttributes().getNamedItemNS(APPLICABLE_POLICYSET_ATTR_NS,
+ APPLICABLE_POLICYSET_ATTR) != null) {
+ applicablePolicySets =
+ aResultNode.getAttributes().getNamedItemNS(APPLICABLE_POLICYSET_ATTR_NS,
+ APPLICABLE_POLICYSET_ATTR)
+ .getNodeValue();
+ }
+
+ if (applicablePolicySets != null && applicablePolicySets.length() > 0) {
+ applicablePolicySets =
+ applicablePolicySets + " "
+ + policySetPrefix
+ + ":"
+ + policySet.getName().getLocalPart();
+ } else {
+ applicablePolicySets =
+ policySetPrefix + ":" + policySet.getName().getLocalPart();
+ }
+
+ ((Element)aResultNode).setAttributeNS(APPLICABLE_POLICYSET_ATTR_NS,
+ appPolicyAttrPrefix + ":"
+ + APPLICABLE_POLICYSET_ATTR,
+ applicablePolicySets);
+ }
+ }
+ }
+
+ public static byte[] addApplicablePolicySets(InputStream is, Collection<PolicySet> domainPolicySets, DocumentBuilderFactory documentBuilderFactory) throws Exception {
+ documentBuilderFactory.setNamespaceAware(true);
+ DocumentBuilder db = documentBuilderFactory.newDocumentBuilder();
+ Document doc = db.parse(is);
+ is.close();
+ return addApplicablePolicySets(doc, domainPolicySets);
+ }
+
+ private static class DOMNamespaceContext implements NamespaceContext {
+ private Node node;
+
+ /**
+ * @param node
+ */
+ public DOMNamespaceContext(Node node) {
+ super();
+ this.node = node;
+ }
+
+ public String getNamespaceURI(String prefix) {
+ return node.lookupNamespaceURI(prefix);
+ }
+
+ public String getPrefix(String namespaceURI) {
+ return node.lookupPrefix(namespaceURI);
+ }
+
+ public Iterator<?> getPrefixes(String namespaceURI) {
+ return null;
+ }
+
+ }
+
+ private static String declareNamespace(Element element, String ns) {
+ if (ns == null) {
+ ns = "";
+ }
+ Node node = element;
+ String prefix = "";
+ boolean declared = false;
+ while (node != null && node.getNodeType() == Node.ELEMENT_NODE) {
+ if ( node.lookupPrefix(ns) != null ) {
+ prefix = node.lookupPrefix(ns);
+ declared = true;
+ break;
+ } else {
+ /*NamedNodeMap attrs = node.getAttributes();
+ if (attrs == null) {
+ break;
+ }
+ Node attr = attrs.getNamedItem(qname);
+ if (attr != null) {
+ declared = ns.equals(attr.getNodeValue());
+ break;
+ }*/
+ node = node.getParentNode();
+ }
+ }
+ if (!declared) {
+ // Find an available prefix
+ for (int i=1; ; i++) {
+ prefix = POLICYSET_PREFIX + i;
+ if (element.lookupNamespaceURI(prefix) == null) {
+ break;
+ }
+ }
+ String qname = "xmlns:" + prefix;
+ org.w3c.dom.Attr attr = element.getOwnerDocument().createAttributeNS(XMLNS_ATTRIBUTE_NS_URI, qname);
+ attr.setValue(ns);
+ element.setAttributeNodeNS(attr);
+ }
+ return prefix;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandler.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandler.java
new file mode 100644
index 0000000000..1f91710f95
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandler.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.util;
+
+import org.apache.tuscany.sca.policy.PolicySet;
+
+/**
+ * @deprecated This interface is replaced by PolicyProviderFactory/PolicyProvider SPIs
+ * Handler interface for handling policies defined in policysets
+ *
+ * @version $Rev$ $Date$
+ */
+@Deprecated
+public interface PolicyHandler {
+ PolicySet getApplicablePolicySet();
+ void setApplicablePolicySet(PolicySet policySet);
+ void setUp(Object... context);
+ void cleanUp(Object... context);
+ void beforeInvoke(Object... context);
+ void afterInvoke(Object... context);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerDefinitionsLoader.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerDefinitionsLoader.java
new file mode 100644
index 0000000000..3a37ed3c41
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerDefinitionsLoader.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.util;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
+
+/**
+ * Utility class for loading policy handler definitions from META-INF/services directories
+ *
+ * @version $Rev$ $Date$
+ */
+public class PolicyHandlerDefinitionsLoader {
+
+ public static List<PolicyHandlerTuple> loadPolicyHandlerClassnames() {
+ // Get the processor service declarations
+ Set<ServiceDeclaration> sds;
+ try {
+ sds = ServiceDiscovery.getInstance().getServiceDeclarations(PolicyHandler.class);
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+
+ List<PolicyHandlerTuple> handlerTupleList = new ArrayList<PolicyHandlerTuple>();
+
+ Map<Object, List<PolicyHandlerTuple>> handlerTuples = new Hashtable<Object, List<PolicyHandlerTuple>>();
+ for (ServiceDeclaration sd : sds) {
+ Map<String, String> attributes = sd.getAttributes();
+ String intentName = attributes.get("intent");
+ QName intentQName = getQName(intentName);
+ String policyModelClassName = attributes.get("model");
+ String appliesTo = attributes.get("appliesTo");
+ if ( appliesTo != null && !appliesTo.startsWith("/") ) {
+ appliesTo = "//" + appliesTo;
+ }
+ handlerTupleList.add(new PolicyHandlerTuple(sd, sd.getClassName(), intentQName, policyModelClassName, appliesTo));
+ }
+
+ return handlerTupleList;
+ }
+
+ private static QName getQName(String qname) {
+ if (qname == null) {
+ return null;
+ }
+ qname = qname.trim();
+ if (qname.startsWith("{")) {
+ int h = qname.indexOf('}');
+ if (h != -1) {
+ return new QName(qname.substring(1, h), qname.substring(h + 1));
+ }
+ } else {
+ int h = qname.indexOf('#');
+ if (h != -1) {
+ return new QName(qname.substring(0, h), qname.substring(h + 1));
+ }
+ }
+ throw new IllegalArgumentException("Invalid qname: " + qname);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerTuple.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerTuple.java
new file mode 100644
index 0000000000..c80e68a0be
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerTuple.java
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.util;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
+
+/**
+ * PolicyHanlder tuples stored in policy handler services files
+ *
+ * @version $Rev$ $Date$
+ */
+public class PolicyHandlerTuple {
+ private ServiceDeclaration declaration;
+ private String policyHandlerClassName;
+ private QName providedIntentName;
+ private String policyModelClassName;
+ private String appliesTo;
+
+ public PolicyHandlerTuple(ServiceDeclaration declaration,
+ String handlerClassName,
+ QName providedIntentName,
+ String policyModelClassName,
+ String appliesTo) {
+ this.declaration = declaration;
+ this.policyHandlerClassName = handlerClassName;
+ this.providedIntentName = providedIntentName;
+ this.policyModelClassName = policyModelClassName;
+ this.appliesTo = appliesTo;
+ }
+
+ public ServiceDeclaration getDeclaration() {
+ return declaration;
+ }
+
+ public void setDeclaration(ServiceDeclaration declaration) {
+ this.declaration = declaration;
+ }
+
+ public String getAppliesTo() {
+ return appliesTo;
+ }
+
+ public void setAppliesTo(String appliesTo) {
+ this.appliesTo = appliesTo;
+ }
+
+
+ public String getPolicyHandlerClassName() {
+ return policyHandlerClassName;
+ }
+ public void setPolicyHandlerClassName(String policyHandlerClassName) {
+ this.policyHandlerClassName = policyHandlerClassName;
+ }
+ public String getPolicyModelClassName() {
+ return policyModelClassName;
+ }
+ public void setPolicyModelClassName(String policyModelClassName) {
+ this.policyModelClassName = policyModelClassName;
+ }
+ public QName getProvidedIntentName() {
+ return providedIntentName;
+ }
+ public void setProvidedIntentName(QName providedIntentName) {
+ this.providedIntentName = providedIntentName;
+ }
+
+ @Override
+ public String toString() {
+ return policyHandlerClassName + ", " + providedIntentName + ", " + policyModelClassName + ", " + appliesTo;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerUtils.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerUtils.java
new file mode 100644
index 0000000000..6d6420017f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyHandlerUtils.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.util;
+
+import java.util.List;
+
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.PolicySet;
+
+/**
+ * Utility methods to deal with PolicyHandlers
+ *
+ * @version $Rev$ $Date$
+ */
+public class PolicyHandlerUtils {
+ public static PolicyHandler findPolicyHandler(PolicySet policySet, List<PolicyHandlerTuple> policyHandlerClassNames)
+ throws IllegalAccessException, ClassNotFoundException, InstantiationException {
+
+ PolicyHandler handler = null;
+
+ for (PolicyHandlerTuple handlerTuple : policyHandlerClassNames) {
+ //System.out.println(handlerTuple);
+ for (Intent intent : policySet.getProvidedIntents()) {
+ if (intent.getName().equals(handlerTuple.getProvidedIntentName())) {
+ for (Object policy : policySet.getPolicies()) {
+ if (policy.getClass().getName().equals(handlerTuple.getPolicyModelClassName())) {
+ if (handlerTuple.getAppliesTo() != null) {
+ if (handlerTuple.getAppliesTo().equals(policySet.getAppliesTo())) {
+ handler = (PolicyHandler)handlerTuple.getDeclaration().loadClass().newInstance();
+ handler.setApplicablePolicySet(policySet);
+ return handler;
+ }
+ } else {
+ handler = (PolicyHandler)handlerTuple.getDeclaration().loadClass().newInstance();
+ handler.setApplicablePolicySet(policySet);
+ return handler;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return handler;
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationException.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationException.java
new file mode 100644
index 0000000000..eb97818042
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationException.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.util;
+
+/**
+ * Exception to be throw for invalid policy intents / policysets
+ *
+ * @version $Rev$ $Date$
+ */
+public class PolicyValidationException extends Exception {
+ private static final long serialVersionUID = 506979037642587755L;
+
+ public PolicyValidationException(String message) {
+ super(message);
+ }
+
+ public PolicyValidationException(Throwable e) {
+ super(e);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationUtils.java b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationUtils.java
new file mode 100644
index 0000000000..afb3c035ae
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/java/org/apache/tuscany/sca/policy/util/PolicyValidationUtils.java
@@ -0,0 +1,111 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.policy.util;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.policy.Intent;
+import org.apache.tuscany.sca.policy.IntentAttachPoint;
+import org.apache.tuscany.sca.policy.IntentAttachPointType;
+import org.apache.tuscany.sca.policy.PolicySet;
+import org.apache.tuscany.sca.policy.PolicySetAttachPoint;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class PolicyValidationUtils {
+
+ public static boolean isConstrained(QName constrained, IntentAttachPointType attachPointType) {
+ return (attachPointType != null && attachPointType.getName().getNamespaceURI()
+ .equals(constrained.getNamespaceURI()) && attachPointType.getName().getLocalPart()
+ .startsWith(constrained.getLocalPart()));
+ }
+
+ public static void validateIntents(IntentAttachPoint attachPoint,
+ IntentAttachPointType attachPointType)
+ throws PolicyValidationException {
+ boolean found = false;
+ if (attachPointType != null) {
+ // validate intents specified against the parent (binding /
+ // implementation)
+ found = false;
+ for (Intent intent : attachPoint.getRequiredIntents()) {
+ if (!intent.isUnresolved()) {
+ for (QName constrained : intent.getConstrains()) {
+ if (isConstrained(constrained, attachPointType)) {
+ found = true;
+ break;
+ }
+ }
+
+ if (!found) {
+ throw new PolicyValidationException("Policy Intent '" + intent.getName()
+ + "' does not constrain extension type "
+ + attachPointType.getName());
+ }
+ } else {
+ throw new PolicyValidationException("Policy Intent '" + intent.getName()
+ + "' is not defined in this domain ");
+ }
+ }
+ }
+ }
+
+ public static void validatePolicySets(PolicySetAttachPoint policySetAttachPoint)
+ throws PolicyValidationException {
+ validatePolicySets(policySetAttachPoint,
+ policySetAttachPoint.getType(),
+ policySetAttachPoint.getApplicablePolicySets());
+ }
+
+ public static void validatePolicySets(PolicySetAttachPoint policySetAttachPoint,
+ IntentAttachPointType attachPointType)
+ throws PolicyValidationException {
+ validatePolicySets(policySetAttachPoint,
+ attachPointType,
+ policySetAttachPoint.getApplicablePolicySets());
+ }
+
+ public static void validatePolicySets(PolicySetAttachPoint policySetAttachPoint,
+ IntentAttachPointType attachPointType,
+ List<PolicySet> applicablePolicySets)
+ throws PolicyValidationException {
+ // Since the applicablePolicySets in a policySetAttachPoint will already
+ // have the list of policysets that might ever be applicable to this attachPoint,
+ // just check if the defined policysets feature in the list of applicable
+ // policysets
+ for (PolicySet definedPolicySet : policySetAttachPoint.getPolicySets()) {
+ if (!definedPolicySet.isUnresolved()) {
+ if (!applicablePolicySets.contains(definedPolicySet)) {
+ throw new PolicyValidationException("Policy Set '" + definedPolicySet
+ .getName()
+ + "' does not apply to extension type "
+ + attachPointType.getName());
+ }
+ } else {
+ throw new PolicyValidationException("Policy Set '" + definedPolicySet.getName()
+ + "' is not defined in this domain ");
+
+ }
+ }
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory b/sca-java-1.x/branches/sca-android/modules/policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory
new file mode 100644
index 0000000000..a0e56c1822
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.policy.DefaultIntentAttachPointTypeFactory \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.PolicyFactory b/sca-java-1.x/branches/sca-android/modules/policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.PolicyFactory
new file mode 100644
index 0000000000..846b3b24a4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/main/resources/META-INF/services/org.apache.tuscany.sca.policy.PolicyFactory
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+org.apache.tuscany.sca.policy.DefaultPolicyFactory \ No newline at end of file
diff --git a/sca-java-1.x/branches/sca-android/modules/policy/src/test/java/org/apache/tuscany/sca/policy/PolicyFactoryTestCase.java b/sca-java-1.x/branches/sca-android/modules/policy/src/test/java/org/apache/tuscany/sca/policy/PolicyFactoryTestCase.java
new file mode 100644
index 0000000000..636ff5ab45
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/policy/src/test/java/org/apache/tuscany/sca/policy/PolicyFactoryTestCase.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.policy;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+/**
+ * Test building of policy model instances using the policy factory.
+ *
+ * @version $Rev$ $Date$
+ */
+public class PolicyFactoryTestCase extends TestCase {
+
+ PolicyFactory factory;
+
+ @Override
+ public void setUp() throws Exception {
+ factory = new DefaultPolicyFactory();
+ }
+
+ public void testCreateIntent() {
+ Intent intent = factory.createIntent();
+ intent.setName(new QName("http://test", "reliability"));
+ assertEquals(intent.getName(), new QName("http://test", "reliability"));
+ }
+
+ public void testCreatePolicySet() {
+ PolicySet policySet = factory.createPolicySet();
+ policySet.setName(new QName("http://test", "reliability"));
+ assertEquals(policySet.getName(), new QName("http://test", "reliability"));
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/pom.xml b/sca-java-1.x/branches/sca-android/modules/pom.xml
new file mode 100644
index 0000000000..fffe442b51
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/pom.xml
@@ -0,0 +1,149 @@
+<?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.sca</groupId>
+ <artifactId>tuscany-sca</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <artifactId>tuscany-modules</artifactId>
+ <packaging>pom</packaging>
+ <name>Apache Tuscany SCA Implementation Modules</name>
+
+ <properties>
+ <tuscany.version>1.4</tuscany.version>
+ </properties>
+
+ <profiles>
+ <profile>
+ <id>default</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <modules>
+ <module>assembly</module>
+ <module>assembly-xml</module>
+ <module>assembly-xsd</module>
+ <module>contribution</module>
+ <module>contribution-java</module>
+ <module>contribution-impl</module>
+ <module>contribution-xml</module>
+ <module>core</module>
+ <module>core-databinding</module>
+ <module>core-spi</module>
+ <module>databinding</module>
+ <module>definitions</module>
+ <module>definitions-xml</module>
+ <module>endpoint</module>
+ <module>extensibility</module>
+ <module>host-embedded</module>
+ <module>interface</module>
+ <module>interface-java</module>
+ <module>interface-java-xml</module>
+ <module>implementation-java</module>
+ <module>implementation-java-xml</module>
+ <module>implementation-java-runtime</module>
+ <module>implementation-node</module>
+ <module>implementation-node-runtime</module>
+ <module>monitor</module>
+ <module>node-api</module>
+ <module>node-impl</module>
+ <module>node-launcher</module>
+ <module>policy</module>
+ <module>policy-xml</module>
+ <module>sca-api</module>
+ </modules>
+ </profile>
+
+ </profiles>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.2</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.easymock</groupId>
+ <artifactId>easymock</artifactId>
+ <version>2.2</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+
+ <build>
+ <plugins>
+ <plugin>
+ <artifactId>maven-eclipse-plugin</artifactId>
+ <version>2.5.1</version>
+ <configuration>
+ <buildcommands>
+ <buildcommand>org.eclipse.pde.ManifestBuilder</buildcommand>
+ <buildcommand>org.eclipse.jdt.core.javabuilder</buildcommand>
+ </buildcommands>
+ <projectnatures>
+ <projectnature>org.eclipse.jdt.core.javanature</projectnature>
+ <projectnature>org.eclipse.pde.PluginNature</projectnature>
+ </projectnatures>
+ <classpathContainers>
+ <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
+ <!--
+ <classpathContainer>org.eclipse.pde.core.requiredPlugins</classpathContainer>
+ -->
+ </classpathContainers>
+ </configuration>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <version>1.4.3</version>
+ <extensions>true</extensions>
+ <executions>
+ <execution>
+ <id>bundle-manifest</id>
+ <phase>process-classes</phase>
+ <goals>
+ <goal>manifest</goal>
+ </goals>
+ <configuration>
+ <manifestLocation>${basedir}/META-INF</manifestLocation>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ <plugin>
+ <artifactId>maven-jar-plugin</artifactId>
+ <configuration>
+ <archive>
+ <manifestFile>${basedir}/META-INF/MANIFEST.MF</manifestFile>
+ </archive>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/LICENSE b/sca-java-1.x/branches/sca-android/modules/sca-api/LICENSE
new file mode 100644
index 0000000000..8aa906c321
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/LICENSE
@@ -0,0 +1,205 @@
+
+ Apache License
+ Version 2.0, January 2004
+ http://www.apache.org/licenses/
+
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+ 1. Definitions.
+
+ "License" shall mean the terms and conditions for use, reproduction,
+ and distribution as defined by Sections 1 through 9 of this document.
+
+ "Licensor" shall mean the copyright owner or entity authorized by
+ the copyright owner that is granting the License.
+
+ "Legal Entity" shall mean the union of the acting entity and all
+ other entities that control, are controlled by, or are under common
+ control with that entity. For the purposes of this definition,
+ "control" means (i) the power, direct or indirect, to cause the
+ direction or management of such entity, whether by contract or
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
+ outstanding shares, or (iii) beneficial ownership of such entity.
+
+ "You" (or "Your") shall mean an individual or Legal Entity
+ exercising permissions granted by this License.
+
+ "Source" form shall mean the preferred form for making modifications,
+ including but not limited to software source code, documentation
+ source, and configuration files.
+
+ "Object" form shall mean any form resulting from mechanical
+ transformation or translation of a Source form, including but
+ not limited to compiled object code, generated documentation,
+ and conversions to other media types.
+
+ "Work" shall mean the work of authorship, whether in Source or
+ Object form, made available under the License, as indicated by a
+ copyright notice that is included in or attached to the work
+ (an example is provided in the Appendix below).
+
+ "Derivative Works" shall mean any work, whether in Source or Object
+ form, that is based on (or derived from) the Work and for which the
+ editorial revisions, annotations, elaborations, or other modifications
+ represent, as a whole, an original work of authorship. For the purposes
+ of this License, Derivative Works shall not include works that remain
+ separable from, or merely link (or bind by name) to the interfaces of,
+ the Work and Derivative Works thereof.
+
+ "Contribution" shall mean any work of authorship, including
+ the original version of the Work and any modifications or additions
+ to that Work or Derivative Works thereof, that is intentionally
+ submitted to Licensor for inclusion in the Work by the copyright owner
+ or by an individual or Legal Entity authorized to submit on behalf of
+ the copyright owner. For the purposes of this definition, "submitted"
+ means any form of electronic, verbal, or written communication sent
+ to the Licensor or its representatives, including but not limited to
+ communication on electronic mailing lists, source code control systems,
+ and issue tracking systems that are managed by, or on behalf of, the
+ Licensor for the purpose of discussing and improving the Work, but
+ excluding communication that is conspicuously marked or otherwise
+ designated in writing by the copyright owner as "Not a Contribution."
+
+ "Contributor" shall mean Licensor and any individual or Legal Entity
+ on behalf of whom a Contribution has been received by Licensor and
+ subsequently incorporated within the Work.
+
+ 2. Grant of Copyright License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ copyright license to reproduce, prepare Derivative Works of,
+ publicly display, publicly perform, sublicense, and distribute the
+ Work and such Derivative Works in Source or Object form.
+
+ 3. Grant of Patent License. Subject to the terms and conditions of
+ this License, each Contributor hereby grants to You a perpetual,
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+ (except as stated in this section) patent license to make, have made,
+ use, offer to sell, sell, import, and otherwise transfer the Work,
+ where such license applies only to those patent claims licensable
+ by such Contributor that are necessarily infringed by their
+ Contribution(s) alone or by combination of their Contribution(s)
+ with the Work to which such Contribution(s) was submitted. If You
+ institute patent litigation against any entity (including a
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
+ or a Contribution incorporated within the Work constitutes direct
+ or contributory patent infringement, then any patent licenses
+ granted to You under this License for that Work shall terminate
+ as of the date such litigation is filed.
+
+ 4. Redistribution. You may reproduce and distribute copies of the
+ Work or Derivative Works thereof in any medium, with or without
+ modifications, and in Source or Object form, provided that You
+ meet the following conditions:
+
+ (a) You must give any other recipients of the Work or
+ Derivative Works a copy of this License; and
+
+ (b) You must cause any modified files to carry prominent notices
+ stating that You changed the files; and
+
+ (c) You must retain, in the Source form of any Derivative Works
+ that You distribute, all copyright, patent, trademark, and
+ attribution notices from the Source form of the Work,
+ excluding those notices that do not pertain to any part of
+ the Derivative Works; and
+
+ (d) If the Work includes a "NOTICE" text file as part of its
+ distribution, then any Derivative Works that You distribute must
+ include a readable copy of the attribution notices contained
+ within such NOTICE file, excluding those notices that do not
+ pertain to any part of the Derivative Works, in at least one
+ of the following places: within a NOTICE text file distributed
+ as part of the Derivative Works; within the Source form or
+ documentation, if provided along with the Derivative Works; or,
+ within a display generated by the Derivative Works, if and
+ wherever such third-party notices normally appear. The contents
+ of the NOTICE file are for informational purposes only and
+ do not modify the License. You may add Your own attribution
+ notices within Derivative Works that You distribute, alongside
+ or as an addendum to the NOTICE text from the Work, provided
+ that such additional attribution notices cannot be construed
+ as modifying the License.
+
+ You may add Your own copyright statement to Your modifications and
+ may provide additional or different license terms and conditions
+ for use, reproduction, or distribution of Your modifications, or
+ for any such Derivative Works as a whole, provided Your use,
+ reproduction, and distribution of the Work otherwise complies with
+ the conditions stated in this License.
+
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
+ any Contribution intentionally submitted for inclusion in the Work
+ by You to the Licensor shall be under the terms and conditions of
+ this License, without any additional terms or conditions.
+ Notwithstanding the above, nothing herein shall supersede or modify
+ the terms of any separate license agreement you may have executed
+ with Licensor regarding such Contributions.
+
+ 6. Trademarks. This License does not grant permission to use the trade
+ names, trademarks, service marks, or product names of the Licensor,
+ except as required for reasonable and customary use in describing the
+ origin of the Work and reproducing the content of the NOTICE file.
+
+ 7. Disclaimer of Warranty. Unless required by applicable law or
+ agreed to in writing, Licensor provides the Work (and each
+ Contributor provides its Contributions) on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ implied, including, without limitation, any warranties or conditions
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+ PARTICULAR PURPOSE. You are solely responsible for determining the
+ appropriateness of using or redistributing the Work and assume any
+ risks associated with Your exercise of permissions under this License.
+
+ 8. Limitation of Liability. In no event and under no legal theory,
+ whether in tort (including negligence), contract, or otherwise,
+ unless required by applicable law (such as deliberate and grossly
+ negligent acts) or agreed to in writing, shall any Contributor be
+ liable to You for damages, including any direct, indirect, special,
+ incidental, or consequential damages of any character arising as a
+ result of this License or out of the use or inability to use the
+ Work (including but not limited to damages for loss of goodwill,
+ work stoppage, computer failure or malfunction, or any and all
+ other commercial damages or losses), even if such Contributor
+ has been advised of the possibility of such damages.
+
+ 9. Accepting Warranty or Additional Liability. While redistributing
+ the Work or Derivative Works thereof, You may choose to offer,
+ and charge a fee for, acceptance of support, warranty, indemnity,
+ or other liability obligations and/or rights consistent with this
+ License. However, in accepting such obligations, You may act only
+ on Your own behalf and on Your sole responsibility, not on behalf
+ of any other Contributor, and only if You agree to indemnify,
+ defend, and hold each Contributor harmless for any liability
+ incurred by, or claims asserted against, such Contributor by reason
+ of your accepting any such warranty or additional liability.
+
+ END OF TERMS AND CONDITIONS
+
+ APPENDIX: How to apply the Apache License to your work.
+
+ To apply the Apache License to your work, attach the following
+ boilerplate notice, with the fields enclosed by brackets "[]"
+ replaced with your own identifying information. (Don't include
+ the brackets!) The text should be enclosed in the appropriate
+ comment syntax for the file format. We also recommend that a
+ file or class name and description of purpose be included on the
+ same "printed page" as the copyright notice for easier
+ identification within third-party archives.
+
+ Copyright [yyyy] [name of copyright owner]
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+
+
+
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/META-INF/README b/sca-java-1.x/branches/sca-android/modules/sca-api/META-INF/README
new file mode 100644
index 0000000000..009570154d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/META-INF/README
@@ -0,0 +1 @@
+This directory contains a generated MANIFEST.MF file.
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/NOTICE b/sca-java-1.x/branches/sca-android/modules/sca-api/NOTICE
new file mode 100644
index 0000000000..fdfa0e9faa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/NOTICE
@@ -0,0 +1,6 @@
+${pom.name}
+Copyright (c) 2005 - 2008 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
+
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/pom.xml b/sca-java-1.x/branches/sca-android/modules/sca-api/pom.xml
new file mode 100644
index 0000000000..54e43ce91c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/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>
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-modules</artifactId>
+ <version>1.4-SNAPSHOT</version>
+ <relativePath>../pom.xml</relativePath>
+ </parent>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-sca-api</artifactId>
+ <name>Apache Tuscany SCA API</name>
+
+ <description>API classes for the Service Component Architecture</description>
+ <packaging>jar</packaging>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+
+ <configuration>
+ <instructions>
+ <Bundle-Version>1.4</Bundle-Version>
+ <Bundle-SymbolicName>org.apache.tuscany.sca.api</Bundle-SymbolicName>
+ <Bundle-Description>${pom.description}</Bundle-Description>
+ <Export-Package>org.osoa.sca*</Export-Package>
+ </instructions>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+
+</project>
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/CallableReference.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/CallableReference.java
new file mode 100644
index 0000000000..c32d229a76
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/CallableReference.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.osoa.sca;
+
+/**
+ * Common superclass for references that can be passed between components.
+ *
+ * @version $Rev$ $Date$
+ * @param <B> the Java interface associated with this reference
+ */
+public interface CallableReference<B> {
+ /**
+ * Returns a type-safe reference to the target of this reference.
+ * The instance returned is guaranteed to implement the business interface for this reference
+ * but may not be a proxy as defined by java.lang.reflect.Proxy.
+ *
+ * @return a proxy to the target that implements the business interface associated with this reference
+ */
+ B getService();
+
+ /**
+ * Returns the Java class for the business interface associated with this reference.
+ *
+ * @return the Class for the business interface associated with this reference
+ */
+ Class<B> getBusinessInterface();
+
+ /**
+ * Returns true if this reference is conversational.
+ *
+ * @return true if this reference is conversational
+ */
+ boolean isConversational();
+
+ /**
+ * Returns the conversation associated with this reference.
+ * Returns null if no conversation is currently active.
+ *
+ * @return the conversation associated with this reference; may be null
+ */
+ Conversation getConversation();
+
+ /**
+ * Returns the callback ID.
+ *
+ * @return the callback ID
+ */
+ Object getCallbackID();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/ComponentContext.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/ComponentContext.java
new file mode 100644
index 0000000000..616d4c6338
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/ComponentContext.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.osoa.sca;
+
+/**
+ * Interface providing programmatic access to a component's SCA context as an alternative to injection.
+ * It provides access to reference and property values for the component and provides a mechanism for
+ * obtaining a reference to a service that can be passed to other components.
+ * <p/>
+ * SCA components obtain an instance of this interface through injection. Non-SCA client code may also
+ * obtain an instance through runtime-specific mechanisms.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface ComponentContext {
+ /**
+ * Returns the absolute URI of the component within the SCA Domain.
+ *
+ * @return the absolute URI of the component
+ */
+ String getURI();
+
+ /**
+ * Cast a type-safe reference to a CallableReference.
+ * Converts a type-safe reference to an equivalent CallableReference; if the target refers to a service
+ * then a ServiceReference will be returned, if the target refers to a callback then a CallableReference
+ * will be returned.
+ *
+ * @param target a reference proxy provided by the SCA runtime
+ * @param <B> the Java type of the business interface for the reference
+ * @param <R> the type of reference to be returned
+ * @return a CallableReference equivalent for the proxy
+ * @throws IllegalArgumentException if the supplied instance is not a reference supplied by the SCA runtime
+ */
+ <B, R extends CallableReference<B>> R cast(B target) throws IllegalArgumentException;
+
+ /**
+ * Returns a proxy for a reference defined by this component.
+ *
+ * @param businessInterface the interface that will be used to invoke the service
+ * @param referenceName the name of the reference
+ * @param <B> the Java type of the business interface for the reference
+ * @return an object that implements the business interface
+ */
+ <B> B getService(Class<B> businessInterface, String referenceName);
+
+ /**
+ * Returns a ServiceReference for a reference defined by this component.
+ *
+ * @param businessInterface the interface that will be used to invoke the service
+ * @param referenceName the name of the reference
+ * @param <B> the Java type of the business interface for the reference
+ * @return a ServiceReference for the designated reference
+ */
+ <B> ServiceReference<B> getServiceReference(Class<B> businessInterface, String referenceName);
+
+ /**
+ * Returns the value of an SCA property defined by this component.
+ *
+ * @param type the Java type to be returned for the property
+ * @param propertyName the name of the property whose value should be returned
+ * @param <B> the Java type of the property
+ * @return the property value
+ */
+ <B> B getProperty(Class<B> type, String propertyName);
+
+ /**
+ * Returns a ServiceReference that can be used to invoke this component over the default service.
+ *
+ * @param businessInterface the interface that will be used to invoke the service
+ * @param <B> the Java type of the business interface for the reference
+ * @return a ServiceReference that will invoke this component
+ */
+ <B> ServiceReference<B> createSelfReference(Class<B> businessInterface);
+
+ /**
+ * Returns a ServiceReference that can be used to invoke this component over the designated service.
+ *
+ * @param businessInterface the interface that will be used to invoke the service
+ * @param serviceName the name of the service to invoke
+ * @param <B> the Java type of the business interface for the reference
+ * @return a ServiceReference that will invoke this component
+ */
+ <B> ServiceReference<B> createSelfReference(Class<B> businessInterface, String serviceName);
+
+ /**
+ * Returns the context for the current SCA service request, or null if there is no current request
+ * or if the context is unavailable.
+ *
+ * @return the SCA request context; may be null
+ */
+ RequestContext getRequestContext();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/Constants.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/Constants.java
new file mode 100644
index 0000000000..b1b2af8048
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/Constants.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.osoa.sca;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface Constants {
+ /**
+ * Namespace for intents.
+ */
+ String SCA_NS = "http://www.osoa.org/xmlns/sca/1.0";
+
+ /**
+ * Prefix form of the namespace that can be prepended to intent declarations.
+ */
+ String SCA_PREFIX = '{' + SCA_NS + '}';
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/Conversation.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/Conversation.java
new file mode 100644
index 0000000000..64423a4aa2
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/Conversation.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.osoa.sca;
+
+/**
+ * Interface representing a Conversation providing access to the conversation id and and a mechanism
+ * to terminate the conversation.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface Conversation {
+ /**
+ * Returns the identifier for this conversation.
+ * If a user-defined identity had been supplied for this reference then its value will be returned;
+ * otherwise the identity generated by the system when the conversation was initiated will be returned.
+ *
+ * @return the identifier for this conversation
+ */
+ Object getConversationID();
+
+ /**
+ * End this conversation.
+ */
+ void end();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/ConversationEndedException.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/ConversationEndedException.java
new file mode 100644
index 0000000000..63e3907cff
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/ConversationEndedException.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.osoa.sca;
+
+/**
+ * Exception thrown to indicate the conversation being used for a stateful interaction has been ended.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ConversationEndedException extends ServiceRuntimeException {
+ private static final long serialVersionUID = 3734864942222558406L;
+
+ /**
+ * Override constructor from ServiceRuntimeException.
+ *
+ * @see ServiceRuntimeException
+ */
+ public ConversationEndedException() {
+ }
+
+ /**
+ * Override constructor from ServiceRuntimeException.
+ *
+ * @param message passed to ServiceRuntimeException
+ * @see ServiceRuntimeException
+ */
+ public ConversationEndedException(String message) {
+ super(message);
+ }
+
+ /**
+ * Override constructor from ServiceRuntimeException.
+ *
+ * @param message passed to ServiceRuntimeException
+ * @param cause passed to ServiceRuntimeException
+ * @see ServiceRuntimeException
+ */
+ public ConversationEndedException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Override constructor from ServiceRuntimeException.
+ *
+ * @param cause passed to ServiceRuntimeException
+ * @see ServiceRuntimeException
+ */
+ public ConversationEndedException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/NoRegisteredCallbackException.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/NoRegisteredCallbackException.java
new file mode 100644
index 0000000000..7c067a3a43
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/NoRegisteredCallbackException.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.osoa.sca;
+
+/**
+ * Exception thrown to indicate that no callback has been registered
+ * when interacting with a service.
+ *
+ * @version $Rev$ $Date$
+ */
+public class NoRegisteredCallbackException extends ServiceRuntimeException {
+ private static final long serialVersionUID = 3734864942222558406L;
+
+ /**
+ * Override constructor from ServiceRuntimeException.
+ *
+ * @see ServiceRuntimeException
+ */
+ public NoRegisteredCallbackException() {
+ }
+
+ /**
+ * Override constructor from ServiceRuntimeException.
+ *
+ * @param message passed to ServiceRuntimeException
+ * @see ServiceRuntimeException
+ */
+ public NoRegisteredCallbackException(String message) {
+ super(message);
+ }
+
+ /**
+ * Override constructor from ServiceRuntimeException.
+ *
+ * @param message passed to ServiceRuntimeException
+ * @param cause passed to ServiceRuntimeException
+ * @see ServiceRuntimeException
+ */
+ public NoRegisteredCallbackException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Override constructor from ServiceRuntimeException.
+ *
+ * @param cause passed to ServiceRuntimeException
+ * @see ServiceRuntimeException
+ */
+ public NoRegisteredCallbackException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/RequestContext.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/RequestContext.java
new file mode 100644
index 0000000000..900d5eecc1
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/RequestContext.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.osoa.sca;
+
+import javax.security.auth.Subject;
+
+/**
+ * Interface that provides information on the current request.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface RequestContext {
+ /**
+ * Returns the JAAS Subject of the current request.
+ *
+ * @return the Subject of the current request
+ */
+ Subject getSecuritySubject();
+
+ /**
+ * Returns the name of the service that was invoked.
+ *
+ * @return the name of the service that was invoked
+ */
+ String getServiceName();
+
+ /**
+ * Returns a CallableReference for the service that was invoked by the caller.
+ *
+ * @param <B> the Java type of the business interface for the reference
+ * @return a CallableReference for the service that was invoked by the caller
+ */
+ <B> CallableReference<B> getServiceReference();
+
+ /**
+ * Returns a type-safe reference to the callback provided by the caller.
+ *
+ * @param <CB> the Java type of the business interface for the callback
+ * @return a type-safe reference to the callback provided by the caller
+ */
+ <CB> CB getCallback();
+
+ /**
+ * Returns a CallableReference to the callback provided by the caller.
+ *
+ * @param <CB> the Java type of the business interface for the callback
+ * @return a CallableReference to the callback provided by the caller
+ */
+ <CB> CallableReference<CB> getCallbackReference();
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/ServiceReference.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/ServiceReference.java
new file mode 100644
index 0000000000..8790aac4fb
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/ServiceReference.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.osoa.sca;
+
+
+/**
+ * A ServiceReference represents a client's perspective of a reference to another service.
+ *
+ * @version $Rev$ $Date$
+ * @param <B> the Java interface associated with this reference
+ */
+public interface ServiceReference<B> extends CallableReference<B> {
+ /**
+ * Returns the id supplied by the user that will be associated with conversations initiated through this reference.
+ *
+ * @return the id to associated with any conversation initiated through this reference
+ */
+ Object getConversationID();
+
+ /**
+ * Set the id to associate with any conversation started through this reference.
+ * If the value supplied is null then the id will be generated by the implementation.
+ *
+ * @param conversationId the user-defined id to associated with a conversation
+ * @throws IllegalStateException if a conversation is currently associated with this reference
+ */
+ void setConversationID(Object conversationId) throws IllegalStateException;
+
+ /**
+ * Sets the callback ID.
+ *
+ * @param callbackID the callback ID
+ */
+ void setCallbackID(Object callbackID);
+
+ /**
+ * Returns the callback object.
+ *
+ * @return the callback object
+ */
+ Object getCallback();
+
+ /**
+ * Sets the callback object.
+ *
+ * @param callback the callback object
+ */
+ void setCallback(Object callback);
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/ServiceRuntimeException.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/ServiceRuntimeException.java
new file mode 100644
index 0000000000..1c6b436afa
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/ServiceRuntimeException.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.osoa.sca;
+
+
+/**
+ * Base for Exceptions that may be raised by an SCA runtime and which typical
+ * application code is not expected to be able to handle.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ServiceRuntimeException extends RuntimeException {
+ private static final long serialVersionUID = -3876058842262557092L;
+
+ /**
+ * Override constructor from RuntimeException.
+ *
+ * @see RuntimeException
+ */
+ public ServiceRuntimeException() {
+ }
+
+ /**
+ * Override constructor from RuntimeException.
+ *
+ * @param message passed to RuntimeException
+ * @see RuntimeException
+ */
+ public ServiceRuntimeException(String message) {
+ super(message);
+ }
+
+ /**
+ * Override constructor from RuntimeException.
+ *
+ * @param message passed to RuntimeException
+ * @param cause passed to RuntimeException
+ * @see RuntimeException
+ */
+ public ServiceRuntimeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Override constructor from RuntimeException.
+ *
+ * @param cause passed to RuntimeException
+ * @see RuntimeException
+ */
+ public ServiceRuntimeException(Throwable cause) {
+ super(cause);
+ }
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/ServiceUnavailableException.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/ServiceUnavailableException.java
new file mode 100644
index 0000000000..d3543799ed
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/ServiceUnavailableException.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.osoa.sca;
+
+/**
+ * Exception used to indicate that a runtime exception occurred during the invocation of and external service.
+ *
+ * @version $Rev$ $Date$
+ */
+public class ServiceUnavailableException extends ServiceRuntimeException {
+
+ private static final long serialVersionUID = -5869397223249401047L;
+
+ /**
+ * Constructs a new ServiceUnavailableException.
+ */
+ public ServiceUnavailableException() {
+ super((Throwable) null);
+ }
+
+ /**
+ * Constructs a new ServiceUnavailableException with the specified detail message.
+ *
+ * @param message The detail message (which is saved to later retrieval by the getMessage() method).
+ */
+ public ServiceUnavailableException(String message) {
+ super(message);
+ }
+
+ /**
+ * Constructs a new ServiceUnavailableException with the specified cause.
+ *
+ * @param cause The cause (which is saved to later retrieval by the getCause() method).
+ */
+ public ServiceUnavailableException(Throwable cause) {
+ super(cause);
+ }
+
+ /**
+ * Constructs a new ServiceUnavailableException with the specified detail message and cause.
+ *
+ * @param message The message (which is saved to later retrieval by the getMessage() method).
+ * @param cause The cause (which is saved to later retrieval by the getCause() method).
+ */
+ public ServiceUnavailableException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/AllowsPassByReference.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/AllowsPassByReference.java
new file mode 100644
index 0000000000..bab9713026
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/AllowsPassByReference.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation on a method that indicates that its parameters may safely
+ * be passed by reference. The annotation may also be placed on an interface
+ * or class to indicate that all declared methods support this optimization.
+ *
+ * @version $Rev$ $Date$
+ */
+@Target({TYPE, METHOD})
+@Retention(RUNTIME)
+public @interface AllowsPassByReference {
+}
+
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Authentication.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Authentication.java
new file mode 100644
index 0000000000..1d1ecdbc13
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Authentication.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static org.osoa.sca.Constants.SCA_PREFIX;
+
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation denoting the intent that service operations require authentication.
+ * <p/>
+ * Applied to the injection site (field, method or constructor parameter) for a reference,
+ * it indicates that all invocations through that reference require authentication.
+ * <p/>
+ * Applied to a interface method on a service contract, it indicates that all invocations
+ * of that service operation require authentication; applied to the type of a service contract,
+ * it indicates that all service operations on that interface require authentication.
+ * <p/>
+ * Applied to a method on an implementation class, it indicates that all invocations that
+ * are dispatched to that implementation method (through any service) require authentication.
+ * Applied to a interface implemented by an implementation class, it indicates that all
+ * invocations that are dispatched to the implementation method for that interface operation
+ * require authentication.
+ * <p/>
+ * Applied to an implementation class, it indicates that all invocations of that implementation
+ * and that all invocations made by that implementation require authentication.
+ *
+ * @version $Rev$ $Date$
+ */
+@Inherited
+@Target({TYPE, FIELD, METHOD, PARAMETER})
+@Retention(RUNTIME)
+@Intent(Authentication.AUTHENTICATION)
+public @interface Authentication {
+ String AUTHENTICATION = SCA_PREFIX + "authentication";
+ String AUTHENTICATION_MESSAGE = AUTHENTICATION + "message";
+ String AUTHENTICATION_TRANSPORT = AUTHENTICATION + "transport";
+
+ /**
+ * List of authentication qualifiers (such as "message" or "transport").
+ *
+ * @return authentication qualifiers
+ */
+ @Qualifier
+ String[] value() default "";
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Callback.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Callback.java
new file mode 100644
index 0000000000..a9fc36f769
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Callback.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * When placed on a service interface, this annotation specifies the interface
+ * to be used for callbacks.
+ * <p/>
+ * When placed on a method or field, this annotation denotes the injection
+ * site to be used for a callback reference.
+ * <p/>
+ * There is a error in the 1.00 draft spec in the declaration of this interface.
+ * The form defined here is a proposed correction for that error.
+ *
+ * @version $Rev$ $Date$
+ */
+@Target({TYPE, METHOD, FIELD})
+@Retention(RUNTIME)
+public @interface Callback {
+ /**
+ * The Class of the associated callback interface.
+ *
+ * @return the associated callback interface
+ */
+ Class<?> value() default Void.class;
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/ComponentName.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/ComponentName.java
new file mode 100644
index 0000000000..477053670a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/ComponentName.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation used to indicate a field or method that is used to inject the component's name.
+ *
+ * @version $Rev$ $Date$
+ */
+@Target({METHOD, FIELD})
+@Retention(RUNTIME)
+public @interface ComponentName {
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Confidentiality.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Confidentiality.java
new file mode 100644
index 0000000000..f54e421c81
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Confidentiality.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static org.osoa.sca.Constants.SCA_PREFIX;
+
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation denoting the intent that service operations require confidentiality.
+ * <p/>
+ * Applied to the injection site (field, method or constructor parameter) for a reference,
+ * it indicates that all invocations through that reference require confidentiality.
+ * <p/>
+ * Applied to a interface method on a service contract, it indicates that all invocations
+ * of that service operation require confidentiality; applied to the type of a service contract,
+ * it indicates that all service operations on that interface require confidentiality.
+ * <p/>
+ * Applied to a method on an implementation class, it indicates that all invocations that
+ * are dispatched to that implementation method (through any service) require confidentiality.
+ * Applied to a interface implemented by an implementation class, it indicates that all
+ * invocations that are dispatched to the implementation method for that interface operation
+ * require confidentiality.
+ * <p/>
+ * Applied to an implementation class, it indicates that all invocations of that implementation
+ * and that all invocations made by that implementation require confidentiality.
+ *
+ * @version $Rev$ $Date$
+ */
+@Inherited
+@Target({TYPE, FIELD, METHOD, PARAMETER})
+@Retention(RUNTIME)
+@Intent(Confidentiality.CONFIDENTIALITY)
+public @interface Confidentiality {
+ String CONFIDENTIALITY = SCA_PREFIX + "confidentiality";
+ String CONFIDENTIALITY_MESSAGE = CONFIDENTIALITY + ".message";
+ String CONFIDENTIALITY_TRANSPORT = CONFIDENTIALITY + ".transport";
+
+ /**
+ * List of confidentiality qualifiers (such as "message" or "transport").
+ *
+ * @return confidentiality qualifiers
+ */
+ @Qualifier
+ String[] value() default "";
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Constructor.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Constructor.java
new file mode 100644
index 0000000000..86d2d6560d
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Constructor.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.CONSTRUCTOR;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Used to indicate the constructor the runtime is to use when instantiating a component implementation instance
+ *
+ * @version $Rev$ $Date$
+ */
+@Target(CONSTRUCTOR)
+@Retention(RUNTIME)
+public @interface Constructor {
+ String[] value() default "";
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Context.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Context.java
new file mode 100644
index 0000000000..37f767c1f4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Context.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation used to indicate a field or setter method that is used to inject an SCA context.
+ * The type of context injected is determined by the type of the field or the parameter
+ * to the setter method and is typically a ComponentContext or RequestContext.
+ *
+ * @version $Rev$ $Date$
+ */
+@Target({METHOD, FIELD})
+@Retention(RUNTIME)
+public @interface Context {
+}
+
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/ConversationAttributes.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/ConversationAttributes.java
new file mode 100644
index 0000000000..1484d4ac77
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/ConversationAttributes.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.osoa.sca.annotations;
+
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation used to indicate the characteristics of a conversation.
+ *
+ * @version $Rev$ $Date$
+ */
+@Target(ElementType.TYPE)
+@Retention(RUNTIME)
+public @interface ConversationAttributes {
+ /**
+ * The maximum time that can pass between operations in a single conversation. If this time is exceeded the
+ * container may end the conversation.
+ *
+ * @return the maximum time that can pass between operations in a single conversation
+ */
+ String maxIdleTime() default "";
+
+ /**
+ * The maximum time that a conversation may remain active. If this time is exceeded the container may end the
+ * conversation.
+ *
+ * @return the maximum time that a conversation may remain active
+ */
+ String maxAge() default "";
+
+ /**
+ * If true, indicates that only the user that initiated the conversation has the authority to continue it.
+ *
+ * @return true if only the user that initiated the conversation has the authority to continue it
+ */
+ boolean singlePrincipal() default false;
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/ConversationID.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/ConversationID.java
new file mode 100644
index 0000000000..13ca9a2931
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/ConversationID.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation used to indicate a field or method that is used to inject the conversation ID.
+ *
+ * @version $Rev$ $Date$
+ */
+@Target({METHOD, FIELD})
+@Retention(RUNTIME)
+public @interface ConversationID {
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Conversational.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Conversational.java
new file mode 100644
index 0000000000..f16bf44808
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Conversational.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Used on a Java interface to denote a conversational service contract.
+ * <p/>
+ * The draft spec erroneously defines the targets for this as {TYPE, METHOD, FIELD}
+ * but this annotation is only applicable to interfaces.
+ *
+ * @version $Rev$ $Date$
+ */
+@Target({TYPE})
+@Retention(RUNTIME)
+public @interface Conversational {
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Destroy.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Destroy.java
new file mode 100644
index 0000000000..7d3da46ea9
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Destroy.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation used to indicate a method that will be called by the container when the
+ * scope defined for the local service ends.
+ *
+ * @version $Rev$ $Date$
+ */
+@Target(METHOD)
+@Retention(RUNTIME)
+public @interface Destroy {
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/EagerInit.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/EagerInit.java
new file mode 100644
index 0000000000..b9483bc9a8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/EagerInit.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation used to indicate an instance should be eagerly initialized.
+ *
+ * @version $Rev$ $Date$
+ */
+@Target({TYPE})
+@Retention(RUNTIME)
+public @interface EagerInit {
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/EndsConversation.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/EndsConversation.java
new file mode 100644
index 0000000000..9e6942651b
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/EndsConversation.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation used to indicate a method ends a conversation.
+ *
+ * @version $Rev$ $Date$
+ */
+@Target({METHOD})
+@Retention(RUNTIME)
+public @interface EndsConversation {
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Init.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Init.java
new file mode 100644
index 0000000000..32654fea17
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Init.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation used to indicate a method that will be called by the container when the scope defined for the local
+ * service begins.
+ *
+ * @version $Rev$ $Date$
+ */
+@Target(METHOD)
+@Retention(RUNTIME)
+public @interface Init {
+
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Integrity.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Integrity.java
new file mode 100644
index 0000000000..1a9288934c
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Integrity.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+import static org.osoa.sca.Constants.SCA_PREFIX;
+
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation denoting the intent that service operations require integrity.
+ * <p/>
+ * Applied to the injection site (field, method or constructor parameter) for a reference,
+ * it indicates that all invocations through that reference require integrity.
+ * <p/>
+ * Applied to a interface method on a service contract, it indicates that all invocations
+ * of that service operation require integrity; applied to the type of a service contract,
+ * it indicates that all service operations on that interface require integrity.
+ * <p/>
+ * Applied to a method on an implementation class, it indicates that all invocations that
+ * are dispatched to that implementation method (through any service) require integrity.
+ * Applied to a interface implemented by an implementation class, it indicates that all
+ * invocations that are dispatched to the implementation method for that interface operation
+ * require integrity.
+ * <p/>
+ * Applied to an implementation class, it indicates that all invocations of that implementation
+ * and that all invocations made by that implementation require integrity.
+ *
+ * @version $Rev$ $Date$
+ */
+@Inherited
+@Target({TYPE, FIELD, METHOD, PARAMETER})
+@Retention(RUNTIME)
+@Intent(Integrity.INTEGRITY)
+public @interface Integrity {
+ String INTEGRITY = SCA_PREFIX + "integrity";
+ String INTEGRITY_MESSAGE = INTEGRITY + "message";
+ String INTEGRITY_TRANSPORT = INTEGRITY + "transport";
+
+ /**
+ * List of integrity qualifiers (such as "message" or "transport").
+ *
+ * @return integrity qualifiers
+ */
+ @Qualifier
+ String[] value() default "";
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Intent.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Intent.java
new file mode 100644
index 0000000000..0769a94fbb
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Intent.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation that can be applied to annotations that describe SCA intents.
+ * Adding this annotation allows SCA runtimes to automatically detect user-defined intents.
+ * <p/>
+ * Applications must specify a value, a pairing of targetNamespace and localPort, or both.
+ * If both value and pairing are supplied they must define the name qualified name.
+ *
+ * @version $Rev$ $Date$
+ */
+@Target({ANNOTATION_TYPE})
+@Retention(RUNTIME)
+public @interface Intent {
+ /**
+ * The qualified name of the intent, in the form defined by {@link javax.xml.namespace.QName#toString}.
+ *
+ * @return the qualified name of the intent
+ */
+ String value() default "";
+
+ /**
+ * The XML namespace for the intent.
+ *
+ * @return the XML namespace for the intent
+ */
+ String targetNamespace() default "";
+
+ /**
+ * The name of the intent within its namespace.
+ *
+ * @return name of the intent within its namespace
+ */
+ String localPart() default "";
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/OneWay.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/OneWay.java
new file mode 100644
index 0000000000..fbc7398da4
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/OneWay.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation on a method that indicates that the method is non-blocking and communication
+ * with the service provider may use buffer the requests and send them at some later time.
+ *
+ * @version $Rev$ $Date$
+ */
+@Target({METHOD})
+@Retention(RUNTIME)
+public @interface OneWay {
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/PolicySets.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/PolicySets.java
new file mode 100644
index 0000000000..57247cd8a3
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/PolicySets.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation that allows application of SCA Policy Sets.
+ * <p/>
+ * Each policy set is specified using its XML QName in the form defined by {@link javax.xml.namespace.QName#toString()}.
+ *
+ * @version $Rev$ $Date$
+ */
+@Target({TYPE, FIELD, METHOD, PARAMETER})
+@Retention(RUNTIME)
+public @interface PolicySets {
+ /**
+ * Returns the policy sets to be applied.
+ *
+ * @return the policy sets to be applied
+ */
+ String[] value() default "";
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Property.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Property.java
new file mode 100644
index 0000000000..864a69b19a
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Property.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation used to indicate a constructor parameter, field or method that is
+ * used to inject a configuration property value.
+ *
+ * @version $Rev$ $Date$
+ */
+@Target({METHOD, FIELD, PARAMETER})
+@Retention(RUNTIME)
+public @interface Property {
+ /**
+ * The name of the property. If not specified then the name will be derived
+ * from the annotated field or method.
+ *
+ * @return the name of the property
+ */
+ String name() default "";
+
+ /**
+ * Indicates whether a value for the property must be provided.
+ *
+ * @return true if a value must be provided
+ */
+ boolean required() default false;
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Qualifier.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Qualifier.java
new file mode 100644
index 0000000000..a0abe16068
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Qualifier.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation that can be applied to an attribute of an @Intent annotation to indicate the
+ * attribute provides qualifiers for the intent.
+ *
+ * @version $Rev$ $Date$
+ */
+@Target(METHOD)
+@Retention(RUNTIME)
+public @interface Qualifier {
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Reference.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Reference.java
new file mode 100644
index 0000000000..768429cd91
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Reference.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation used to indicate a constructor parameter, field or method that is used to inject a reference.
+ *
+ * @version $Rev$ $Date$
+ */
+@Target({METHOD, FIELD, PARAMETER})
+@Retention(RUNTIME)
+public @interface Reference {
+ /**
+ * The name of the reference. If not specified then the name will be derived from the annotated field or method.
+ *
+ * @return the name of the reference
+ */
+ String name() default "";
+
+ /**
+ * Indicates if a reference must be specified.
+ *
+ * @return true if a reference must be specified
+ */
+ boolean required() default true;
+}
+
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Remotable.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Remotable.java
new file mode 100644
index 0000000000..1021f6e37f
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Remotable.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation used to indicate a Java interface as remotable.
+ * Remotable interfaces use pass-by-value semantics, can be published as entry points
+ * and used for external services.
+ *
+ * @version $Rev$ $Date$
+ */
+@Target(TYPE)
+@Retention(RUNTIME)
+public @interface Remotable {
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Requires.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Requires.java
new file mode 100644
index 0000000000..aa439cabab
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Requires.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation that allows the attachment of any intent to a Java Class or interface or to members of that
+ * class such as methods, fields or constructor parameters.
+ * <p/>
+ * Intents are specified as XML QNames in the representation defined by
+ * {@link javax.xml.namespace.QName#toString()}. Intents may be qualified with one or more
+ * suffixes separated by a "." such as:
+ * <ul>
+ * <li>{http://www.osoa.org/xmlns/sca/1.0}confidentiality</li>
+ * <li>{http://www.osoa.org/xmlns/sca/1.0}confidentiality.message</li>
+ * </ul>
+ * This annotation supports general purpose intents specified as strings. Users may also define
+ * specific intents using the {@link @org.osoa.sca.annotations.Intent} annotation.
+ *
+ * @version $Rev$ $Date$
+ */
+@Inherited
+@Retention(RUNTIME)
+@Target({TYPE, METHOD, FIELD, PARAMETER})
+public @interface Requires {
+ /**
+ * Returns the attached intents.
+ *
+ * @return the attached intents
+ */
+ String[] value() default "";
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Scope.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Scope.java
new file mode 100644
index 0000000000..6fded2dec8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Scope.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation used to indicate a scoped service.
+ * <p/>
+ * The spec refers to but does not describe an eager() attribute; this is an error in the draft.
+ *
+ * @version $Rev$ $Date$
+ */
+@Target(TYPE)
+@Retention(RUNTIME)
+public @interface Scope {
+ /**
+ * The name of the scope. Values currently defined by the specification are:
+ * <ul>
+ * <li>STATELESS (default)</li>
+ * <li>REQUEST</li>
+ * <li>CONVERSATION</li>
+ * <li>COMPOSITE</li>
+ * </ul>
+ *
+ * @return the name of the scope
+ */
+ String value() default "STATELESS";
+}
diff --git a/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Service.java b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Service.java
new file mode 100644
index 0000000000..1e475cd4c8
--- /dev/null
+++ b/sca-java-1.x/branches/sca-android/modules/sca-api/src/main/java/org/osoa/sca/annotations/Service.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.osoa.sca.annotations;
+
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation used to indicate the service interfaces exposed by a Java class.
+ *
+ * @version $Rev$ $Date$
+ */
+@Target({TYPE})
+@Retention(RUNTIME)
+public @interface Service {
+ /**
+ * Array of interfaces that should be exposed as services.
+ *
+ * @return a list of interfaces that should be exposed as services
+ */
+ Class<?>[] interfaces() default {};
+
+ /**
+ * Shortcut allowing a single interface to be exposed.
+ *
+ * @return a single service interfaces to be exposed
+ */
+ Class<?> value() default Void.class;
+}