From 994c753d4c4f224e7b93fa8dc6ae807367317678 Mon Sep 17 00:00:00 2001 From: rfeng Date: Tue, 19 Aug 2008 00:08:11 +0000 Subject: Add SCANodeFactory/SCANode and rename the artifact ids from node2-xxx to node-xxx git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@686901 13f79535-47bb-0310-9956-ffa450edef68 --- java/sca/distribution/bundle/pom.xml | 6 +- java/sca/distribution/manifest/pom.xml | 6 +- java/sca/itest/callablereferences/pom.xml | 2 +- .../CallableReferenceRemoteTestCase.java | 10 +- java/sca/itest/conversations-ws/pom.xml | 2 +- .../conversational/ConversationWSDLTestCase.java | 8 +- .../NonConversationalCallbackTestCase.java | 8 +- .../itest/conversational/RequestScopeTestCase.java | 8 +- .../conversational/StatefulStatefulTestCase.java | 8 +- .../conversational/StatefulStatelessTestCase.java | 8 +- .../conversational/StatelessStatefulTestCase.java | 8 +- .../conversational/StatelessStatelessTestCase.java | 8 +- java/sca/itest/databindings/jaxb-top-down/pom.xml | 2 +- .../jaxb/topdown/DatabindingTestCase.java | 8 +- .../topdown/PrimitivesDatabindingTestCase.java | 8 +- .../topdown/StandardTypesDatabindingTestCase.java | 8 +- java/sca/itest/domain/pom.xml | 4 +- .../sca/itest/domain/ContributionSPIsTestCase.java | 8 +- java/sca/itest/late-reference-resolution/pom.xml | 4 +- .../LateReferenceResolutionTestCase.java | 12 +- java/sca/itest/oneway/pom.xml | 2 +- .../tuscany/sca/itest/oneway/OneWayTestCase.java | 8 +- .../osgi-tuscany/tuscany-osgi-installer/pom.xml | 6 +- java/sca/itest/validation/pom.xml | 2 +- .../ComponentReferenceTargetNotFoundTestCase.java | 8 +- ...uplicateImplementationPropertyNameTestCase.java | 8 +- ...plicateImplementationReferenceNameTestCase.java | 8 +- .../warning/DuplicatePropertyNameTestCase.java | 8 +- .../warning/DuplicateReferenceNameTestCase.java | 8 +- .../MultipleBindingsForServiceTestCase.java | 8 +- .../warning/NoComponentImplementationTestCase.java | 8 +- .../warning/NoCompositeNamespaceTestCase.java | 8 +- .../warning/NoMatchingBindingTestCase.java | 8 +- .../warning/PromotedReferenceNotFoundTestCase.java | 8 +- .../warning/PromotedServiceNotFoundTestCase.java | 8 +- .../PropertyAttributeMustSupplyNullTestCase.java | 8 +- .../warning/PropertyAttributeTestCase.java | 8 +- .../warning/PropertyNotFoundTestCase.java | 8 +- .../PropertyOverrideManyAttributeTestCase.java | 8 +- ...enceIncompatibleComponentInterfaceTestCase.java | 8 +- .../ReferenceIncompatibleInterfaceTestCase.java | 8 +- .../ReferenceIncompatibleMultiplicityTestCase.java | 8 +- .../warning/ReferenceNotFoundTestCase.java | 8 +- .../warning/ReferenceWithoutTargetsTestCase.java | 8 +- ...ServiceNotFoundForComponentServiceTestCase.java | 8 +- .../UnresolvedComponentImplementationTestCase.java | 8 +- .../calculator/warning/XSDValidationTestCase.java | 8 +- java/sca/modules/domain-manager/pom.xml | 4 +- .../launcher/DomainManagerLauncherBootstrap.java | 14 +- java/sca/modules/host-embedded/pom.xml | 2 +- .../sca/host/embedded/impl/DefaultSCADomain.java | 8 +- .../modules/implementation-node-runtime/pom.xml | 6 +- .../NodeImplementationDaemonBootstrap.java | 8 +- .../NodeImplementationLauncherBootstrap.java | 22 +- .../node/webapp/NodeWebAppServletHost.java | 10 +- java/sca/modules/node-api/LICENSE | 205 ++++++ java/sca/modules/node-api/NOTICE | 6 + java/sca/modules/node-api/pom.xml | 61 ++ .../org/apache/tuscany/sca/node/SCAClient.java | 71 ++ .../apache/tuscany/sca/node/SCAContribution.java | 54 ++ .../java/org/apache/tuscany/sca/node/SCANode.java | 42 ++ .../java/org/apache/tuscany/sca/node/SCANode2.java | 33 + .../apache/tuscany/sca/node/SCANode2Factory.java | 203 +++++ .../apache/tuscany/sca/node/SCANodeFactory.java | 201 +++++ java/sca/modules/node-impl/LICENSE | 205 ++++++ java/sca/modules/node-impl/NOTICE | 6 + java/sca/modules/node-impl/pom.xml | 154 ++++ .../tuscany/sca/node/impl/Node2FactoryImpl.java | 57 ++ .../apache/tuscany/sca/node/impl/Node2Impl.java | 63 ++ .../tuscany/sca/node/impl/NodeFactoryImpl.java | 55 ++ .../org/apache/tuscany/sca/node/impl/NodeImpl.java | 818 +++++++++++++++++++++ .../tuscany/sca/node/impl/RuntimeBootStrapper.java | 385 ++++++++++ .../tuscany/sca/node/impl/RuntimeBuilder.java | 261 +++++++ .../org.apache.tuscany.sca.node.SCANode2Factory | 17 + .../org.apache.tuscany.sca.node.SCANodeFactory | 17 + .../node-impl/src/test/java/hello/HelloWorld.java | 30 + .../src/test/java/hello/HelloWorldImpl.java | 30 + .../tuscany/sca/node/impl/Node2ImplTestCase.java | 119 +++ .../tuscany/sca/node/impl/NodeImplTestCase.java | 119 +++ .../src/test/resources/HelloWorld.composite | 30 + .../test/resources/META-INF/sca-contribution.xml | 23 + java/sca/modules/node-launcher-osgi/LICENSE | 205 ++++++ java/sca/modules/node-launcher-osgi/NOTICE | 6 + java/sca/modules/node-launcher-osgi/pom.xml | 150 ++++ .../sca/node/osgi/launcher/Contribution.java | 48 ++ .../node/osgi/launcher/DomainManagerLauncher.java | 103 +++ .../sca/node/osgi/launcher/FelixOSGiHost.java | 172 +++++ .../sca/node/osgi/launcher/JarFileFinder.java | 348 +++++++++ .../osgi/launcher/LauncherBundleActivator.java | 457 ++++++++++++ .../sca/node/osgi/launcher/LauncherException.java | 55 ++ .../sca/node/osgi/launcher/NodeDaemonLauncher.java | 100 +++ .../sca/node/osgi/launcher/NodeLauncher.java | 143 ++++ .../sca/node/osgi/launcher/NodeLauncherUtil.java | 186 +++++ .../tuscany/sca/node/osgi/launcher/NodeMain.java | 44 ++ .../sca/node/osgi/launcher/NodeServletFilter.java | 127 ++++ .../tuscany/sca/node/osgi/launcher/OSGiHost.java | 30 + .../src/test/java/hello/HelloWorld.java | 30 + .../src/test/java/hello/HelloWorldImpl.java | 30 + .../node/osgi/launcher/FelixOSGiHostTestCase.java | 95 +++ .../node/osgi/launcher/NodeLauncherTestCase.java | 69 ++ .../src/test/resources/HelloWorld.composite | 30 + java/sca/modules/node-launcher-webapp/LICENSE | 205 ++++++ java/sca/modules/node-launcher-webapp/NOTICE | 6 + java/sca/modules/node-launcher-webapp/pom.xml | 62 ++ .../src/main/webapp/META-INF/sca-contribution.xml | 21 + .../src/main/webapp/WEB-INF/web.xml | 41 ++ .../node-launcher-webapp/src/main/webapp/index.jsp | 27 + java/sca/modules/node-launcher/LICENSE | 205 ++++++ java/sca/modules/node-launcher/NOTICE | 6 + java/sca/modules/node-launcher/pom.xml | 72 ++ .../tuscany/sca/node/launcher/Contribution.java | 48 ++ .../sca/node/launcher/DomainManagerLauncher.java | 141 ++++ .../sca/node/launcher/LauncherException.java | 55 ++ .../sca/node/launcher/NodeDaemonLauncher.java | 100 +++ .../tuscany/sca/node/launcher/NodeLauncher.java | 150 ++++ .../sca/node/launcher/NodeLauncherUtil.java | 536 ++++++++++++++ .../apache/tuscany/sca/node/launcher/NodeMain.java | 44 ++ .../sca/node/launcher/NodeServletFilter.java | 128 ++++ java/sca/modules/node-manager/pom.xml | 6 +- java/sca/modules/node2-api/LICENSE | 205 ------ java/sca/modules/node2-api/NOTICE | 6 - java/sca/modules/node2-api/pom.xml | 61 -- .../org/apache/tuscany/sca/node/SCAClient.java | 71 -- .../apache/tuscany/sca/node/SCAContribution.java | 54 -- .../java/org/apache/tuscany/sca/node/SCANode2.java | 42 -- .../apache/tuscany/sca/node/SCANode2Factory.java | 201 ----- java/sca/modules/node2-impl/LICENSE | 205 ------ java/sca/modules/node2-impl/NOTICE | 6 - java/sca/modules/node2-impl/pom.xml | 154 ---- .../tuscany/sca/node/impl/NodeFactoryImpl.java | 55 -- .../org/apache/tuscany/sca/node/impl/NodeImpl.java | 813 -------------------- .../tuscany/sca/node/impl/RuntimeBootStrapper.java | 385 ---------- .../tuscany/sca/node/impl/RuntimeBuilder.java | 261 ------- .../org.apache.tuscany.sca.node.SCANode2Factory | 17 - .../node2-impl/src/test/java/hello/HelloWorld.java | 30 - .../src/test/java/hello/HelloWorldImpl.java | 30 - .../tuscany/sca/node/impl/NodeImplTestCase.java | 119 --- .../src/test/resources/HelloWorld.composite | 30 - .../test/resources/META-INF/sca-contribution.xml | 23 - java/sca/modules/node2-launcher-osgi/LICENSE | 205 ------ java/sca/modules/node2-launcher-osgi/NOTICE | 6 - java/sca/modules/node2-launcher-osgi/pom.xml | 150 ---- .../sca/node/osgi/launcher/Contribution.java | 48 -- .../node/osgi/launcher/DomainManagerLauncher.java | 103 --- .../sca/node/osgi/launcher/FelixOSGiHost.java | 172 ----- .../sca/node/osgi/launcher/JarFileFinder.java | 348 --------- .../osgi/launcher/LauncherBundleActivator.java | 457 ------------ .../sca/node/osgi/launcher/LauncherException.java | 55 -- .../sca/node/osgi/launcher/NodeDaemonLauncher.java | 100 --- .../sca/node/osgi/launcher/NodeLauncher.java | 143 ---- .../sca/node/osgi/launcher/NodeLauncherUtil.java | 186 ----- .../tuscany/sca/node/osgi/launcher/NodeMain.java | 44 -- .../sca/node/osgi/launcher/NodeServletFilter.java | 127 ---- .../tuscany/sca/node/osgi/launcher/OSGiHost.java | 30 - .../src/test/java/hello/HelloWorld.java | 30 - .../src/test/java/hello/HelloWorldImpl.java | 30 - .../node/osgi/launcher/FelixOSGiHostTestCase.java | 95 --- .../node/osgi/launcher/NodeLauncherTestCase.java | 69 -- .../src/test/resources/HelloWorld.composite | 30 - java/sca/modules/node2-launcher-webapp/LICENSE | 205 ------ java/sca/modules/node2-launcher-webapp/NOTICE | 6 - java/sca/modules/node2-launcher-webapp/pom.xml | 62 -- .../src/main/webapp/META-INF/sca-contribution.xml | 21 - .../src/main/webapp/WEB-INF/web.xml | 41 -- .../src/main/webapp/index.jsp | 27 - java/sca/modules/node2-launcher/LICENSE | 205 ------ java/sca/modules/node2-launcher/NOTICE | 6 - java/sca/modules/node2-launcher/pom.xml | 72 -- .../tuscany/sca/node/launcher/Contribution.java | 48 -- .../sca/node/launcher/DomainManagerLauncher.java | 141 ---- .../sca/node/launcher/LauncherException.java | 55 -- .../sca/node/launcher/NodeDaemonLauncher.java | 100 --- .../tuscany/sca/node/launcher/NodeLauncher.java | 150 ---- .../sca/node/launcher/NodeLauncherUtil.java | 536 -------------- .../apache/tuscany/sca/node/launcher/NodeMain.java | 44 -- .../sca/node/launcher/NodeServletFilter.java | 128 ---- java/sca/modules/pom.xml | 10 +- java/sca/modules/runtime/pom.xml | 4 +- java/sca/samples/calculator-distributed/pom.xml | 4 +- .../src/main/java/node/LaunchCalculatorNodeA.java | 4 +- .../calculator/CalculatorDistributedTestCase.java | 14 +- java/sca/samples/calculator/pom.xml | 4 +- .../src/main/java/calculator/CalculatorClient.java | 8 +- .../test/java/calculator/CalculatorTestCase.java | 8 +- java/sca/samples/callback-ws-client/pom.xml | 2 +- .../src/main/java/myapp/MyClientImpl.java | 8 +- .../test/java/myapp/CallbackClientTestCase.java | 8 +- java/sca/samples/callback-ws-service/pom.xml | 2 +- .../src/main/java/myserver/CallbackServer.java | 6 +- .../test/java/myserver/CallbackServerTestCase.java | 8 +- .../sca/samples/customer-dojo/build-dependency.xml | 3 + java/sca/samples/domain-management/pom.xml | 4 +- .../java/manager/DistributeAndRunComponents.java | 8 +- java/sca/samples/store-distributed/pom.xml | 4 +- java/sca/tools/maven/maven-osgi-junit/pom.xml | 2 +- java/sca/tools/runtime-inspector/pom.xml | 2 +- .../sca/tools/inspector/AssemblyInspector.java | 23 +- .../sca/tools/inspector/RegistryInspector.java | 5 +- .../sca/tools/inspector/RuntimeInspector.java | 4 +- .../src/test/java/calculator/CalculatorClient.java | 6 +- .../tools/inspector/RegistryInspectorTestCase.java | 8 +- java/sca/tutorials/store/catalog-webapp/pom.xml | 4 +- java/sca/tutorials/store/domain/pom.xml | 2 +- .../store-client/launch/LaunchStoreClientNode.java | 4 +- java/sca/tutorials/store/store-client/pom.xml | 4 +- java/sca/tutorials/store/store-test/pom.xml | 4 +- .../store-test/test/StoreSupplierTestCase.java | 10 +- .../sca/vtest/java-api/annotations/destroy/pom.xml | 2 +- .../destroy/DestroyAnnotationTestCase.java | 24 +- java/sca/vtest/java-api/annotations/init/pom.xml | 2 +- .../annotations/init/InitAnnotationTestCase.java | 24 +- 211 files changed, 7860 insertions(+), 7380 deletions(-) create mode 100644 java/sca/modules/node-api/LICENSE create mode 100644 java/sca/modules/node-api/NOTICE create mode 100644 java/sca/modules/node-api/pom.xml create mode 100644 java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCAClient.java create mode 100644 java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCAContribution.java create mode 100644 java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode.java create mode 100644 java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode2.java create mode 100644 java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode2Factory.java create mode 100644 java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANodeFactory.java create mode 100644 java/sca/modules/node-impl/LICENSE create mode 100644 java/sca/modules/node-impl/NOTICE create mode 100644 java/sca/modules/node-impl/pom.xml create mode 100644 java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/Node2FactoryImpl.java create mode 100644 java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/Node2Impl.java create mode 100644 java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java create mode 100644 java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java create mode 100644 java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java create mode 100644 java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBuilder.java create mode 100644 java/sca/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.SCANode2Factory create mode 100644 java/sca/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.SCANodeFactory create mode 100644 java/sca/modules/node-impl/src/test/java/hello/HelloWorld.java create mode 100644 java/sca/modules/node-impl/src/test/java/hello/HelloWorldImpl.java create mode 100644 java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/Node2ImplTestCase.java create mode 100644 java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java create mode 100644 java/sca/modules/node-impl/src/test/resources/HelloWorld.composite create mode 100644 java/sca/modules/node-impl/src/test/resources/META-INF/sca-contribution.xml create mode 100644 java/sca/modules/node-launcher-osgi/LICENSE create mode 100644 java/sca/modules/node-launcher-osgi/NOTICE create mode 100644 java/sca/modules/node-launcher-osgi/pom.xml create mode 100644 java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/Contribution.java create mode 100644 java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/DomainManagerLauncher.java create mode 100644 java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHost.java create mode 100644 java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/JarFileFinder.java create mode 100644 java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/LauncherBundleActivator.java create mode 100644 java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/LauncherException.java create mode 100644 java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeDaemonLauncher.java create mode 100644 java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncher.java create mode 100644 java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherUtil.java create mode 100644 java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeMain.java create mode 100644 java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeServletFilter.java create mode 100644 java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/OSGiHost.java create mode 100644 java/sca/modules/node-launcher-osgi/src/test/java/hello/HelloWorld.java create mode 100644 java/sca/modules/node-launcher-osgi/src/test/java/hello/HelloWorldImpl.java create mode 100644 java/sca/modules/node-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHostTestCase.java create mode 100644 java/sca/modules/node-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherTestCase.java create mode 100644 java/sca/modules/node-launcher-osgi/src/test/resources/HelloWorld.composite create mode 100644 java/sca/modules/node-launcher-webapp/LICENSE create mode 100644 java/sca/modules/node-launcher-webapp/NOTICE create mode 100644 java/sca/modules/node-launcher-webapp/pom.xml create mode 100644 java/sca/modules/node-launcher-webapp/src/main/webapp/META-INF/sca-contribution.xml create mode 100644 java/sca/modules/node-launcher-webapp/src/main/webapp/WEB-INF/web.xml create mode 100644 java/sca/modules/node-launcher-webapp/src/main/webapp/index.jsp create mode 100644 java/sca/modules/node-launcher/LICENSE create mode 100644 java/sca/modules/node-launcher/NOTICE create mode 100644 java/sca/modules/node-launcher/pom.xml create mode 100644 java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/Contribution.java create mode 100644 java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/DomainManagerLauncher.java create mode 100644 java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/LauncherException.java create mode 100644 java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeDaemonLauncher.java create mode 100644 java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java create mode 100644 java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java create mode 100644 java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeMain.java create mode 100644 java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.java delete mode 100644 java/sca/modules/node2-api/LICENSE delete mode 100644 java/sca/modules/node2-api/NOTICE delete mode 100644 java/sca/modules/node2-api/pom.xml delete mode 100644 java/sca/modules/node2-api/src/main/java/org/apache/tuscany/sca/node/SCAClient.java delete mode 100644 java/sca/modules/node2-api/src/main/java/org/apache/tuscany/sca/node/SCAContribution.java delete mode 100644 java/sca/modules/node2-api/src/main/java/org/apache/tuscany/sca/node/SCANode2.java delete mode 100644 java/sca/modules/node2-api/src/main/java/org/apache/tuscany/sca/node/SCANode2Factory.java delete mode 100644 java/sca/modules/node2-impl/LICENSE delete mode 100644 java/sca/modules/node2-impl/NOTICE delete mode 100644 java/sca/modules/node2-impl/pom.xml delete mode 100644 java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java delete mode 100644 java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java delete mode 100644 java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java delete mode 100644 java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBuilder.java delete mode 100644 java/sca/modules/node2-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.SCANode2Factory delete mode 100644 java/sca/modules/node2-impl/src/test/java/hello/HelloWorld.java delete mode 100644 java/sca/modules/node2-impl/src/test/java/hello/HelloWorldImpl.java delete mode 100644 java/sca/modules/node2-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java delete mode 100644 java/sca/modules/node2-impl/src/test/resources/HelloWorld.composite delete mode 100644 java/sca/modules/node2-impl/src/test/resources/META-INF/sca-contribution.xml delete mode 100644 java/sca/modules/node2-launcher-osgi/LICENSE delete mode 100644 java/sca/modules/node2-launcher-osgi/NOTICE delete mode 100644 java/sca/modules/node2-launcher-osgi/pom.xml delete mode 100644 java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/Contribution.java delete mode 100644 java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/DomainManagerLauncher.java delete mode 100644 java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHost.java delete mode 100644 java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/JarFileFinder.java delete mode 100644 java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/LauncherBundleActivator.java delete mode 100644 java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/LauncherException.java delete mode 100644 java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeDaemonLauncher.java delete mode 100644 java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncher.java delete mode 100644 java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherUtil.java delete mode 100644 java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeMain.java delete mode 100644 java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeServletFilter.java delete mode 100644 java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/OSGiHost.java delete mode 100644 java/sca/modules/node2-launcher-osgi/src/test/java/hello/HelloWorld.java delete mode 100644 java/sca/modules/node2-launcher-osgi/src/test/java/hello/HelloWorldImpl.java delete mode 100644 java/sca/modules/node2-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHostTestCase.java delete mode 100644 java/sca/modules/node2-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherTestCase.java delete mode 100644 java/sca/modules/node2-launcher-osgi/src/test/resources/HelloWorld.composite delete mode 100644 java/sca/modules/node2-launcher-webapp/LICENSE delete mode 100644 java/sca/modules/node2-launcher-webapp/NOTICE delete mode 100644 java/sca/modules/node2-launcher-webapp/pom.xml delete mode 100644 java/sca/modules/node2-launcher-webapp/src/main/webapp/META-INF/sca-contribution.xml delete mode 100644 java/sca/modules/node2-launcher-webapp/src/main/webapp/WEB-INF/web.xml delete mode 100644 java/sca/modules/node2-launcher-webapp/src/main/webapp/index.jsp delete mode 100644 java/sca/modules/node2-launcher/LICENSE delete mode 100644 java/sca/modules/node2-launcher/NOTICE delete mode 100644 java/sca/modules/node2-launcher/pom.xml delete mode 100644 java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/Contribution.java delete mode 100644 java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/DomainManagerLauncher.java delete mode 100644 java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/LauncherException.java delete mode 100644 java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeDaemonLauncher.java delete mode 100644 java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java delete mode 100644 java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java delete mode 100644 java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeMain.java delete mode 100644 java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.java (limited to 'java') diff --git a/java/sca/distribution/bundle/pom.xml b/java/sca/distribution/bundle/pom.xml index 9a72908c41..3273e3b9ed 100644 --- a/java/sca/distribution/bundle/pom.xml +++ b/java/sca/distribution/bundle/pom.xml @@ -381,17 +381,17 @@ ${pom.groupId} - tuscany-node2-api + tuscany-node-api ${pom.version} ${pom.groupId} - tuscany-node2-impl + tuscany-node-impl ${pom.version} ${pom.groupId} - tuscany-node2-launcher + tuscany-node-launcher ${pom.version} diff --git a/java/sca/distribution/manifest/pom.xml b/java/sca/distribution/manifest/pom.xml index 015dec667f..9e56624f72 100644 --- a/java/sca/distribution/manifest/pom.xml +++ b/java/sca/distribution/manifest/pom.xml @@ -459,17 +459,17 @@ ${pom.groupId} - tuscany-node2-api + tuscany-node-api ${pom.version} ${pom.groupId} - tuscany-node2-impl + tuscany-node-impl ${pom.version} ${pom.groupId} - tuscany-node2-launcher + tuscany-node-launcher ${pom.version} diff --git a/java/sca/itest/callablereferences/pom.xml b/java/sca/itest/callablereferences/pom.xml index f9deb7b230..5fbf05c6e7 100644 --- a/java/sca/itest/callablereferences/pom.xml +++ b/java/sca/itest/callablereferences/pom.xml @@ -45,7 +45,7 @@ + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.4-SNAPSHOT + ../pom.xml + + + tuscany-node-api + Apache Tuscany SCA Node API + + + + org.apache.tuscany.sca + tuscany-sca-api + 1.4-SNAPSHOT + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.node2.api + ${pom.name} + org.apache.tuscany.sca.node* + org.apache.tuscany.sca.node.impl + + + + + + + diff --git a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCAClient.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCAClient.java new file mode 100644 index 0000000000..f390e8881e --- /dev/null +++ b/java/sca/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 the Java type of the business interface for the reference + * @param 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 + */ + > 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 the Java type of the business interface for the service + * @return an object that implements the business interface + */ + B getService(Class 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 the Java type of the business interface for the service + * @return a ServiceReference for the designated service + */ + ServiceReference getServiceReference(Class businessInterface, String serviceName); + +} \ No newline at end of file diff --git a/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCAContribution.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCAContribution.java new file mode 100644 index 0000000000..de7f352122 --- /dev/null +++ b/java/sca/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/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode.java new file mode 100644 index 0000000000..fea749a57c --- /dev/null +++ b/java/sca/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/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode2.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode2.java new file mode 100644 index 0000000000..a1d4ddb2b1 --- /dev/null +++ b/java/sca/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/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode2Factory.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANode2Factory.java new file mode 100644 index 0000000000..2b0dbc88eb --- /dev/null +++ b/java/sca/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 createProxy(Class type, Object node) { + try { + return type.getDeclaredConstructor(Object.class).newInstance(node); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + } + + public > 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 getService(Class 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 ServiceReference getServiceReference(Class businessInterface, String serviceName) { + try { + return (ServiceReference)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: + *
    + *
  • This is a standalone application and there is a deployable composite file on the classpath. + *
  • There is only one contribution which contains the deployable composite file physically in its packaging hierarchy. + *
+ * @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/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANodeFactory.java b/java/sca/modules/node-api/src/main/java/org/apache/tuscany/sca/node/SCANodeFactory.java new file mode 100644 index 0000000000..6d02d654e2 --- /dev/null +++ b/java/sca/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 createProxy(Class type, Object node) { + try { + return type.getDeclaredConstructor(Object.class).newInstance(node); + } catch (Exception e) { + throw new IllegalArgumentException(e); + } + } + + public > 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 getService(Class 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 ServiceReference getServiceReference(Class businessInterface, String serviceName) { + try { + return (ServiceReference)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", true, classLoader); + 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, true, classLoader); + 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: + *
    + *
  • This is a standalone application and there is a deployable composite file on the classpath. + *
  • There is only one contribution which contains the deployable composite file physically in its packaging hierarchy. + *
+ * @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/java/sca/modules/node-impl/LICENSE b/java/sca/modules/node-impl/LICENSE new file mode 100644 index 0000000000..8aa906c321 --- /dev/null +++ b/java/sca/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/java/sca/modules/node-impl/NOTICE b/java/sca/modules/node-impl/NOTICE new file mode 100644 index 0000000000..fdfa0e9faa --- /dev/null +++ b/java/sca/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/java/sca/modules/node-impl/pom.xml b/java/sca/modules/node-impl/pom.xml new file mode 100644 index 0000000000..7bad8a5750 --- /dev/null +++ b/java/sca/modules/node-impl/pom.xml @@ -0,0 +1,154 @@ + + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.4-SNAPSHOT + ../pom.xml + + + tuscany-node-impl + Apache Tuscany SCA Node Implementation + + + + + org.apache.tuscany.sca + tuscany-assembly + 1.4-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-contribution + 1.4-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-node-api + 1.4-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-node + 1.4-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-core + 1.4-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-contribution-impl + 1.4-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-assembly-xml + 1.4-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-definitions-xml + 1.4-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-binding-sca + 1.4-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-binding-sca-xml + 1.4-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-policy-xml + 1.4-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-core-databinding + 1.4-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-assembly-xsd + 1.4-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-endpoint + 1.4-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.4-SNAPSHOT + test + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.node2.impl + ${pom.name} + org.apache.tuscany.sca.node.impl* + + + + + + + diff --git a/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/Node2FactoryImpl.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/Node2FactoryImpl.java new file mode 100644 index 0000000000..419900c5ac --- /dev/null +++ b/java/sca/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/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/Node2Impl.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/Node2Impl.java new file mode 100644 index 0000000000..bc2f10fb7e --- /dev/null +++ b/java/sca/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/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java new file mode 100644 index 0000000000..18b166acdd --- /dev/null +++ b/java/sca/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/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java new file mode 100644 index 0000000000..e35203bc5b --- /dev/null +++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java @@ -0,0 +1,818 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* 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 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 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() { + 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 (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() { + 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 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 localContributions = localContributions(); + + // Load the specified contributions + ContributionService contributionService = runtime.getContributionService(); + contributions = new ArrayList(); + 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 deployables = new ArrayList(); + 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 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 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 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 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 > R cast(B target) throws IllegalArgumentException { + return (R)runtime.getProxyFactory().cast(target); + } + + public B getService(Class businessInterface, String serviceName) { + + ServiceReference serviceReference = getServiceReference(businessInterface, serviceName); + if (serviceReference == null) { + throw new ServiceRuntimeException("Service not found: " + serviceName); + } + return serviceReference.getService(); + } + + public ServiceReference getServiceReference(Class businessInterface, String name) { + + // Extract the component name + String componentName; + String serviceName; + int i = name.indexOf('/'); + if (i != -1) { + componentName = name.substring(0, i); + serviceName = name.substring(i + 1); + + } else { + componentName = name; + serviceName = null; + } + + // Lookup the component + 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() + "." + 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 localContributions() { + Map localContributions = new HashMap(); + collectJARs(localContributions, Thread.currentThread().getContextClassLoader()); + return localContributions; + } + + /** + * Collect JARs on the classpath of a URLClassLoader + * @param urls + * @param cl + */ + private static void collectJARs(Map 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/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java new file mode 100644 index 0000000000..c9995d6024 --- /dev/null +++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.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.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 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 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 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(); + 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); + UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); + InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class); + + //Create a composite builder + SCADefinitions aggregatedDefinitions = new SCADefinitionsImpl(); + for (SCADefinitions definition : ((List)policyDefinitions)) { + SCADefinitionsUtil.aggregateSCADefinitions(definition, aggregatedDefinitions); + } + compositeBuilder = + RuntimeBuilder.createCompositeBuilder(monitor, + assemblyFactory, + scaBindingFactory, + endpointFactory, + intentAttachPointTypeFactory, + 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 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 loadModules(ExtensionPointRegistry registry) throws ActivationException { + + // Load and instantiate the modules found on the classpath (or any registered ClassLoaders) + modules = new ArrayList(); + try { + Set moduleActivators = + ServiceDiscovery.getInstance().getServiceDeclarations(ModuleActivator.class); + Set moduleClasses = new HashSet(); + 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 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 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/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBuilder.java b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBuilder.java new file mode 100644 index 0000000000..98a44cef9e --- /dev/null +++ b/java/sca/modules/node-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBuilder.java @@ -0,0 +1,261 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.node.impl; + +import java.io.IOException; +import java.security.AccessController; +import java.security.PrivilegedAction; +import java.util.List; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLOutputFactory; + +import org.apache.tuscany.sca.assembly.AssemblyFactory; +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.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, + InterfaceContractMapper interfaceContractMapper, + SCADefinitions policyDefinitions) { + + return new CompositeBuilderImpl(assemblyFactory, endpointFactory, scaBindingFactory, + intentAttachPointTypeFactory, 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 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() { + 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() { + 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); + documentProcessors.addArtifactProcessor(new CompositeDocumentProcessor(staxProcessor, validatingInputFactory, + 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/java/sca/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.SCANode2Factory b/java/sca/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/java/sca/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/java/sca/modules/node-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.SCANodeFactory b/java/sca/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/java/sca/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/java/sca/modules/node-impl/src/test/java/hello/HelloWorld.java b/java/sca/modules/node-impl/src/test/java/hello/HelloWorld.java new file mode 100644 index 0000000000..2f519cb81d --- /dev/null +++ b/java/sca/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/java/sca/modules/node-impl/src/test/java/hello/HelloWorldImpl.java b/java/sca/modules/node-impl/src/test/java/hello/HelloWorldImpl.java new file mode 100644 index 0000000000..c9a7560b12 --- /dev/null +++ b/java/sca/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/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/Node2ImplTestCase.java b/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/Node2ImplTestCase.java new file mode 100644 index 0000000000..52d96dd72d --- /dev/null +++ b/java/sca/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 = + "" + + " " + + " " + + " " + + " "; + + @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/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java b/java/sca/modules/node-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java new file mode 100644 index 0000000000..d620f6b62a --- /dev/null +++ b/java/sca/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 = + "" + + " " + + " " + + " " + + " "; + + @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/java/sca/modules/node-impl/src/test/resources/HelloWorld.composite b/java/sca/modules/node-impl/src/test/resources/HelloWorld.composite new file mode 100644 index 0000000000..9e3299d691 --- /dev/null +++ b/java/sca/modules/node-impl/src/test/resources/HelloWorld.composite @@ -0,0 +1,30 @@ + + + + + + + + + diff --git a/java/sca/modules/node-impl/src/test/resources/META-INF/sca-contribution.xml b/java/sca/modules/node-impl/src/test/resources/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..1d37bcebe0 --- /dev/null +++ b/java/sca/modules/node-impl/src/test/resources/META-INF/sca-contribution.xml @@ -0,0 +1,23 @@ + + + + + + diff --git a/java/sca/modules/node-launcher-osgi/LICENSE b/java/sca/modules/node-launcher-osgi/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/java/sca/modules/node-launcher-osgi/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/java/sca/modules/node-launcher-osgi/NOTICE b/java/sca/modules/node-launcher-osgi/NOTICE new file mode 100644 index 0000000000..1325efd8bf --- /dev/null +++ b/java/sca/modules/node-launcher-osgi/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2008 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/java/sca/modules/node-launcher-osgi/pom.xml b/java/sca/modules/node-launcher-osgi/pom.xml new file mode 100644 index 0000000000..682a1725df --- /dev/null +++ b/java/sca/modules/node-launcher-osgi/pom.xml @@ -0,0 +1,150 @@ + + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.4-SNAPSHOT + ../pom.xml + + + tuscany-node-launcher-osgi + Apache Tuscany SCA Node OSGi Launcher + + + + javax.servlet + servlet-api + 2.5 + provided + + + org.apache.felix + org.osgi.core + 1.0.1 + + + org.apache.felix + org.apache.felix.framework + 1.0.4 + compile + + + org.apache.felix + javax.servlet + + + + + org.apache.tuscany.sca + tuscany-implementation-node-runtime + 1.4-SNAPSHOT + test + + + org.apache.tuscany.sca + tuscany-extensibility-osgi + 1.4-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-contribution-osgi + 1.4-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-domain-manager + 1.4-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-binding-http-runtime + 1.4-SNAPSHOT + test + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.4-SNAPSHOT + test + + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.0 + + + copy-dependencies + process-test-resources + + copy-dependencies + + + ${project.build.directory}/tuscany/modules + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + org.apache.tuscany.sca.node.osgi.launcher.NodeMain + + + + + + + + + + diff --git a/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/Contribution.java b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/Contribution.java new file mode 100644 index 0000000000..0214d5185f --- /dev/null +++ b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/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.osgi.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/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/DomainManagerLauncher.java b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/DomainManagerLauncher.java new file mode 100644 index 0000000000..6c28ef8b28 --- /dev/null +++ b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/DomainManagerLauncher.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.node.osgi.launcher; + +import static org.apache.tuscany.sca.node.osgi.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 { + + private 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 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 createDomainManager(String rootDirectory) throws LauncherException { + return (T)domainManager(rootDirectory); + } + + public static void main(String[] args) throws Exception { + logger.info("Apache Tuscany SCA Domain Manager starting..."); + + // Create a domain manager + DomainManagerLauncher launcher = newInstance(); + Object domainManager = launcher.createDomainManager(); + + // Start the domain manager + 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 started."); + + logger.info("Press enter to shutdown."); + try { + System.in.read(); + } catch (IOException e) {} + + // Stop the domain manager + try { + domainManager.getClass().getMethod("stop").invoke(domainManager); + } catch (Exception e) { + logger.log(Level.SEVERE, "SCA Domain Manager could not be stopped", e); + throw e; + } + } +} diff --git a/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHost.java b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHost.java new file mode 100644 index 0000000000..0c54c89c40 --- /dev/null +++ b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHost.java @@ -0,0 +1,172 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.node.osgi.launcher; + +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.felix.framework.Felix; +import org.apache.felix.framework.cache.BundleCache; +import org.apache.felix.framework.util.FelixConstants; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleException; +import org.osgi.framework.Constants; + +/** + * + */ +public class FelixOSGiHost implements OSGiHost { + + private Felix felix; + private LauncherBundleActivator activator; + private ClassLoader tccl; + + private final static String systemPackages = + "org.osgi.framework; version=1.3.0," + "org.osgi.service.packageadmin; version=1.2.0, " + + "org.osgi.service.startlevel; version=1.0.0, " + + "org.osgi.service.url; version=1.0.0, " + + "org.osgi.util.tracker; version=1.3.2, " + + "javax.xml, " + + "javax.xml.datatype, " + + "javax.xml.namespace, " + + "javax.xml.parsers, " + + "javax.xml.transform, " + + "javax.xml.transform.dom, " + + "javax.xml.transform.sax, " + + "javax.xml.transform.stream, " + + "javax.xml.validation, " + + "javax.xml.xpath, " + // Force the classes to be imported from the system bundle + // + "javax.xml.stream, " + // + "javax.xml.stream.util, " + + "javax.sql," + + "org.w3c.dom, " + + "org.xml.sax, " + + "org.xml.sax.ext, " + + "org.xml.sax.helpers, " + + "javax.security.auth, " + + "javax.security.cert, " + + "javax.security.auth.login, " + + "javax.security.auth.callback, " + + "javax.naming, " + + "javax.naming.spi, " + + "javax.naming.directory, " + + "javax.management, " + + "javax.imageio, " + + "sun.misc, " + + "javax.net, " + + "javax.net.ssl, " + + "javax.crypto, " + + "javax.rmi, " + + "javax.transaction, " + + "javax.transaction.xa"; + + public LauncherBundleActivator getActivator() { + if (activator == null) { + activator = new LauncherBundleActivator(); + } + return activator; + } + + public void setActivator(LauncherBundleActivator activator) { + this.activator = activator; + } + + public BundleContext start() { + try { + startup(); + } catch (Exception e) { + throw new IllegalStateException(e); + } + BundleContext bundleContext = felix.getBundleContext(); + return bundleContext; + } + + public void stop() { + try { + shutdown(); + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + + private void startup() throws BundleException { + if (felix != null) { + throw new IllegalStateException("Felix is already running."); + } + + // Create a configuration property map. + Map configMap = new HashMap(); + // Configure the Felix instance to be embedded. + configMap.put(FelixConstants.EMBEDDED_EXECUTION_PROP, "true"); + // Add core OSGi packages to be exported from the class path + // via the system bundle. + configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES, systemPackages); + // Explicitly specify the directory to use for caching bundles. + configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP, "target/.felix"); + List list = new ArrayList(); + + list.add(getActivator()); + + // Now create an instance of the framework with + // our configuration properties and activator. + felix = new Felix(configMap, list); + + // Now start Felix instance. + felix.start(); + + tccl = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader(getContextClassLoader(felix.getBundleContext())); + + } + + private ClassLoader getContextClassLoader(BundleContext bundleContext) { + for (Bundle b : bundleContext.getBundles()) { + if ("org.apache.tuscany.sca.extensibility.osgi".equals(b.getSymbolicName())) { + try { + b.start(); + Class discovererClass = b.loadClass("org.apache.tuscany.sca.extensibility.ServiceDiscovery"); + Method getter = discovererClass.getMethod("getServiceDiscoverer"); + Object discoverer = getter.invoke(null); + + Method getCL = discoverer.getClass().getMethod("getContextClassLoader"); + ClassLoader cl = (ClassLoader)getCL.invoke(discoverer); + return cl; + } catch (Exception e) { + throw new IllegalStateException(e); + } + } + } + return null; + } + + private void shutdown() throws BundleException { + if (felix != null) { + felix.stop(); + } + Thread.currentThread().setContextClassLoader(tccl); + } + +} diff --git a/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/JarFileFinder.java b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/JarFileFinder.java new file mode 100644 index 0000000000..38c7093a16 --- /dev/null +++ b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/JarFileFinder.java @@ -0,0 +1,348 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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.osgi.launcher; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FilenameFilter; +import java.io.IOException; +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.security.PrivilegedActionException; +import java.security.PrivilegedExceptionAction; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.StringTokenizer; +import java.util.logging.Logger; + +/** + * + */ +public class JarFileFinder { + /** + * A file name filter used to filter JAR files. + */ + 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. + */ + static class WebAppJARFileNameFilter extends StandAloneJARFileNameFilter { + + 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; + } + } + + private static final Logger logger = Logger.getLogger(JarFileFinder.class.getName()); + + static final String TUSCANY_HOME = "TUSCANY_HOME"; + private static final String TUSCANY_PATH = "TUSCANY_PATH"; + + /** + * Collect JAR files in the given directory + * @param directory + * @param urls + * @param filter + * @throws MalformedURLException + */ + private static void collectJARFiles(File directory, List 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()); + } + } + } + + /** + * Collect JAR files under the given directory. + * + * @param directory + * @param jarDirectoryURLs + * @param jarURLs + * @param filter + * @throws MalformedURLException + */ + private static void collectJARFiles(String directory, + Set jarDirectoryURLs, + List 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); + } + } + } + + /** + * Returns a ClassLoader for the Tuscany runtime JARs. + * + * @param parentClassLoader + * @param filter + * + * @return + */ + public static List findJarFiles(File root, FilenameFilter filter) throws FileNotFoundException, + URISyntaxException, MalformedURLException { + + // Build list of runtime JARs + Set jarDirectoryURLs = new HashSet(); + List jarURLs = new ArrayList(); + + URL url = null; + if (root != null) { + url = root.toURI().toURL(); + } else { + // First determine the path to the launcher class + String resource = JarFileFinder.class.getName().replace('.', '/') + ".class"; + url = JarFileFinder.class.getClassLoader().getResource(resource); + if (url == null) { + throw new FileNotFoundException(resource); + } + + url = getContainer(url, 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 + if (url != null && "file".equals(url.getProtocol())) { + + 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 = getProperty(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 = getProperty(TUSCANY_PATH); + if (ext != null && ext.length() != 0) { + logger.fine(TUSCANY_PATH + ": " + ext); + String separator = getProperty("path.separator"); + for (StringTokenizer tokens = new StringTokenizer(ext, separator); tokens.hasMoreTokens();) { + collectJARFiles(tokens.nextToken(), jarDirectoryURLs, jarURLs, filter); + } + } + + return jarURLs; + + } + + static String getProperty(final String prop) { + return AccessController.doPrivileged(new PrivilegedAction() { + public String run() { + String value = System.getProperty(prop); + if (value == null || value.length() == 0) { + return System.getenv(prop); + } else { + return value; + } + } + }); + } + + private 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) { + 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); + } + } + + private static URL getContainer(URL resourceURL, String resourceName) { + URL root = null; + // "jar:file://....../something.jar!/a/b/c/app.composite" + try { + String url = resourceURL.toExternalForm(); + String protocol = resourceURL.getProtocol(); + if ("file".equals(protocol)) { + // directory contribution + if (url.endsWith("/" + resourceName)) { + final String location = url.substring(0, url.length() - resourceName.length() - 1); + // 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 { + root = AccessController.doPrivileged(new PrivilegedExceptionAction() { + public URL run() throws IOException { + return 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 + root = 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 + root = toFile(new URL(location)).toURI().toURL(); + + } else if (protocol != null && (protocol.equals("bundle") || protocol.equals("bundleresource"))) { + root = new URL(resourceURL.getProtocol(), resourceURL.getHost(), resourceURL.getPort(), "/"); + } + } catch (MalformedURLException mfe) { + throw new IllegalArgumentException(mfe); + } + return root; + } + +} diff --git a/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/LauncherBundleActivator.java b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/LauncherBundleActivator.java new file mode 100644 index 0000000000..13af11238e --- /dev/null +++ b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/LauncherBundleActivator.java @@ -0,0 +1,457 @@ +package org.apache.tuscany.sca.node.osgi.launcher; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URI; +import java.net.URL; +import java.security.CodeSource; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.jar.Attributes; +import java.util.jar.JarEntry; +import java.util.jar.JarInputStream; +import java.util.jar.JarOutputStream; +import java.util.jar.Manifest; +import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.zip.ZipEntry; + +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleEvent; +import org.osgi.framework.BundleListener; +import org.osgi.framework.Constants; + +/** + * Bundle activator which installs Tuscany modules and 3rd party jars into an OSGi runtime. + * + */ +public class LauncherBundleActivator implements BundleActivator, Constants, BundleListener { + private static Logger logger = Logger.getLogger(LauncherBundleActivator.class.getName()); + private static final String[] immutableJars = {"bcprov"}; + + private BundleContext bundleContext; + private List tuscanyBundles = new ArrayList(); + + private List jarFiles; + + public LauncherBundleActivator() { + super(); + } + + public LauncherBundleActivator(List jarFiles) { + super(); + this.jarFiles = jarFiles; + } + + public static String toString(Bundle b, boolean verbose) { + StringBuffer sb = new StringBuffer(); + sb.append(b.getBundleId()).append(" ").append(b.getSymbolicName()); + int s = b.getState(); + if ((s & Bundle.UNINSTALLED) != 0) { + sb.append(" UNINSTALLED"); + } + if ((s & Bundle.INSTALLED) != 0) { + sb.append(" INSTALLED"); + } + if ((s & Bundle.RESOLVED) != 0) { + sb.append(" RESOLVED"); + } + if ((s & Bundle.STARTING) != 0) { + sb.append(" STARTING"); + } + if ((s & Bundle.STOPPING) != 0) { + sb.append(" STOPPING"); + } + if ((s & Bundle.ACTIVE) != 0) { + sb.append(" ACTIVE"); + } + + if (verbose) { + sb.append(" ").append(b.getLocation()); + sb.append(" ").append(b.getHeaders()); + } + return sb.toString(); + } + + public void start(BundleContext bundleContext) throws Exception { + this.bundleContext = bundleContext; + this.bundleContext.addBundleListener(this); + installTuscany(bundleContext); + + for (Bundle b : bundleContext.getBundles()) { + try { + if ("org.apache.tuscany.sca.contribution.osgi".equals(b.getSymbolicName())) { + b.start(); + logger.info(toString(b, false) + " " + b.getState()); + break; + } + } catch (Exception e) { + logger.log(Level.SEVERE, e.getMessage(), e); + } + } + } + + public void stop(BundleContext bundleContext) throws Exception { + /* + for (Bundle bundle : tuscanyBundles) { + try { + bundle.stop(); + } catch (Exception e) { + logger.log(Level.SEVERE, e.getMessage(), e); + } + } + */ + + for (Bundle bundle : tuscanyBundles) { + try { + if (logger.isLoggable(Level.FINE)) { + logger.fine("Uninstalling bundle: " + toString(bundle, false)); + } + bundle.uninstall(); + } catch (Exception e) { + logger.log(Level.SEVERE, e.getMessage(), e); + } + } + this.bundleContext.removeBundleListener(this); + tuscanyBundles.clear(); + this.bundleContext = null; + } + + public void installTuscany(BundleContext bundleContext) { + long start = System.currentTimeMillis(); + + try { + + // FIXME: SDO bundles dont have the correct dependencies + System.setProperty("commonj.sdo.impl.HelperProvider", "org.apache.tuscany.sdo.helper.HelperProviderImpl"); + List urls = jarFiles; + if (urls == null) { + File tuscanyInstallDir = findTuscanyInstallDir(bundleContext.getBundle()); + + urls = JarFileFinder.findJarFiles(tuscanyInstallDir, new JarFileFinder.StandAloneJARFileNameFilter()); + } + + for (URL url : urls) { + File file = new File(url.toURI()); + if (file.getName().startsWith("org.apache.felix.") || file.getName().startsWith("org.osgi.")) { + continue; + } + try { + Bundle bundle = createAndInstallBundle(bundleContext, url); + } catch (Exception e) { + logger.log(Level.SEVERE, e.getMessage(), e); + } + } + + long end = System.currentTimeMillis(); + logger.info("Tuscany bundles are installed in " + (end - start) + " ms."); + + } catch (Exception e) { + e.printStackTrace(); + } + } + + private File findTuscanyInstallDir(Bundle bundle) throws IOException { + String tuscanyDirName = JarFileFinder.getProperty(JarFileFinder.TUSCANY_HOME); + if (tuscanyDirName != null) { + File tuscanyInstallDir = new File(tuscanyDirName); + if (tuscanyInstallDir.exists() && tuscanyInstallDir.isDirectory()) + return tuscanyInstallDir; + } + + String location = bundle.getLocation(); + + if (location != null && location.startsWith("file:")) { + File file = new File(URI.create(location)); + File tuscanyInstallDir = file.getParentFile(); + if (tuscanyInstallDir.exists() && tuscanyInstallDir.isDirectory()) + return tuscanyInstallDir; + } + if (this.getClass().getProtectionDomain() != null) { + CodeSource codeSource = this.getClass().getProtectionDomain().getCodeSource(); + if (codeSource != null) { + try { + File tuscanyInstallDir = new File(codeSource.getLocation().toURI()); + if (tuscanyInstallDir.exists() && tuscanyInstallDir.isDirectory()) + return tuscanyInstallDir; + } catch (Exception e) { + // ignore + } + } + } + return null; + } + + public Bundle createAndInstallBundle(BundleContext bundleContext, URL bundleFile) throws Exception { + if (logger.isLoggable(Level.FINE)) { + logger.fine("Installing bundle: " + bundleFile); + } + long start = System.currentTimeMillis(); + + Manifest manifest = readManifest(bundleFile); + boolean isOSGiBundle = manifest != null && manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME) != null; + + if (!isOSGiBundle) { + manifest = updateBundleManifest(bundleFile, manifest); + } + + String symbolicName = manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME); + String version = manifest.getMainAttributes().getValue(BUNDLE_VERSION); + Bundle bundle = findBundle(bundleContext, symbolicName, version); + if (bundle != null) { + if (logger.isLoggable(Level.FINE)) { + logger.fine("Bundle is already installed: " + symbolicName); + } + return bundle; + } + + String bundleLocation = bundleFile.toString(); + InputStream inStream = null; + if (!isOSGiBundle) { + // We need to repackage the bundle + ByteArrayOutputStream out = new ByteArrayOutputStream(); + JarOutputStream jarOut = new JarOutputStream(out, manifest); + + String classpath = manifest.getMainAttributes().getValue("Bundle-ClassPath"); + boolean embedded = classpath != null && !classpath.trim().equals("."); + if (embedded) { + addFileToJar(bundleFile, jarOut); + } else { + copyJar(bundleFile, jarOut); + } + + jarOut.close(); + inStream = new ByteArrayInputStream(out.toByteArray()); + } else { + // The file itself is already a bundle + inStream = bundleFile.openStream(); + } + + try { + bundle = bundleContext.installBundle(bundleLocation, inStream); + if (logger.isLoggable(Level.FINE)) { + logger.fine("Bundle installed in " + (System.currentTimeMillis() - start) + " ms: " + bundleLocation); + } + tuscanyBundles.add(bundle); + return bundle; + } finally { + inStream.close(); + } + + } + + private Bundle findBundle(BundleContext bundleContext, String symbolicName, String version) { + Bundle[] bundles = bundleContext.getBundles(); + if (version == null) { + version = "0.0.0"; + } + for (Bundle b : bundles) { + String v = (String)b.getHeaders().get(BUNDLE_VERSION); + if (v == null) { + v = "0.0.0"; + } + if (b.getSymbolicName().equals(symbolicName) && (version.equals("0.0.0") || v.equals(version))) { + return b; + } + } + return null; + } + + private String getFileName(URL url) { + String name = url.getPath(); + int index = name.lastIndexOf('/'); + return name.substring(index + 1); + } + + private void addFileToJar(URL file, JarOutputStream jarOut) throws IOException { + JarEntry ze = new JarEntry(getFileName(file)); + jarOut.putNextEntry(ze); + InputStream inStream = file.openStream(); + copy(inStream, jarOut); + inStream.close(); + } + + private void copy(InputStream in, OutputStream out) throws IOException { + byte[] readBuf = new byte[4096]; + int bytesRead; + while ((bytesRead = in.read(readBuf)) > 0) { + out.write(readBuf, 0, bytesRead); + } + } + + private void copyJar(URL in, JarOutputStream jarOut) throws IOException { + JarInputStream jarIn = new JarInputStream(in.openStream()); + ZipEntry ze; + while ((ze = jarIn.getNextEntry()) != null) { + // Skip the MANIFEST.MF + if (ze.getName().equals("META-INF/MANIFEST.MF")) + continue; + jarOut.putNextEntry(ze); + copy(jarIn, jarOut); + } + jarIn.close(); + } + + private Manifest readManifest(URL jarFile) throws IOException { + JarInputStream jar = new JarInputStream(jarFile.openStream()); + // Read the Manifest from the jar file + Manifest manifest = jar.getManifest(); + jar.close(); + + if (manifest == null) { + // Create a new one if no Manifest is found + manifest = new Manifest(); + } + return manifest; + } + + private Manifest updateBundleManifest(URL jarFile, Manifest manifest) throws Exception { + + // Check if we have an associated .mf file + String name = jarFile.toString(); + int index = name.lastIndexOf('.'); + if (index != -1) { + URL mf = new URL(name.substring(0, index) + ".mf"); + try { + InputStream in = mf.openStream(); + manifest.read(in); + in.close(); + } catch (IOException e) { + // Ignore + } + } + + String jarFileName = getFileName(jarFile); + boolean isImmutableJar = false; + for (String immutableJar : immutableJars) { + if (jarFileName.startsWith(immutableJar)) { + isImmutableJar = true; + break; + } + } + + Attributes attributes = manifest.getMainAttributes(); + if (attributes.getValue(BUNDLE_SYMBOLICNAME) == null) { + String bundleSymbolicName = jarFileName; + if (bundleSymbolicName.endsWith(".jar")) { + bundleSymbolicName = bundleSymbolicName.substring(0, bundleSymbolicName.length() - 4); + } + attributes.putValue(BUNDLE_SYMBOLICNAME, bundleSymbolicName); + } else { + // Assume the jar is already a bundle + return null; + } + + if (attributes.getValue("Manifest-Version") == null) { + attributes.putValue("Manifest-Version", "1.0"); + } + + if (attributes.getValue(BUNDLE_MANIFESTVERSION) == null) { + attributes.putValue(BUNDLE_MANIFESTVERSION, "2"); + } + + if (isImmutableJar && attributes.getValue(BUNDLE_CLASSPATH) == null) { + attributes.putValue(BUNDLE_CLASSPATH, ".," + jarFileName); + } + + JarInputStream jar = new JarInputStream(jarFile.openStream()); + HashSet packages = getPackagesInJar(jarFileName, jar); + jar.close(); + String version = getJarVersion(jarFileName); + + // attributes.remove(new Attributes.Name("Require-Bundle")); + // attributes.remove(new Attributes.Name("Import-Package")); + + if (attributes.getValue(BUNDLE_VERSION) == null) { + attributes.putValue(BUNDLE_VERSION, version); + } + // Existing export statements in bundles may contain versions, so they should be used as is + // SDO exports are not sufficient, and should be changed + if (attributes.getValue(EXPORT_PACKAGE) == null || jarFileName.startsWith("tuscany-sdo-impl")) { + String pkgs = packagesToString(packages, version); + if (pkgs.length() > 0) { + attributes.putValue(EXPORT_PACKAGE, pkgs); + attributes.putValue(IMPORT_PACKAGE, packagesToString(packages, null)); + } + // attributes.putValue("Import-Package", packagesToString(packages, null)); + } + + attributes.putValue(DYNAMICIMPORT_PACKAGE, "*"); + return manifest; + } + + private HashSet getPackagesInJar(String bundleName, JarInputStream jar) throws Exception { + HashSet packages = new HashSet(); + ZipEntry entry; + while ((entry = jar.getNextEntry()) != null) { + String entryName = entry.getName(); + if (!entry.isDirectory() && entryName != null && entryName.length() > 0 && !entryName.startsWith(".") + // && !entryName.startsWith("META-INF") + && entryName.lastIndexOf("/") > 0) { + String pkg = entryName.substring(0, entryName.lastIndexOf("/")).replace('/', '.'); + packages.add(pkg); + + } + } + // FIXME: Split package + if (bundleName.startsWith("axis2-adb")) { + packages.remove("org.apache.axis2.util"); + } else if (bundleName.startsWith("axis2-codegen")) { + packages.remove("org.apache.axis2.wsdl"); + packages.remove("org.apache.axis2.wsdl.util"); + } else if (bundleName.startsWith("bsf-all")) { + packages.remove("org.mozilla.javascript"); + } + + return packages; + } + + private String packagesToString(HashSet packages, String version) { + + StringBuilder pkgBuf = new StringBuilder(); + for (String pkg : packages) { + if (pkgBuf.length() > 0) { + pkgBuf.append(','); + } + pkgBuf.append(pkg); + if (version != null && !pkg.startsWith("META-INF.")) { + pkgBuf.append(";version=\""); + pkgBuf.append(version); + pkgBuf.append('\"'); + } + } + return pkgBuf.toString(); + } + + private String getJarVersion(String bundleName) { + Pattern pattern = Pattern.compile("-([0-9.]+)"); + Matcher matcher = pattern.matcher(bundleName); + String version = "1.0.0"; + if (matcher.find()) { + version = matcher.group(); + if (version.endsWith(".")) { + version = version.substring(1, version.length() - 1); + } else { + version = version.substring(1); + } + } + return version; + } + + public BundleContext getBundleContext() { + return bundleContext; + } + + public void bundleChanged(BundleEvent event) { + } + +} diff --git a/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/LauncherException.java b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/LauncherException.java new file mode 100644 index 0000000000..bf17222e34 --- /dev/null +++ b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/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.osgi.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/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeDaemonLauncher.java b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeDaemonLauncher.java new file mode 100644 index 0000000000..f0e4e9da70 --- /dev/null +++ b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeDaemonLauncher.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.node.osgi.launcher; + +import static org.apache.tuscany.sca.node.osgi.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 { + + private 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 createNodeDaemon() throws LauncherException { + return (T)nodeDaemon(); + } + + public static void main(String[] args) throws Exception { + logger.info("Apache Tuscany SCA Node Daemon starting..."); + + // Create a node daemon + NodeDaemonLauncher launcher = newInstance(); + OSGiHost host = NodeLauncherUtil.startOSGi(); + + try { + Object daemon = launcher.createNodeDaemon(); + + // Start the node daemon + try { + daemon.getClass().getMethod("start").invoke(daemon); + } catch (Exception e) { + logger.log(Level.SEVERE, "SCA Node Daemon could not be started", e); + throw e; + } + logger.info("SCA Node Daemon started."); + + logger.info("Press enter to shutdown."); + try { + System.in.read(); + } catch (IOException e) { + } + + // Stop the node daemon + try { + daemon.getClass().getMethod("stop").invoke(daemon); + } catch (Exception e) { + logger.log(Level.SEVERE, "SCA Node Daemon could not be stopped", e); + throw e; + } + } finally { + NodeLauncherUtil.stopOSGi(host); + } + } + +} diff --git a/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncher.java b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncher.java new file mode 100644 index 0000000000..917838d521 --- /dev/null +++ b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncher.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.node.osgi.launcher; + +import static org.apache.tuscany.sca.node.osgi.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 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 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 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: + *
    + *
  • This is a standalone application and there is a deployable composite file on the classpath. + *
  • There is only one contribution which contains the deployable composite file physically in its packaging hierarchy. + *
+ * + * @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 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 starting..."); + + // Create a node + NodeLauncher launcher = newInstance(); + String configurationURI = args[0]; + logger.info("SCA Node configuration: " + configurationURI); + Object node = launcher.createNodeFromURL(configurationURI); + + // 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 started."); + + logger.info("Press enter to shutdown."); + try { + System.in.read(); + } catch (IOException e) {} + + // Stop the node + try { + node.getClass().getMethod("stop").invoke(node); + } catch (Exception e) { + logger.log(Level.SEVERE, "SCA Node could not be stopped", e); + throw e; + } + } + +} diff --git a/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherUtil.java b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherUtil.java new file mode 100644 index 0000000000..4a13c0a589 --- /dev/null +++ b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherUtil.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.node.osgi.launcher; + +import java.lang.reflect.Constructor; +import java.util.logging.Level; + +/** + * 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 DOMAIN_MANAGER_LAUNCHER_BOOTSTRAP = + "org.apache.tuscany.sca.domain.manager.launcher.DomainManagerLauncherBootstrap"; + + private static final String NODE_IMPLEMENTATION_DAEMON_BOOTSTRAP = + "org.apache.tuscany.sca.implementation.node.launcher.NodeImplementationDaemonBootstrap"; + + private static final String NODE_IMPLEMENTATION_LAUNCHER_BOOTSTRAP = + "org.apache.tuscany.sca.implementation.node.launcher.NodeImplementationLauncherBootstrap"; + + /** + * Collect JAR files under the given directory. + * + * @p @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 { + + // Use Java reflection to create the node as only the runtime class + // loader knows the runtime classes required by the node + String className = NODE_IMPLEMENTATION_LAUNCHER_BOOTSTRAP; + Class bootstrapClass; + bootstrapClass = Class.forName(className, false, tccl); + + 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); + try { + Class type = Class.forName("org.apache.tuscany.sca.node.SCANodeFactory"); + type = type.getDeclaredClasses()[0]; + return type.getMethod("createProxy", Class.class, Object.class).invoke(null, type, node); + } catch (ClassNotFoundException e) { + // Ignore + } + 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 { + + // Use Java reflection to create the node daemon as only the runtime class + // loader knows the runtime classes required by the node + String className = NODE_IMPLEMENTATION_DAEMON_BOOTSTRAP; + Class bootstrapClass; + bootstrapClass = Class.forName(className, false, tccl); + Object bootstrap = bootstrapClass.getConstructor().newInstance(); + + Object nodeDaemon = bootstrapClass.getMethod("getNode").invoke(bootstrap); + return nodeDaemon; + + } catch (Exception e) { + NodeLauncher.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 { + + // Use Java reflection to create the node daemon as only the runtime class + // loader knows the runtime classes required by the node + String className = DOMAIN_MANAGER_LAUNCHER_BOOTSTRAP; + Class bootstrapClass; + bootstrapClass = Class.forName(className, false, tccl); + Constructor constructor = bootstrapClass.getConstructor(String.class); + Object bootstrap = constructor.newInstance(rootDirectory); + + Object domainManager = bootstrapClass.getMethod("getNode").invoke(bootstrap); + return domainManager; + + } catch (Exception e) { + NodeLauncher.logger.log(Level.SEVERE, "SCA Domain Manager could not be created", e); + throw new LauncherException(e); + } finally { + Thread.currentThread().setContextClassLoader(tccl); + } + } + + static OSGiHost startOSGi() { + OSGiHost host = new FelixOSGiHost(); + host.start(); + return host; + } + + static void stopOSGi(OSGiHost host) { + host.stop(); + } + +} diff --git a/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeMain.java b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeMain.java new file mode 100644 index 0000000000..445ea80786 --- /dev/null +++ b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/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.osgi.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/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeServletFilter.java b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeServletFilter.java new file mode 100644 index 0000000000..fcbe259dba --- /dev/null +++ b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeServletFilter.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.node.osgi.launcher; + +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 String NODE_WEB_APP_SERVLET_HOST = "org.apache.tuscany.sca.implementation.node.osgi.webapp.NodeWebAppServletHost"; + + private static final long serialVersionUID = 1L; + + 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 starting..."); + + try { + // Get the Tuscany runtime ClassLoader + ClassLoader tccl = Thread.currentThread().getContextClassLoader(); + + 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/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/OSGiHost.java b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/OSGiHost.java new file mode 100644 index 0000000000..c5ea0439de --- /dev/null +++ b/java/sca/modules/node-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/OSGiHost.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.node.osgi.launcher; + +import org.osgi.framework.BundleContext; + +/** + * SPI to plug in OSGi implementations such as Equinox or Felix + */ +public interface OSGiHost { + BundleContext start(); + void stop(); +} diff --git a/java/sca/modules/node-launcher-osgi/src/test/java/hello/HelloWorld.java b/java/sca/modules/node-launcher-osgi/src/test/java/hello/HelloWorld.java new file mode 100644 index 0000000000..2f519cb81d --- /dev/null +++ b/java/sca/modules/node-launcher-osgi/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/java/sca/modules/node-launcher-osgi/src/test/java/hello/HelloWorldImpl.java b/java/sca/modules/node-launcher-osgi/src/test/java/hello/HelloWorldImpl.java new file mode 100644 index 0000000000..c9a7560b12 --- /dev/null +++ b/java/sca/modules/node-launcher-osgi/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/java/sca/modules/node-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHostTestCase.java b/java/sca/modules/node-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHostTestCase.java new file mode 100644 index 0000000000..e5194d0e5f --- /dev/null +++ b/java/sca/modules/node-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHostTestCase.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.node.osgi.launcher; + +import java.util.Dictionary; +import java.util.Enumeration; + +import junit.framework.Assert; + +import org.junit.Test; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; + + +/** + * + */ +public class FelixOSGiHostTestCase { + @Test + public void testStartThenStop() { + FelixOSGiHost host = new FelixOSGiHost(); + BundleContext context = host.start(); + Assert.assertNotNull(context); + for (Bundle b : context.getBundles()) { + System.out.println(toString(b, false)); + } + host.stop(); + } + + @Test + public void testStartTwice() { + FelixOSGiHost host = new FelixOSGiHost(); + host.start(); + try { + host.start(); + Assert.fail(); + } catch (IllegalStateException e) { + Assert.assertTrue(IllegalStateException.class.isInstance(e.getCause())); + } finally { + host.stop(); + } + } + + public static String toString(Bundle b, boolean verbose) { + StringBuffer sb = new StringBuffer(); + sb.append(b.getBundleId()).append(" ").append(b.getSymbolicName()); + int s = b.getState(); + if ((s & Bundle.UNINSTALLED) != 0) { + sb.append(" UNINSTALLED"); + } + if ((s & Bundle.INSTALLED) != 0) { + sb.append(" INSTALLED"); + } + if ((s & Bundle.RESOLVED) != 0) { + sb.append(" RESOLVED"); + } + if ((s & Bundle.STARTING) != 0) { + sb.append(" STARTING"); + } + if ((s & Bundle.STOPPING) != 0) { + sb.append(" STOPPING"); + } + if ((s & Bundle.ACTIVE) != 0) { + sb.append(" ACTIVE"); + } + + sb.append(" ").append(b.getLocation()); + if (verbose) { + Dictionary dict = b.getHeaders(); + Enumeration keys = dict.keys(); + while (keys.hasMoreElements()) { + Object key = keys.nextElement(); + sb.append(" ").append(key).append("=").append(dict.get(key)); + } + } + return sb.toString(); + } +} diff --git a/java/sca/modules/node-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherTestCase.java b/java/sca/modules/node-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherTestCase.java new file mode 100644 index 0000000000..97976e256a --- /dev/null +++ b/java/sca/modules/node-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherTestCase.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.node.osgi.launcher; + +import hello.HelloWorld; + +import org.apache.tuscany.sca.node.SCAClient; +import org.apache.tuscany.sca.node.SCANode; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Ignore; +import org.junit.Test; + +/** + * + */ +public class NodeLauncherTestCase { + private static OSGiHost host; + + @BeforeClass + public static void setUp() { + System.setProperty("TUSCANY_HOME", "target/tuscany"); + host = NodeLauncherUtil.startOSGi(); + } + + @AfterClass + public static void tearDown() { + if (host != null) { + NodeLauncherUtil.stopOSGi(host); + } + + } + + @Test + public void testLaunch() throws Exception { + NodeLauncher launcher = NodeLauncher.newInstance(); + SCANode node = launcher.createNodeFromClassLoader("HelloWorld.composite", getClass().getClassLoader()); + node.start(); + + HelloWorld hw = ((SCAClient)node).getService(HelloWorld.class, "HelloWorld"); + hw.hello("OSGi"); + + node.stop(); + } + + @Test + @Ignore("contribution-osgi issue") + public void testLaunchDomain() throws Exception { + DomainManagerLauncher.main(new String[] {}); + } + +} diff --git a/java/sca/modules/node-launcher-osgi/src/test/resources/HelloWorld.composite b/java/sca/modules/node-launcher-osgi/src/test/resources/HelloWorld.composite new file mode 100644 index 0000000000..9e3299d691 --- /dev/null +++ b/java/sca/modules/node-launcher-osgi/src/test/resources/HelloWorld.composite @@ -0,0 +1,30 @@ + + + + + + + + + diff --git a/java/sca/modules/node-launcher-webapp/LICENSE b/java/sca/modules/node-launcher-webapp/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/java/sca/modules/node-launcher-webapp/LICENSE @@ -0,0 +1,205 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + diff --git a/java/sca/modules/node-launcher-webapp/NOTICE b/java/sca/modules/node-launcher-webapp/NOTICE new file mode 100644 index 0000000000..1325efd8bf --- /dev/null +++ b/java/sca/modules/node-launcher-webapp/NOTICE @@ -0,0 +1,6 @@ +${pom.name} +Copyright (c) 2005 - 2008 The Apache Software Foundation + +This product includes software developed by +The Apache Software Foundation (http://www.apache.org/). + diff --git a/java/sca/modules/node-launcher-webapp/pom.xml b/java/sca/modules/node-launcher-webapp/pom.xml new file mode 100644 index 0000000000..de5c843c17 --- /dev/null +++ b/java/sca/modules/node-launcher-webapp/pom.xml @@ -0,0 +1,62 @@ + + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.4-SNAPSHOT + ../pom.xml + + + tuscany-node-launcher-webapp + war + Apache Tuscany SCA Node WebApp + + + + org.apache.tuscany.sca + tuscany-node-launcher + 1.4-SNAPSHOT + runtime + + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.node2.launcher.webapp + ${pom.name} + org.apache.tuscany.sca.node* + + + + + + + diff --git a/java/sca/modules/node-launcher-webapp/src/main/webapp/META-INF/sca-contribution.xml b/java/sca/modules/node-launcher-webapp/src/main/webapp/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..78bbebbb83 --- /dev/null +++ b/java/sca/modules/node-launcher-webapp/src/main/webapp/META-INF/sca-contribution.xml @@ -0,0 +1,21 @@ + + + + diff --git a/java/sca/modules/node-launcher-webapp/src/main/webapp/WEB-INF/web.xml b/java/sca/modules/node-launcher-webapp/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..6c2c943c99 --- /dev/null +++ b/java/sca/modules/node-launcher-webapp/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,41 @@ + + + + + + + Apache Tuscany SCA Node + + + tuscany + org.apache.tuscany.sca.node.launcher.NodeServletFilter + + + + tuscany + /* + + + + index.jsp + + + diff --git a/java/sca/modules/node-launcher-webapp/src/main/webapp/index.jsp b/java/sca/modules/node-launcher-webapp/src/main/webapp/index.jsp new file mode 100644 index 0000000000..3cc6c7b504 --- /dev/null +++ b/java/sca/modules/node-launcher-webapp/src/main/webapp/index.jsp @@ -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. +--%> + +<%@ page contentType="text/html;charset=UTF-8" language="java" %> + +Apache Tuscany SCA Node + + +

It works!

+ + diff --git a/java/sca/modules/node-launcher/LICENSE b/java/sca/modules/node-launcher/LICENSE new file mode 100644 index 0000000000..6e529a25c4 --- /dev/null +++ b/java/sca/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/java/sca/modules/node-launcher/NOTICE b/java/sca/modules/node-launcher/NOTICE new file mode 100644 index 0000000000..1325efd8bf --- /dev/null +++ b/java/sca/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/java/sca/modules/node-launcher/pom.xml b/java/sca/modules/node-launcher/pom.xml new file mode 100644 index 0000000000..4277f5109e --- /dev/null +++ b/java/sca/modules/node-launcher/pom.xml @@ -0,0 +1,72 @@ + + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-modules + 1.4-SNAPSHOT + ../pom.xml + + + tuscany-node-launcher + Apache Tuscany SCA Node Launcher + + + + javax.servlet + servlet-api + 2.4 + provided + + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + org.apache.tuscany.sca.node.launcher.NodeMain + + + + + + + org.apache.felix + maven-bundle-plugin + + + + ${tuscany.version} + org.apache.tuscany.sca.node2.launcher + ${pom.name} + org.apache.tuscany.sca.node* + + + + + + + diff --git a/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/Contribution.java b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/Contribution.java new file mode 100644 index 0000000000..4f4f861e2f --- /dev/null +++ b/java/sca/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/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/DomainManagerLauncher.java b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/DomainManagerLauncher.java new file mode 100644 index 0000000000..f0c0a0a2f4 --- /dev/null +++ b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/DomainManagerLauncher.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.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 { + + private 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 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 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 domain manager + DomainManagerLauncher launcher = newInstance(); + Object domainManager = launcher.createDomainManager(); + + // Start the domain manager + 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."); + + ShutdownThread hook = new ShutdownThread(domainManager); + Runtime.getRuntime().addShutdownHook(hook); + + logger.info("Press enter to shutdown."); + + try { + System.in.read(); + } catch (IOException e) { + + // Wait forever + Object lock = new Object(); + synchronized(lock) { + lock.wait(); + } + } + + stop(domainManager); + // Remove the hook + Runtime.getRuntime().removeShutdownHook(hook); + } + + private static void stop(Object domainManager) throws Exception { + // Stop the domain manager + if (domainManager == null) { + return; + } + 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 { + DomainManagerLauncher.stop(domainManager); + } catch (Exception e) { + // Ignore + } + } + } +} diff --git a/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/LauncherException.java b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/LauncherException.java new file mode 100644 index 0000000000..39e8d81139 --- /dev/null +++ b/java/sca/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/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeDaemonLauncher.java b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeDaemonLauncher.java new file mode 100644 index 0000000000..2756bf2073 --- /dev/null +++ b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeDaemonLauncher.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.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 { + + private 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 createNodeDaemon() throws LauncherException { + return (T)nodeDaemon(); + } + + public static void main(String[] args) throws Exception { + logger.info("Apache Tuscany SCA Node Daemon starting..."); + + // Create a node daemon + NodeDaemonLauncher launcher = newInstance(); + Object daemon = launcher.createNodeDaemon(); + + // Start the node daemon + try { + daemon.getClass().getMethod("start").invoke(daemon); + } catch (Exception e) { + logger.log(Level.SEVERE, "SCA Node Daemon could not be started", e); + throw e; + } + logger.info("SCA Node Daemon started."); + + logger.info("Press enter to shutdown."); + try { + System.in.read(); + } catch (IOException e) { + + // Wait forever + Object lock = new Object(); + synchronized(lock) { + lock.wait(); + } + } + + // Stop the node daemon + try { + daemon.getClass().getMethod("stop").invoke(daemon); + } catch (Exception e) { + logger.log(Level.SEVERE, "SCA Node Daemon could not be stopped", e); + throw e; + } + } + +} diff --git a/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java new file mode 100644 index 0000000000..44a5430976 --- /dev/null +++ b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java @@ -0,0 +1,150 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.sca.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 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 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 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: + *
    + *
  • This is a standalone application and there is a deployable composite file on the classpath. + *
  • There is only one contribution which contains the deployable composite file physically in its packaging hierarchy. + *
+ * + * @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 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 starting..."); + + // Create a node + NodeLauncher launcher = newInstance(); + String configurationURI = args[0]; + logger.info("SCA Node configuration: " + configurationURI); + Object node = launcher.createNodeFromURL(configurationURI); + + // 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 started."); + + logger.info("Press enter to shutdown."); + try { + System.in.read(); + } catch (IOException e) { + + // Wait forever + Object lock = new Object(); + synchronized(lock) { + lock.wait(); + } + } + + // Stop the node + try { + node.getClass().getMethod("stop").invoke(node); + } catch (Exception e) { + logger.log(Level.SEVERE, "SCA Node could not be stopped", e); + throw e; + } + } + +} diff --git a/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java new file mode 100644 index 0000000000..6d8bcbe65c --- /dev/null +++ b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java @@ -0,0 +1,536 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * 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 jarDirectoryURLs = new HashSet(); + List jarURLs = new ArrayList(); + + // 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 jarDirectoryURLs, List 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 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) { + NodeLauncher.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) { + NodeLauncher.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 findResources(String name) throws IOException { + Enumeration resources = super.findResources(name); + Enumeration parentResources = parent.getResources(name); + List allResources = new ArrayList(); + 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/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeMain.java b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeMain.java new file mode 100644 index 0000000000..eafe4ddaa0 --- /dev/null +++ b/java/sca/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/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.java b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.java new file mode 100644 index 0000000000..ad4009a1e1 --- /dev/null +++ b/java/sca/modules/node-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.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.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 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 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 = "org.apache.tuscany.sca.implementation.node.webapp.NodeWebAppServletHost"; + 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/java/sca/modules/node-manager/pom.xml b/java/sca/modules/node-manager/pom.xml index f39c818a7e..08152a6344 100644 --- a/java/sca/modules/node-manager/pom.xml +++ b/java/sca/modules/node-manager/pom.xml @@ -44,13 +44,13 @@ org.apache.tuscany.sca - tuscany-node2-api + tuscany-node-api 1.4-SNAPSHOT org.apache.tuscany.sca - tuscany-node2-launcher + tuscany-node-launcher 1.4-SNAPSHOT @@ -81,7 +81,7 @@ org.apache.tuscany.sca - tuscany-node2-impl + tuscany-node-impl 1.4-SNAPSHOT runtime diff --git a/java/sca/modules/node2-api/LICENSE b/java/sca/modules/node2-api/LICENSE deleted file mode 100644 index 6e529a25c4..0000000000 --- a/java/sca/modules/node2-api/LICENSE +++ /dev/null @@ -1,205 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - - diff --git a/java/sca/modules/node2-api/NOTICE b/java/sca/modules/node2-api/NOTICE deleted file mode 100644 index 1325efd8bf..0000000000 --- a/java/sca/modules/node2-api/NOTICE +++ /dev/null @@ -1,6 +0,0 @@ -${pom.name} -Copyright (c) 2005 - 2008 The Apache Software Foundation - -This product includes software developed by -The Apache Software Foundation (http://www.apache.org/). - diff --git a/java/sca/modules/node2-api/pom.xml b/java/sca/modules/node2-api/pom.xml deleted file mode 100644 index 8e52a99014..0000000000 --- a/java/sca/modules/node2-api/pom.xml +++ /dev/null @@ -1,61 +0,0 @@ - - - - - 4.0.0 - - org.apache.tuscany.sca - tuscany-modules - 1.4-SNAPSHOT - ../pom.xml - - - tuscany-node2-api - Apache Tuscany SCA Node API - - - - org.apache.tuscany.sca - tuscany-sca-api - 1.4-SNAPSHOT - - - - - - - - org.apache.felix - maven-bundle-plugin - - - - ${tuscany.version} - org.apache.tuscany.sca.node2.api - ${pom.name} - org.apache.tuscany.sca.node* - org.apache.tuscany.sca.node.impl - - - - - - - diff --git a/java/sca/modules/node2-api/src/main/java/org/apache/tuscany/sca/node/SCAClient.java b/java/sca/modules/node2-api/src/main/java/org/apache/tuscany/sca/node/SCAClient.java deleted file mode 100644 index f390e8881e..0000000000 --- a/java/sca/modules/node2-api/src/main/java/org/apache/tuscany/sca/node/SCAClient.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.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 the Java type of the business interface for the reference - * @param 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 - */ - > 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 the Java type of the business interface for the service - * @return an object that implements the business interface - */ - B getService(Class 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 the Java type of the business interface for the service - * @return a ServiceReference for the designated service - */ - ServiceReference getServiceReference(Class businessInterface, String serviceName); - -} \ No newline at end of file diff --git a/java/sca/modules/node2-api/src/main/java/org/apache/tuscany/sca/node/SCAContribution.java b/java/sca/modules/node2-api/src/main/java/org/apache/tuscany/sca/node/SCAContribution.java deleted file mode 100644 index de7f352122..0000000000 --- a/java/sca/modules/node2-api/src/main/java/org/apache/tuscany/sca/node/SCAContribution.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.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/java/sca/modules/node2-api/src/main/java/org/apache/tuscany/sca/node/SCANode2.java b/java/sca/modules/node2-api/src/main/java/org/apache/tuscany/sca/node/SCANode2.java deleted file mode 100644 index c193467b09..0000000000 --- a/java/sca/modules/node2-api/src/main/java/org/apache/tuscany/sca/node/SCANode2.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.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 SCANode2 { - - /** - * Start the composite loaded in the node. - */ - void start(); - - /** - * Stop the composite loaded in the node. - */ - void stop(); - -} diff --git a/java/sca/modules/node2-api/src/main/java/org/apache/tuscany/sca/node/SCANode2Factory.java b/java/sca/modules/node2-api/src/main/java/org/apache/tuscany/sca/node/SCANode2Factory.java deleted file mode 100644 index 9b63531a94..0000000000 --- a/java/sca/modules/node2-api/src/main/java/org/apache/tuscany/sca/node/SCANode2Factory.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.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 SCANode2Factory { - - public static class NodeProxy implements SCANode2, SCAClient { - private Object node; - - private NodeProxy(Object node) { - super(); - this.node = node; - } - - public static T createProxy(Class type, Object node) { - try { - return type.getDeclaredConstructor(Object.class).newInstance(node); - } catch (Exception e) { - throw new IllegalArgumentException(e); - } - } - - public > 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 getService(Class 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 ServiceReference getServiceReference(Class businessInterface, String serviceName) { - try { - return (ServiceReference)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.NodeFactoryImpl"; - - 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: - *
    - *
  • This is a standalone application and there is a deployable composite file on the classpath. - *
  • There is only one contribution which contains the deployable composite file physically in its packaging hierarchy. - *
- * @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/java/sca/modules/node2-impl/LICENSE b/java/sca/modules/node2-impl/LICENSE deleted file mode 100644 index 8aa906c321..0000000000 --- a/java/sca/modules/node2-impl/LICENSE +++ /dev/null @@ -1,205 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - - diff --git a/java/sca/modules/node2-impl/NOTICE b/java/sca/modules/node2-impl/NOTICE deleted file mode 100644 index fdfa0e9faa..0000000000 --- a/java/sca/modules/node2-impl/NOTICE +++ /dev/null @@ -1,6 +0,0 @@ -${pom.name} -Copyright (c) 2005 - 2008 The Apache Software Foundation - -This product includes software developed by -The Apache Software Foundation (http://www.apache.org/). - diff --git a/java/sca/modules/node2-impl/pom.xml b/java/sca/modules/node2-impl/pom.xml deleted file mode 100644 index 4f6f73d9be..0000000000 --- a/java/sca/modules/node2-impl/pom.xml +++ /dev/null @@ -1,154 +0,0 @@ - - - - - 4.0.0 - - org.apache.tuscany.sca - tuscany-modules - 1.4-SNAPSHOT - ../pom.xml - - - tuscany-node2-impl - Apache Tuscany SCA Node Implementation - - - - - org.apache.tuscany.sca - tuscany-assembly - 1.4-SNAPSHOT - - - - org.apache.tuscany.sca - tuscany-contribution - 1.4-SNAPSHOT - - - - org.apache.tuscany.sca - tuscany-node2-api - 1.4-SNAPSHOT - - - - org.apache.tuscany.sca - tuscany-implementation-node - 1.4-SNAPSHOT - - - - org.apache.tuscany.sca - tuscany-core - 1.4-SNAPSHOT - - - - org.apache.tuscany.sca - tuscany-contribution-impl - 1.4-SNAPSHOT - - - - org.apache.tuscany.sca - tuscany-assembly-xml - 1.4-SNAPSHOT - - - - org.apache.tuscany.sca - tuscany-definitions-xml - 1.4-SNAPSHOT - runtime - - - - org.apache.tuscany.sca - tuscany-binding-sca - 1.4-SNAPSHOT - runtime - - - - org.apache.tuscany.sca - tuscany-binding-sca-xml - 1.4-SNAPSHOT - runtime - - - - org.apache.tuscany.sca - tuscany-policy-xml - 1.4-SNAPSHOT - runtime - - - - org.apache.tuscany.sca - tuscany-core-databinding - 1.4-SNAPSHOT - runtime - - - - org.apache.tuscany.sca - tuscany-assembly-xsd - 1.4-SNAPSHOT - runtime - - - - org.apache.tuscany.sca - tuscany-endpoint - 1.4-SNAPSHOT - runtime - - - - org.apache.tuscany.sca - tuscany-implementation-java-runtime - 1.4-SNAPSHOT - test - - - - - - - - - org.apache.felix - maven-bundle-plugin - - - - ${tuscany.version} - org.apache.tuscany.sca.node2.impl - ${pom.name} - org.apache.tuscany.sca.node.impl* - - - - - - - diff --git a/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java b/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java deleted file mode 100644 index 3ec0958e4f..0000000000 --- a/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeFactoryImpl.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.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$ - */ -public class NodeFactoryImpl extends SCANode2Factory { - public NodeFactoryImpl() { - } - - @Override - public SCANode2 createSCANodeFromClassLoader(String compositeURI, ClassLoader classLoader) { - return new NodeImpl(classLoader, compositeURI); - } - - @Override - public SCANode2 createSCANodeFromURL(String configurationURI) { - return new NodeImpl(configurationURI); - } - - @Override - public SCANode2 createSCANode(String compositeURI, SCAContribution... contributions) { - return new NodeImpl(compositeURI, contributions); - } - - @Override - public SCANode2 createSCANode(String compositeURI, String compositeContent, SCAContribution... contributions) { - return new NodeImpl(compositeURI, compositeContent, contributions); - } - -} diff --git a/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java b/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java deleted file mode 100644 index 835829db1a..0000000000 --- a/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/NodeImpl.java +++ /dev/null @@ -1,813 +0,0 @@ -/* -* Licensed to the Apache Software Foundation (ASF) under one -* or more contributor license agreements. See the NOTICE file -* distributed with this work for additional information -* regarding copyright ownership. The ASF licenses this file -* to you under the Apache License, Version 2.0 (the -* "License"); you may not use this file except in compliance -* with the License. You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, -* software distributed under the License is distributed on an -* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -* KIND, either express or implied. See the License for the -* specific language governing permissions and limitations -* under the License. -*/ - -package org.apache.tuscany.sca.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.SCANode2; -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 SCANode2, 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 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 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); - } - } - - 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() { - 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 (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() { - 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 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 localContributions = localContributions(); - - // Load the specified contributions - ContributionService contributionService = runtime.getContributionService(); - contributions = new ArrayList(); - 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 deployables = new ArrayList(); - 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 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 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 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 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 > R cast(B target) throws IllegalArgumentException { - return (R)runtime.getProxyFactory().cast(target); - } - - public B getService(Class businessInterface, String serviceName) { - - ServiceReference serviceReference = getServiceReference(businessInterface, serviceName); - if (serviceReference == null) { - throw new ServiceRuntimeException("Service not found: " + serviceName); - } - return serviceReference.getService(); - } - - public ServiceReference getServiceReference(Class businessInterface, String name) { - - // Extract the component name - String componentName; - String serviceName; - int i = name.indexOf('/'); - if (i != -1) { - componentName = name.substring(0, i); - serviceName = name.substring(i + 1); - - } else { - componentName = name; - serviceName = null; - } - - // Lookup the component - 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() + "." + 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 localContributions() { - Map localContributions = new HashMap(); - collectJARs(localContributions, Thread.currentThread().getContextClassLoader()); - return localContributions; - } - - /** - * Collect JARs on the classpath of a URLClassLoader - * @param urls - * @param cl - */ - private static void collectJARs(Map 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/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java b/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java deleted file mode 100644 index c9995d6024..0000000000 --- a/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBootStrapper.java +++ /dev/null @@ -1,385 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.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 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 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 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(); - 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); - UtilityExtensionPoint utilities = registry.getExtensionPoint(UtilityExtensionPoint.class); - InterfaceContractMapper mapper = utilities.getUtility(InterfaceContractMapper.class); - - //Create a composite builder - SCADefinitions aggregatedDefinitions = new SCADefinitionsImpl(); - for (SCADefinitions definition : ((List)policyDefinitions)) { - SCADefinitionsUtil.aggregateSCADefinitions(definition, aggregatedDefinitions); - } - compositeBuilder = - RuntimeBuilder.createCompositeBuilder(monitor, - assemblyFactory, - scaBindingFactory, - endpointFactory, - intentAttachPointTypeFactory, - 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 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 loadModules(ExtensionPointRegistry registry) throws ActivationException { - - // Load and instantiate the modules found on the classpath (or any registered ClassLoaders) - modules = new ArrayList(); - try { - Set moduleActivators = - ServiceDiscovery.getInstance().getServiceDeclarations(ModuleActivator.class); - Set moduleClasses = new HashSet(); - 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 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 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/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBuilder.java b/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBuilder.java deleted file mode 100644 index 98a44cef9e..0000000000 --- a/java/sca/modules/node2-impl/src/main/java/org/apache/tuscany/sca/node/impl/RuntimeBuilder.java +++ /dev/null @@ -1,261 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.node.impl; - -import java.io.IOException; -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.util.List; - -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLOutputFactory; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.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, - InterfaceContractMapper interfaceContractMapper, - SCADefinitions policyDefinitions) { - - return new CompositeBuilderImpl(assemblyFactory, endpointFactory, scaBindingFactory, - intentAttachPointTypeFactory, 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 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() { - 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() { - 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); - documentProcessors.addArtifactProcessor(new CompositeDocumentProcessor(staxProcessor, validatingInputFactory, - 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/java/sca/modules/node2-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.SCANode2Factory b/java/sca/modules/node2-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.SCANode2Factory deleted file mode 100644 index 800bdd84cc..0000000000 --- a/java/sca/modules/node2-impl/src/main/resources/META-INF/services/org.apache.tuscany.sca.node.SCANode2Factory +++ /dev/null @@ -1,17 +0,0 @@ -# Licensed to the Apache Software Foundation (ASF) under one -# or more contributor license agreements. See the NOTICE file -# distributed with this work for additional information -# regarding copyright ownership. The ASF licenses this file -# to you under the Apache License, Version 2.0 (the -# "License"); you may not use this file except in compliance -# with the License. You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, -# software distributed under the License is distributed on an -# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -# KIND, either express or implied. See the License for the -# specific language governing permissions and limitations -# under the License. -org.apache.tuscany.sca.node.impl.NodeFactoryImpl \ No newline at end of file diff --git a/java/sca/modules/node2-impl/src/test/java/hello/HelloWorld.java b/java/sca/modules/node2-impl/src/test/java/hello/HelloWorld.java deleted file mode 100644 index 2f519cb81d..0000000000 --- a/java/sca/modules/node2-impl/src/test/java/hello/HelloWorld.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package hello; - -import org.osoa.sca.annotations.Remotable; - -/** - * HelloWorld interface - */ -@Remotable -public interface HelloWorld { - String hello(String name); -} diff --git a/java/sca/modules/node2-impl/src/test/java/hello/HelloWorldImpl.java b/java/sca/modules/node2-impl/src/test/java/hello/HelloWorldImpl.java deleted file mode 100644 index c9a7560b12..0000000000 --- a/java/sca/modules/node2-impl/src/test/java/hello/HelloWorldImpl.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package hello; - -/** - * HelloWorldImpl - */ -public class HelloWorldImpl implements HelloWorld { - public String hello(String name) { - System.out.println("Hello: " + name); - return "Hello, " + name; - } -} diff --git a/java/sca/modules/node2-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java b/java/sca/modules/node2-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java deleted file mode 100644 index 38fe211e7d..0000000000 --- a/java/sca/modules/node2-impl/src/test/java/org/apache/tuscany/sca/node/impl/NodeImplTestCase.java +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * \"License\"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.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; - -/** - * - */ -public class NodeImplTestCase { - private static String composite = - "" - + " " - + " " - + " " - + " "; - - @Test - public void testNodeWithCompositeContent() { - SCANode2Factory factory = new NodeFactoryImpl(); - 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 = new NodeFactoryImpl(); - SCANode2 node = factory.createSCANode("HelloWorld.composite", composite); - testNode(node); - } - - @Test - public void testNodeWithoutCompositeURI() { - SCANode2Factory factory = new NodeFactoryImpl(); - 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 = 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(); - SCANode2 node = factory.createSCANode(compositeURI, contribution); - testNode(node); - } - - @Test - public void testNodeWithRelativeCompositeURI() { - SCANode2Factory factory = new NodeFactoryImpl(); - 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 = new NodeFactoryImpl(); - String compositeURI = "HelloWorld.composite"; - SCANode2 node = factory.createSCANode(compositeURI, new SCAContribution[0]); - testNode(node); - } - - @Test - public void testNodeWithClassLoader() { - SCANode2Factory factory = new NodeFactoryImpl(); - String compositeURI = "HelloWorld.composite"; - SCANode2 node = factory.createSCANodeFromClassLoader(compositeURI, HelloWorld.class.getClassLoader()); - testNode(node); - } - - @Test - public void testNodeWithClassLoaderAndNullComposite() { - SCANode2Factory factory = new NodeFactoryImpl(); - 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/java/sca/modules/node2-impl/src/test/resources/HelloWorld.composite b/java/sca/modules/node2-impl/src/test/resources/HelloWorld.composite deleted file mode 100644 index 9e3299d691..0000000000 --- a/java/sca/modules/node2-impl/src/test/resources/HelloWorld.composite +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - diff --git a/java/sca/modules/node2-impl/src/test/resources/META-INF/sca-contribution.xml b/java/sca/modules/node2-impl/src/test/resources/META-INF/sca-contribution.xml deleted file mode 100644 index 1d37bcebe0..0000000000 --- a/java/sca/modules/node2-impl/src/test/resources/META-INF/sca-contribution.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - diff --git a/java/sca/modules/node2-launcher-osgi/LICENSE b/java/sca/modules/node2-launcher-osgi/LICENSE deleted file mode 100644 index 6e529a25c4..0000000000 --- a/java/sca/modules/node2-launcher-osgi/LICENSE +++ /dev/null @@ -1,205 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - - diff --git a/java/sca/modules/node2-launcher-osgi/NOTICE b/java/sca/modules/node2-launcher-osgi/NOTICE deleted file mode 100644 index 1325efd8bf..0000000000 --- a/java/sca/modules/node2-launcher-osgi/NOTICE +++ /dev/null @@ -1,6 +0,0 @@ -${pom.name} -Copyright (c) 2005 - 2008 The Apache Software Foundation - -This product includes software developed by -The Apache Software Foundation (http://www.apache.org/). - diff --git a/java/sca/modules/node2-launcher-osgi/pom.xml b/java/sca/modules/node2-launcher-osgi/pom.xml deleted file mode 100644 index 3565aaf31a..0000000000 --- a/java/sca/modules/node2-launcher-osgi/pom.xml +++ /dev/null @@ -1,150 +0,0 @@ - - - - - 4.0.0 - - org.apache.tuscany.sca - tuscany-modules - 1.4-SNAPSHOT - ../pom.xml - - - tuscany-node2-launcher-osgi - Apache Tuscany SCA Node OSGi Launcher - - - - javax.servlet - servlet-api - 2.5 - provided - - - org.apache.felix - org.osgi.core - 1.0.1 - - - org.apache.felix - org.apache.felix.framework - 1.0.4 - compile - - - org.apache.felix - javax.servlet - - - - - org.apache.tuscany.sca - tuscany-implementation-node-runtime - 1.4-SNAPSHOT - test - - - org.apache.tuscany.sca - tuscany-extensibility-osgi - 1.4-SNAPSHOT - test - - - - org.apache.tuscany.sca - tuscany-contribution-osgi - 1.4-SNAPSHOT - test - - - - org.apache.tuscany.sca - tuscany-domain-manager - 1.4-SNAPSHOT - test - - - - org.apache.tuscany.sca - tuscany-binding-http-runtime - 1.4-SNAPSHOT - test - - - - org.apache.tuscany.sca - tuscany-implementation-java-runtime - 1.4-SNAPSHOT - test - - - - - - - - org.apache.maven.plugins - maven-dependency-plugin - 2.0 - - - copy-dependencies - process-test-resources - - copy-dependencies - - - ${project.build.directory}/tuscany/modules - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - org.apache.tuscany.sca.node.osgi.launcher.NodeMain - - - - - - - - - - diff --git a/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/Contribution.java b/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/Contribution.java deleted file mode 100644 index 0214d5185f..0000000000 --- a/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/Contribution.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.node.osgi.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/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/DomainManagerLauncher.java b/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/DomainManagerLauncher.java deleted file mode 100644 index 6c28ef8b28..0000000000 --- a/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/DomainManagerLauncher.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.node.osgi.launcher; - -import static org.apache.tuscany.sca.node.osgi.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 { - - private 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 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 createDomainManager(String rootDirectory) throws LauncherException { - return (T)domainManager(rootDirectory); - } - - public static void main(String[] args) throws Exception { - logger.info("Apache Tuscany SCA Domain Manager starting..."); - - // Create a domain manager - DomainManagerLauncher launcher = newInstance(); - Object domainManager = launcher.createDomainManager(); - - // Start the domain manager - 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 started."); - - logger.info("Press enter to shutdown."); - try { - System.in.read(); - } catch (IOException e) {} - - // Stop the domain manager - try { - domainManager.getClass().getMethod("stop").invoke(domainManager); - } catch (Exception e) { - logger.log(Level.SEVERE, "SCA Domain Manager could not be stopped", e); - throw e; - } - } -} diff --git a/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHost.java b/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHost.java deleted file mode 100644 index 0c54c89c40..0000000000 --- a/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHost.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.node.osgi.launcher; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.felix.framework.Felix; -import org.apache.felix.framework.cache.BundleCache; -import org.apache.felix.framework.util.FelixConstants; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleException; -import org.osgi.framework.Constants; - -/** - * - */ -public class FelixOSGiHost implements OSGiHost { - - private Felix felix; - private LauncherBundleActivator activator; - private ClassLoader tccl; - - private final static String systemPackages = - "org.osgi.framework; version=1.3.0," + "org.osgi.service.packageadmin; version=1.2.0, " - + "org.osgi.service.startlevel; version=1.0.0, " - + "org.osgi.service.url; version=1.0.0, " - + "org.osgi.util.tracker; version=1.3.2, " - + "javax.xml, " - + "javax.xml.datatype, " - + "javax.xml.namespace, " - + "javax.xml.parsers, " - + "javax.xml.transform, " - + "javax.xml.transform.dom, " - + "javax.xml.transform.sax, " - + "javax.xml.transform.stream, " - + "javax.xml.validation, " - + "javax.xml.xpath, " - // Force the classes to be imported from the system bundle - // + "javax.xml.stream, " - // + "javax.xml.stream.util, " - + "javax.sql," - + "org.w3c.dom, " - + "org.xml.sax, " - + "org.xml.sax.ext, " - + "org.xml.sax.helpers, " - + "javax.security.auth, " - + "javax.security.cert, " - + "javax.security.auth.login, " - + "javax.security.auth.callback, " - + "javax.naming, " - + "javax.naming.spi, " - + "javax.naming.directory, " - + "javax.management, " - + "javax.imageio, " - + "sun.misc, " - + "javax.net, " - + "javax.net.ssl, " - + "javax.crypto, " - + "javax.rmi, " - + "javax.transaction, " - + "javax.transaction.xa"; - - public LauncherBundleActivator getActivator() { - if (activator == null) { - activator = new LauncherBundleActivator(); - } - return activator; - } - - public void setActivator(LauncherBundleActivator activator) { - this.activator = activator; - } - - public BundleContext start() { - try { - startup(); - } catch (Exception e) { - throw new IllegalStateException(e); - } - BundleContext bundleContext = felix.getBundleContext(); - return bundleContext; - } - - public void stop() { - try { - shutdown(); - } catch (Exception e) { - throw new IllegalStateException(e); - } - } - - private void startup() throws BundleException { - if (felix != null) { - throw new IllegalStateException("Felix is already running."); - } - - // Create a configuration property map. - Map configMap = new HashMap(); - // Configure the Felix instance to be embedded. - configMap.put(FelixConstants.EMBEDDED_EXECUTION_PROP, "true"); - // Add core OSGi packages to be exported from the class path - // via the system bundle. - configMap.put(Constants.FRAMEWORK_SYSTEMPACKAGES, systemPackages); - // Explicitly specify the directory to use for caching bundles. - configMap.put(BundleCache.CACHE_PROFILE_DIR_PROP, "target/.felix"); - List list = new ArrayList(); - - list.add(getActivator()); - - // Now create an instance of the framework with - // our configuration properties and activator. - felix = new Felix(configMap, list); - - // Now start Felix instance. - felix.start(); - - tccl = Thread.currentThread().getContextClassLoader(); - Thread.currentThread().setContextClassLoader(getContextClassLoader(felix.getBundleContext())); - - } - - private ClassLoader getContextClassLoader(BundleContext bundleContext) { - for (Bundle b : bundleContext.getBundles()) { - if ("org.apache.tuscany.sca.extensibility.osgi".equals(b.getSymbolicName())) { - try { - b.start(); - Class discovererClass = b.loadClass("org.apache.tuscany.sca.extensibility.ServiceDiscovery"); - Method getter = discovererClass.getMethod("getServiceDiscoverer"); - Object discoverer = getter.invoke(null); - - Method getCL = discoverer.getClass().getMethod("getContextClassLoader"); - ClassLoader cl = (ClassLoader)getCL.invoke(discoverer); - return cl; - } catch (Exception e) { - throw new IllegalStateException(e); - } - } - } - return null; - } - - private void shutdown() throws BundleException { - if (felix != null) { - felix.stop(); - } - Thread.currentThread().setContextClassLoader(tccl); - } - -} diff --git a/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/JarFileFinder.java b/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/JarFileFinder.java deleted file mode 100644 index 38c7093a16..0000000000 --- a/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/JarFileFinder.java +++ /dev/null @@ -1,348 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.node.osgi.launcher; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FilenameFilter; -import java.io.IOException; -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.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.StringTokenizer; -import java.util.logging.Logger; - -/** - * - */ -public class JarFileFinder { - /** - * A file name filter used to filter JAR files. - */ - 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. - */ - static class WebAppJARFileNameFilter extends StandAloneJARFileNameFilter { - - 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; - } - } - - private static final Logger logger = Logger.getLogger(JarFileFinder.class.getName()); - - static final String TUSCANY_HOME = "TUSCANY_HOME"; - private static final String TUSCANY_PATH = "TUSCANY_PATH"; - - /** - * Collect JAR files in the given directory - * @param directory - * @param urls - * @param filter - * @throws MalformedURLException - */ - private static void collectJARFiles(File directory, List 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()); - } - } - } - - /** - * Collect JAR files under the given directory. - * - * @param directory - * @param jarDirectoryURLs - * @param jarURLs - * @param filter - * @throws MalformedURLException - */ - private static void collectJARFiles(String directory, - Set jarDirectoryURLs, - List 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); - } - } - } - - /** - * Returns a ClassLoader for the Tuscany runtime JARs. - * - * @param parentClassLoader - * @param filter - * - * @return - */ - public static List findJarFiles(File root, FilenameFilter filter) throws FileNotFoundException, - URISyntaxException, MalformedURLException { - - // Build list of runtime JARs - Set jarDirectoryURLs = new HashSet(); - List jarURLs = new ArrayList(); - - URL url = null; - if (root != null) { - url = root.toURI().toURL(); - } else { - // First determine the path to the launcher class - String resource = JarFileFinder.class.getName().replace('.', '/') + ".class"; - url = JarFileFinder.class.getClassLoader().getResource(resource); - if (url == null) { - throw new FileNotFoundException(resource); - } - - url = getContainer(url, 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 - if (url != null && "file".equals(url.getProtocol())) { - - 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 = getProperty(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 = getProperty(TUSCANY_PATH); - if (ext != null && ext.length() != 0) { - logger.fine(TUSCANY_PATH + ": " + ext); - String separator = getProperty("path.separator"); - for (StringTokenizer tokens = new StringTokenizer(ext, separator); tokens.hasMoreTokens();) { - collectJARFiles(tokens.nextToken(), jarDirectoryURLs, jarURLs, filter); - } - } - - return jarURLs; - - } - - static String getProperty(final String prop) { - return AccessController.doPrivileged(new PrivilegedAction() { - public String run() { - String value = System.getProperty(prop); - if (value == null || value.length() == 0) { - return System.getenv(prop); - } else { - return value; - } - } - }); - } - - private 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) { - 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); - } - } - - private static URL getContainer(URL resourceURL, String resourceName) { - URL root = null; - // "jar:file://....../something.jar!/a/b/c/app.composite" - try { - String url = resourceURL.toExternalForm(); - String protocol = resourceURL.getProtocol(); - if ("file".equals(protocol)) { - // directory contribution - if (url.endsWith("/" + resourceName)) { - final String location = url.substring(0, url.length() - resourceName.length() - 1); - // 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 { - root = AccessController.doPrivileged(new PrivilegedExceptionAction() { - public URL run() throws IOException { - return 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 - root = 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 - root = toFile(new URL(location)).toURI().toURL(); - - } else if (protocol != null && (protocol.equals("bundle") || protocol.equals("bundleresource"))) { - root = new URL(resourceURL.getProtocol(), resourceURL.getHost(), resourceURL.getPort(), "/"); - } - } catch (MalformedURLException mfe) { - throw new IllegalArgumentException(mfe); - } - return root; - } - -} diff --git a/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/LauncherBundleActivator.java b/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/LauncherBundleActivator.java deleted file mode 100644 index 13af11238e..0000000000 --- a/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/LauncherBundleActivator.java +++ /dev/null @@ -1,457 +0,0 @@ -package org.apache.tuscany.sca.node.osgi.launcher; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URI; -import java.net.URL; -import java.security.CodeSource; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.jar.Attributes; -import java.util.jar.JarEntry; -import java.util.jar.JarInputStream; -import java.util.jar.JarOutputStream; -import java.util.jar.Manifest; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; -import java.util.zip.ZipEntry; - -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleActivator; -import org.osgi.framework.BundleContext; -import org.osgi.framework.BundleEvent; -import org.osgi.framework.BundleListener; -import org.osgi.framework.Constants; - -/** - * Bundle activator which installs Tuscany modules and 3rd party jars into an OSGi runtime. - * - */ -public class LauncherBundleActivator implements BundleActivator, Constants, BundleListener { - private static Logger logger = Logger.getLogger(LauncherBundleActivator.class.getName()); - private static final String[] immutableJars = {"bcprov"}; - - private BundleContext bundleContext; - private List tuscanyBundles = new ArrayList(); - - private List jarFiles; - - public LauncherBundleActivator() { - super(); - } - - public LauncherBundleActivator(List jarFiles) { - super(); - this.jarFiles = jarFiles; - } - - public static String toString(Bundle b, boolean verbose) { - StringBuffer sb = new StringBuffer(); - sb.append(b.getBundleId()).append(" ").append(b.getSymbolicName()); - int s = b.getState(); - if ((s & Bundle.UNINSTALLED) != 0) { - sb.append(" UNINSTALLED"); - } - if ((s & Bundle.INSTALLED) != 0) { - sb.append(" INSTALLED"); - } - if ((s & Bundle.RESOLVED) != 0) { - sb.append(" RESOLVED"); - } - if ((s & Bundle.STARTING) != 0) { - sb.append(" STARTING"); - } - if ((s & Bundle.STOPPING) != 0) { - sb.append(" STOPPING"); - } - if ((s & Bundle.ACTIVE) != 0) { - sb.append(" ACTIVE"); - } - - if (verbose) { - sb.append(" ").append(b.getLocation()); - sb.append(" ").append(b.getHeaders()); - } - return sb.toString(); - } - - public void start(BundleContext bundleContext) throws Exception { - this.bundleContext = bundleContext; - this.bundleContext.addBundleListener(this); - installTuscany(bundleContext); - - for (Bundle b : bundleContext.getBundles()) { - try { - if ("org.apache.tuscany.sca.contribution.osgi".equals(b.getSymbolicName())) { - b.start(); - logger.info(toString(b, false) + " " + b.getState()); - break; - } - } catch (Exception e) { - logger.log(Level.SEVERE, e.getMessage(), e); - } - } - } - - public void stop(BundleContext bundleContext) throws Exception { - /* - for (Bundle bundle : tuscanyBundles) { - try { - bundle.stop(); - } catch (Exception e) { - logger.log(Level.SEVERE, e.getMessage(), e); - } - } - */ - - for (Bundle bundle : tuscanyBundles) { - try { - if (logger.isLoggable(Level.FINE)) { - logger.fine("Uninstalling bundle: " + toString(bundle, false)); - } - bundle.uninstall(); - } catch (Exception e) { - logger.log(Level.SEVERE, e.getMessage(), e); - } - } - this.bundleContext.removeBundleListener(this); - tuscanyBundles.clear(); - this.bundleContext = null; - } - - public void installTuscany(BundleContext bundleContext) { - long start = System.currentTimeMillis(); - - try { - - // FIXME: SDO bundles dont have the correct dependencies - System.setProperty("commonj.sdo.impl.HelperProvider", "org.apache.tuscany.sdo.helper.HelperProviderImpl"); - List urls = jarFiles; - if (urls == null) { - File tuscanyInstallDir = findTuscanyInstallDir(bundleContext.getBundle()); - - urls = JarFileFinder.findJarFiles(tuscanyInstallDir, new JarFileFinder.StandAloneJARFileNameFilter()); - } - - for (URL url : urls) { - File file = new File(url.toURI()); - if (file.getName().startsWith("org.apache.felix.") || file.getName().startsWith("org.osgi.")) { - continue; - } - try { - Bundle bundle = createAndInstallBundle(bundleContext, url); - } catch (Exception e) { - logger.log(Level.SEVERE, e.getMessage(), e); - } - } - - long end = System.currentTimeMillis(); - logger.info("Tuscany bundles are installed in " + (end - start) + " ms."); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - private File findTuscanyInstallDir(Bundle bundle) throws IOException { - String tuscanyDirName = JarFileFinder.getProperty(JarFileFinder.TUSCANY_HOME); - if (tuscanyDirName != null) { - File tuscanyInstallDir = new File(tuscanyDirName); - if (tuscanyInstallDir.exists() && tuscanyInstallDir.isDirectory()) - return tuscanyInstallDir; - } - - String location = bundle.getLocation(); - - if (location != null && location.startsWith("file:")) { - File file = new File(URI.create(location)); - File tuscanyInstallDir = file.getParentFile(); - if (tuscanyInstallDir.exists() && tuscanyInstallDir.isDirectory()) - return tuscanyInstallDir; - } - if (this.getClass().getProtectionDomain() != null) { - CodeSource codeSource = this.getClass().getProtectionDomain().getCodeSource(); - if (codeSource != null) { - try { - File tuscanyInstallDir = new File(codeSource.getLocation().toURI()); - if (tuscanyInstallDir.exists() && tuscanyInstallDir.isDirectory()) - return tuscanyInstallDir; - } catch (Exception e) { - // ignore - } - } - } - return null; - } - - public Bundle createAndInstallBundle(BundleContext bundleContext, URL bundleFile) throws Exception { - if (logger.isLoggable(Level.FINE)) { - logger.fine("Installing bundle: " + bundleFile); - } - long start = System.currentTimeMillis(); - - Manifest manifest = readManifest(bundleFile); - boolean isOSGiBundle = manifest != null && manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME) != null; - - if (!isOSGiBundle) { - manifest = updateBundleManifest(bundleFile, manifest); - } - - String symbolicName = manifest.getMainAttributes().getValue(BUNDLE_SYMBOLICNAME); - String version = manifest.getMainAttributes().getValue(BUNDLE_VERSION); - Bundle bundle = findBundle(bundleContext, symbolicName, version); - if (bundle != null) { - if (logger.isLoggable(Level.FINE)) { - logger.fine("Bundle is already installed: " + symbolicName); - } - return bundle; - } - - String bundleLocation = bundleFile.toString(); - InputStream inStream = null; - if (!isOSGiBundle) { - // We need to repackage the bundle - ByteArrayOutputStream out = new ByteArrayOutputStream(); - JarOutputStream jarOut = new JarOutputStream(out, manifest); - - String classpath = manifest.getMainAttributes().getValue("Bundle-ClassPath"); - boolean embedded = classpath != null && !classpath.trim().equals("."); - if (embedded) { - addFileToJar(bundleFile, jarOut); - } else { - copyJar(bundleFile, jarOut); - } - - jarOut.close(); - inStream = new ByteArrayInputStream(out.toByteArray()); - } else { - // The file itself is already a bundle - inStream = bundleFile.openStream(); - } - - try { - bundle = bundleContext.installBundle(bundleLocation, inStream); - if (logger.isLoggable(Level.FINE)) { - logger.fine("Bundle installed in " + (System.currentTimeMillis() - start) + " ms: " + bundleLocation); - } - tuscanyBundles.add(bundle); - return bundle; - } finally { - inStream.close(); - } - - } - - private Bundle findBundle(BundleContext bundleContext, String symbolicName, String version) { - Bundle[] bundles = bundleContext.getBundles(); - if (version == null) { - version = "0.0.0"; - } - for (Bundle b : bundles) { - String v = (String)b.getHeaders().get(BUNDLE_VERSION); - if (v == null) { - v = "0.0.0"; - } - if (b.getSymbolicName().equals(symbolicName) && (version.equals("0.0.0") || v.equals(version))) { - return b; - } - } - return null; - } - - private String getFileName(URL url) { - String name = url.getPath(); - int index = name.lastIndexOf('/'); - return name.substring(index + 1); - } - - private void addFileToJar(URL file, JarOutputStream jarOut) throws IOException { - JarEntry ze = new JarEntry(getFileName(file)); - jarOut.putNextEntry(ze); - InputStream inStream = file.openStream(); - copy(inStream, jarOut); - inStream.close(); - } - - private void copy(InputStream in, OutputStream out) throws IOException { - byte[] readBuf = new byte[4096]; - int bytesRead; - while ((bytesRead = in.read(readBuf)) > 0) { - out.write(readBuf, 0, bytesRead); - } - } - - private void copyJar(URL in, JarOutputStream jarOut) throws IOException { - JarInputStream jarIn = new JarInputStream(in.openStream()); - ZipEntry ze; - while ((ze = jarIn.getNextEntry()) != null) { - // Skip the MANIFEST.MF - if (ze.getName().equals("META-INF/MANIFEST.MF")) - continue; - jarOut.putNextEntry(ze); - copy(jarIn, jarOut); - } - jarIn.close(); - } - - private Manifest readManifest(URL jarFile) throws IOException { - JarInputStream jar = new JarInputStream(jarFile.openStream()); - // Read the Manifest from the jar file - Manifest manifest = jar.getManifest(); - jar.close(); - - if (manifest == null) { - // Create a new one if no Manifest is found - manifest = new Manifest(); - } - return manifest; - } - - private Manifest updateBundleManifest(URL jarFile, Manifest manifest) throws Exception { - - // Check if we have an associated .mf file - String name = jarFile.toString(); - int index = name.lastIndexOf('.'); - if (index != -1) { - URL mf = new URL(name.substring(0, index) + ".mf"); - try { - InputStream in = mf.openStream(); - manifest.read(in); - in.close(); - } catch (IOException e) { - // Ignore - } - } - - String jarFileName = getFileName(jarFile); - boolean isImmutableJar = false; - for (String immutableJar : immutableJars) { - if (jarFileName.startsWith(immutableJar)) { - isImmutableJar = true; - break; - } - } - - Attributes attributes = manifest.getMainAttributes(); - if (attributes.getValue(BUNDLE_SYMBOLICNAME) == null) { - String bundleSymbolicName = jarFileName; - if (bundleSymbolicName.endsWith(".jar")) { - bundleSymbolicName = bundleSymbolicName.substring(0, bundleSymbolicName.length() - 4); - } - attributes.putValue(BUNDLE_SYMBOLICNAME, bundleSymbolicName); - } else { - // Assume the jar is already a bundle - return null; - } - - if (attributes.getValue("Manifest-Version") == null) { - attributes.putValue("Manifest-Version", "1.0"); - } - - if (attributes.getValue(BUNDLE_MANIFESTVERSION) == null) { - attributes.putValue(BUNDLE_MANIFESTVERSION, "2"); - } - - if (isImmutableJar && attributes.getValue(BUNDLE_CLASSPATH) == null) { - attributes.putValue(BUNDLE_CLASSPATH, ".," + jarFileName); - } - - JarInputStream jar = new JarInputStream(jarFile.openStream()); - HashSet packages = getPackagesInJar(jarFileName, jar); - jar.close(); - String version = getJarVersion(jarFileName); - - // attributes.remove(new Attributes.Name("Require-Bundle")); - // attributes.remove(new Attributes.Name("Import-Package")); - - if (attributes.getValue(BUNDLE_VERSION) == null) { - attributes.putValue(BUNDLE_VERSION, version); - } - // Existing export statements in bundles may contain versions, so they should be used as is - // SDO exports are not sufficient, and should be changed - if (attributes.getValue(EXPORT_PACKAGE) == null || jarFileName.startsWith("tuscany-sdo-impl")) { - String pkgs = packagesToString(packages, version); - if (pkgs.length() > 0) { - attributes.putValue(EXPORT_PACKAGE, pkgs); - attributes.putValue(IMPORT_PACKAGE, packagesToString(packages, null)); - } - // attributes.putValue("Import-Package", packagesToString(packages, null)); - } - - attributes.putValue(DYNAMICIMPORT_PACKAGE, "*"); - return manifest; - } - - private HashSet getPackagesInJar(String bundleName, JarInputStream jar) throws Exception { - HashSet packages = new HashSet(); - ZipEntry entry; - while ((entry = jar.getNextEntry()) != null) { - String entryName = entry.getName(); - if (!entry.isDirectory() && entryName != null && entryName.length() > 0 && !entryName.startsWith(".") - // && !entryName.startsWith("META-INF") - && entryName.lastIndexOf("/") > 0) { - String pkg = entryName.substring(0, entryName.lastIndexOf("/")).replace('/', '.'); - packages.add(pkg); - - } - } - // FIXME: Split package - if (bundleName.startsWith("axis2-adb")) { - packages.remove("org.apache.axis2.util"); - } else if (bundleName.startsWith("axis2-codegen")) { - packages.remove("org.apache.axis2.wsdl"); - packages.remove("org.apache.axis2.wsdl.util"); - } else if (bundleName.startsWith("bsf-all")) { - packages.remove("org.mozilla.javascript"); - } - - return packages; - } - - private String packagesToString(HashSet packages, String version) { - - StringBuilder pkgBuf = new StringBuilder(); - for (String pkg : packages) { - if (pkgBuf.length() > 0) { - pkgBuf.append(','); - } - pkgBuf.append(pkg); - if (version != null && !pkg.startsWith("META-INF.")) { - pkgBuf.append(";version=\""); - pkgBuf.append(version); - pkgBuf.append('\"'); - } - } - return pkgBuf.toString(); - } - - private String getJarVersion(String bundleName) { - Pattern pattern = Pattern.compile("-([0-9.]+)"); - Matcher matcher = pattern.matcher(bundleName); - String version = "1.0.0"; - if (matcher.find()) { - version = matcher.group(); - if (version.endsWith(".")) { - version = version.substring(1, version.length() - 1); - } else { - version = version.substring(1); - } - } - return version; - } - - public BundleContext getBundleContext() { - return bundleContext; - } - - public void bundleChanged(BundleEvent event) { - } - -} diff --git a/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/LauncherException.java b/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/LauncherException.java deleted file mode 100644 index bf17222e34..0000000000 --- a/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/LauncherException.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.node.osgi.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/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeDaemonLauncher.java b/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeDaemonLauncher.java deleted file mode 100644 index f0e4e9da70..0000000000 --- a/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeDaemonLauncher.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.node.osgi.launcher; - -import static org.apache.tuscany.sca.node.osgi.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 { - - private 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 createNodeDaemon() throws LauncherException { - return (T)nodeDaemon(); - } - - public static void main(String[] args) throws Exception { - logger.info("Apache Tuscany SCA Node Daemon starting..."); - - // Create a node daemon - NodeDaemonLauncher launcher = newInstance(); - OSGiHost host = NodeLauncherUtil.startOSGi(); - - try { - Object daemon = launcher.createNodeDaemon(); - - // Start the node daemon - try { - daemon.getClass().getMethod("start").invoke(daemon); - } catch (Exception e) { - logger.log(Level.SEVERE, "SCA Node Daemon could not be started", e); - throw e; - } - logger.info("SCA Node Daemon started."); - - logger.info("Press enter to shutdown."); - try { - System.in.read(); - } catch (IOException e) { - } - - // Stop the node daemon - try { - daemon.getClass().getMethod("stop").invoke(daemon); - } catch (Exception e) { - logger.log(Level.SEVERE, "SCA Node Daemon could not be stopped", e); - throw e; - } - } finally { - NodeLauncherUtil.stopOSGi(host); - } - } - -} diff --git a/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncher.java b/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncher.java deleted file mode 100644 index 917838d521..0000000000 --- a/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncher.java +++ /dev/null @@ -1,143 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.node.osgi.launcher; - -import static org.apache.tuscany.sca.node.osgi.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 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 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 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: - *
    - *
  • This is a standalone application and there is a deployable composite file on the classpath. - *
  • There is only one contribution which contains the deployable composite file physically in its packaging hierarchy. - *
- * - * @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 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 starting..."); - - // Create a node - NodeLauncher launcher = newInstance(); - String configurationURI = args[0]; - logger.info("SCA Node configuration: " + configurationURI); - Object node = launcher.createNodeFromURL(configurationURI); - - // 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 started."); - - logger.info("Press enter to shutdown."); - try { - System.in.read(); - } catch (IOException e) {} - - // Stop the node - try { - node.getClass().getMethod("stop").invoke(node); - } catch (Exception e) { - logger.log(Level.SEVERE, "SCA Node could not be stopped", e); - throw e; - } - } - -} diff --git a/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherUtil.java b/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherUtil.java deleted file mode 100644 index 6aafbd91bf..0000000000 --- a/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherUtil.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.node.osgi.launcher; - -import java.lang.reflect.Constructor; -import java.util.logging.Level; - -/** - * 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 DOMAIN_MANAGER_LAUNCHER_BOOTSTRAP = - "org.apache.tuscany.sca.domain.manager.launcher.DomainManagerLauncherBootstrap"; - - private static final String NODE_IMPLEMENTATION_DAEMON_BOOTSTRAP = - "org.apache.tuscany.sca.implementation.node.launcher.NodeImplementationDaemonBootstrap"; - - private static final String NODE_IMPLEMENTATION_LAUNCHER_BOOTSTRAP = - "org.apache.tuscany.sca.implementation.node.launcher.NodeImplementationLauncherBootstrap"; - - /** - * Collect JAR files under the given directory. - * - * @p @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 { - - // Use Java reflection to create the node as only the runtime class - // loader knows the runtime classes required by the node - String className = NODE_IMPLEMENTATION_LAUNCHER_BOOTSTRAP; - Class bootstrapClass; - bootstrapClass = Class.forName(className, false, tccl); - - 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); - try { - Class type = Class.forName("org.apache.tuscany.sca.node.SCANode2Factory"); - type = type.getDeclaredClasses()[0]; - return type.getMethod("createProxy", Class.class, Object.class).invoke(null, type, node); - } catch (ClassNotFoundException e) { - // Ignore - } - 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 { - - // Use Java reflection to create the node daemon as only the runtime class - // loader knows the runtime classes required by the node - String className = NODE_IMPLEMENTATION_DAEMON_BOOTSTRAP; - Class bootstrapClass; - bootstrapClass = Class.forName(className, false, tccl); - Object bootstrap = bootstrapClass.getConstructor().newInstance(); - - Object nodeDaemon = bootstrapClass.getMethod("getNode").invoke(bootstrap); - return nodeDaemon; - - } catch (Exception e) { - NodeLauncher.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 { - - // Use Java reflection to create the node daemon as only the runtime class - // loader knows the runtime classes required by the node - String className = DOMAIN_MANAGER_LAUNCHER_BOOTSTRAP; - Class bootstrapClass; - bootstrapClass = Class.forName(className, false, tccl); - Constructor constructor = bootstrapClass.getConstructor(String.class); - Object bootstrap = constructor.newInstance(rootDirectory); - - Object domainManager = bootstrapClass.getMethod("getNode").invoke(bootstrap); - return domainManager; - - } catch (Exception e) { - NodeLauncher.logger.log(Level.SEVERE, "SCA Domain Manager could not be created", e); - throw new LauncherException(e); - } finally { - Thread.currentThread().setContextClassLoader(tccl); - } - } - - static OSGiHost startOSGi() { - OSGiHost host = new FelixOSGiHost(); - host.start(); - return host; - } - - static void stopOSGi(OSGiHost host) { - host.stop(); - } - -} diff --git a/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeMain.java b/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeMain.java deleted file mode 100644 index 445ea80786..0000000000 --- a/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeMain.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.node.osgi.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/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeServletFilter.java b/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeServletFilter.java deleted file mode 100644 index fcbe259dba..0000000000 --- a/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/NodeServletFilter.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.node.osgi.launcher; - -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 String NODE_WEB_APP_SERVLET_HOST = "org.apache.tuscany.sca.implementation.node.osgi.webapp.NodeWebAppServletHost"; - - private static final long serialVersionUID = 1L; - - 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 starting..."); - - try { - // Get the Tuscany runtime ClassLoader - ClassLoader tccl = Thread.currentThread().getContextClassLoader(); - - 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/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/OSGiHost.java b/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/OSGiHost.java deleted file mode 100644 index c5ea0439de..0000000000 --- a/java/sca/modules/node2-launcher-osgi/src/main/java/org/apache/tuscany/sca/node/osgi/launcher/OSGiHost.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.node.osgi.launcher; - -import org.osgi.framework.BundleContext; - -/** - * SPI to plug in OSGi implementations such as Equinox or Felix - */ -public interface OSGiHost { - BundleContext start(); - void stop(); -} diff --git a/java/sca/modules/node2-launcher-osgi/src/test/java/hello/HelloWorld.java b/java/sca/modules/node2-launcher-osgi/src/test/java/hello/HelloWorld.java deleted file mode 100644 index 2f519cb81d..0000000000 --- a/java/sca/modules/node2-launcher-osgi/src/test/java/hello/HelloWorld.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package hello; - -import org.osoa.sca.annotations.Remotable; - -/** - * HelloWorld interface - */ -@Remotable -public interface HelloWorld { - String hello(String name); -} diff --git a/java/sca/modules/node2-launcher-osgi/src/test/java/hello/HelloWorldImpl.java b/java/sca/modules/node2-launcher-osgi/src/test/java/hello/HelloWorldImpl.java deleted file mode 100644 index c9a7560b12..0000000000 --- a/java/sca/modules/node2-launcher-osgi/src/test/java/hello/HelloWorldImpl.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package hello; - -/** - * HelloWorldImpl - */ -public class HelloWorldImpl implements HelloWorld { - public String hello(String name) { - System.out.println("Hello: " + name); - return "Hello, " + name; - } -} diff --git a/java/sca/modules/node2-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHostTestCase.java b/java/sca/modules/node2-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHostTestCase.java deleted file mode 100644 index e5194d0e5f..0000000000 --- a/java/sca/modules/node2-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/FelixOSGiHostTestCase.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.node.osgi.launcher; - -import java.util.Dictionary; -import java.util.Enumeration; - -import junit.framework.Assert; - -import org.junit.Test; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleContext; - - -/** - * - */ -public class FelixOSGiHostTestCase { - @Test - public void testStartThenStop() { - FelixOSGiHost host = new FelixOSGiHost(); - BundleContext context = host.start(); - Assert.assertNotNull(context); - for (Bundle b : context.getBundles()) { - System.out.println(toString(b, false)); - } - host.stop(); - } - - @Test - public void testStartTwice() { - FelixOSGiHost host = new FelixOSGiHost(); - host.start(); - try { - host.start(); - Assert.fail(); - } catch (IllegalStateException e) { - Assert.assertTrue(IllegalStateException.class.isInstance(e.getCause())); - } finally { - host.stop(); - } - } - - public static String toString(Bundle b, boolean verbose) { - StringBuffer sb = new StringBuffer(); - sb.append(b.getBundleId()).append(" ").append(b.getSymbolicName()); - int s = b.getState(); - if ((s & Bundle.UNINSTALLED) != 0) { - sb.append(" UNINSTALLED"); - } - if ((s & Bundle.INSTALLED) != 0) { - sb.append(" INSTALLED"); - } - if ((s & Bundle.RESOLVED) != 0) { - sb.append(" RESOLVED"); - } - if ((s & Bundle.STARTING) != 0) { - sb.append(" STARTING"); - } - if ((s & Bundle.STOPPING) != 0) { - sb.append(" STOPPING"); - } - if ((s & Bundle.ACTIVE) != 0) { - sb.append(" ACTIVE"); - } - - sb.append(" ").append(b.getLocation()); - if (verbose) { - Dictionary dict = b.getHeaders(); - Enumeration keys = dict.keys(); - while (keys.hasMoreElements()) { - Object key = keys.nextElement(); - sb.append(" ").append(key).append("=").append(dict.get(key)); - } - } - return sb.toString(); - } -} diff --git a/java/sca/modules/node2-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherTestCase.java b/java/sca/modules/node2-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherTestCase.java deleted file mode 100644 index 4c8a7c4719..0000000000 --- a/java/sca/modules/node2-launcher-osgi/src/test/java/org/apache/tuscany/sca/node/osgi/launcher/NodeLauncherTestCase.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.node.osgi.launcher; - -import hello.HelloWorld; - -import org.apache.tuscany.sca.node.SCAClient; -import org.apache.tuscany.sca.node.SCANode2; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Ignore; -import org.junit.Test; - -/** - * - */ -public class NodeLauncherTestCase { - private static OSGiHost host; - - @BeforeClass - public static void setUp() { - System.setProperty("TUSCANY_HOME", "target/tuscany"); - host = NodeLauncherUtil.startOSGi(); - } - - @AfterClass - public static void tearDown() { - if (host != null) { - NodeLauncherUtil.stopOSGi(host); - } - - } - - @Test - public void testLaunch() throws Exception { - NodeLauncher launcher = NodeLauncher.newInstance(); - SCANode2 node = launcher.createNodeFromClassLoader("HelloWorld.composite", getClass().getClassLoader()); - node.start(); - - HelloWorld hw = ((SCAClient)node).getService(HelloWorld.class, "HelloWorld"); - hw.hello("OSGi"); - - node.stop(); - } - - @Test - @Ignore("contribution-osgi issue") - public void testLaunchDomain() throws Exception { - DomainManagerLauncher.main(new String[] {}); - } - -} diff --git a/java/sca/modules/node2-launcher-osgi/src/test/resources/HelloWorld.composite b/java/sca/modules/node2-launcher-osgi/src/test/resources/HelloWorld.composite deleted file mode 100644 index 9e3299d691..0000000000 --- a/java/sca/modules/node2-launcher-osgi/src/test/resources/HelloWorld.composite +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - diff --git a/java/sca/modules/node2-launcher-webapp/LICENSE b/java/sca/modules/node2-launcher-webapp/LICENSE deleted file mode 100644 index 6e529a25c4..0000000000 --- a/java/sca/modules/node2-launcher-webapp/LICENSE +++ /dev/null @@ -1,205 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - - diff --git a/java/sca/modules/node2-launcher-webapp/NOTICE b/java/sca/modules/node2-launcher-webapp/NOTICE deleted file mode 100644 index 1325efd8bf..0000000000 --- a/java/sca/modules/node2-launcher-webapp/NOTICE +++ /dev/null @@ -1,6 +0,0 @@ -${pom.name} -Copyright (c) 2005 - 2008 The Apache Software Foundation - -This product includes software developed by -The Apache Software Foundation (http://www.apache.org/). - diff --git a/java/sca/modules/node2-launcher-webapp/pom.xml b/java/sca/modules/node2-launcher-webapp/pom.xml deleted file mode 100644 index 5e09e9c58d..0000000000 --- a/java/sca/modules/node2-launcher-webapp/pom.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - 4.0.0 - - org.apache.tuscany.sca - tuscany-modules - 1.4-SNAPSHOT - ../pom.xml - - - tuscany-node2-launcher-webapp - war - Apache Tuscany SCA Node WebApp - - - - org.apache.tuscany.sca - tuscany-node2-launcher - 1.4-SNAPSHOT - runtime - - - - - - - - org.apache.felix - maven-bundle-plugin - - - - ${tuscany.version} - org.apache.tuscany.sca.node2.launcher.webapp - ${pom.name} - org.apache.tuscany.sca.node* - - - - - - - diff --git a/java/sca/modules/node2-launcher-webapp/src/main/webapp/META-INF/sca-contribution.xml b/java/sca/modules/node2-launcher-webapp/src/main/webapp/META-INF/sca-contribution.xml deleted file mode 100644 index 78bbebbb83..0000000000 --- a/java/sca/modules/node2-launcher-webapp/src/main/webapp/META-INF/sca-contribution.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - diff --git a/java/sca/modules/node2-launcher-webapp/src/main/webapp/WEB-INF/web.xml b/java/sca/modules/node2-launcher-webapp/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 6c2c943c99..0000000000 --- a/java/sca/modules/node2-launcher-webapp/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,41 +0,0 @@ - - - - - - - Apache Tuscany SCA Node - - - tuscany - org.apache.tuscany.sca.node.launcher.NodeServletFilter - - - - tuscany - /* - - - - index.jsp - - - diff --git a/java/sca/modules/node2-launcher-webapp/src/main/webapp/index.jsp b/java/sca/modules/node2-launcher-webapp/src/main/webapp/index.jsp deleted file mode 100644 index 3cc6c7b504..0000000000 --- a/java/sca/modules/node2-launcher-webapp/src/main/webapp/index.jsp +++ /dev/null @@ -1,27 +0,0 @@ -<%-- - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. ---%> - -<%@ page contentType="text/html;charset=UTF-8" language="java" %> - -Apache Tuscany SCA Node - - -

It works!

- - diff --git a/java/sca/modules/node2-launcher/LICENSE b/java/sca/modules/node2-launcher/LICENSE deleted file mode 100644 index 6e529a25c4..0000000000 --- a/java/sca/modules/node2-launcher/LICENSE +++ /dev/null @@ -1,205 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - - - diff --git a/java/sca/modules/node2-launcher/NOTICE b/java/sca/modules/node2-launcher/NOTICE deleted file mode 100644 index 1325efd8bf..0000000000 --- a/java/sca/modules/node2-launcher/NOTICE +++ /dev/null @@ -1,6 +0,0 @@ -${pom.name} -Copyright (c) 2005 - 2008 The Apache Software Foundation - -This product includes software developed by -The Apache Software Foundation (http://www.apache.org/). - diff --git a/java/sca/modules/node2-launcher/pom.xml b/java/sca/modules/node2-launcher/pom.xml deleted file mode 100644 index 6833e13c4f..0000000000 --- a/java/sca/modules/node2-launcher/pom.xml +++ /dev/null @@ -1,72 +0,0 @@ - - - - - 4.0.0 - - org.apache.tuscany.sca - tuscany-modules - 1.4-SNAPSHOT - ../pom.xml - - - tuscany-node2-launcher - Apache Tuscany SCA Node Launcher - - - - javax.servlet - servlet-api - 2.4 - provided - - - - - - - org.apache.maven.plugins - maven-jar-plugin - - - - org.apache.tuscany.sca.node.launcher.NodeMain - - - - - - - org.apache.felix - maven-bundle-plugin - - - - ${tuscany.version} - org.apache.tuscany.sca.node2.launcher - ${pom.name} - org.apache.tuscany.sca.node* - - - - - - - diff --git a/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/Contribution.java b/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/Contribution.java deleted file mode 100644 index 4f4f861e2f..0000000000 --- a/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/Contribution.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.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/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/DomainManagerLauncher.java b/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/DomainManagerLauncher.java deleted file mode 100644 index f0c0a0a2f4..0000000000 --- a/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/DomainManagerLauncher.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.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 { - - private 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 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 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 domain manager - DomainManagerLauncher launcher = newInstance(); - Object domainManager = launcher.createDomainManager(); - - // Start the domain manager - 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."); - - ShutdownThread hook = new ShutdownThread(domainManager); - Runtime.getRuntime().addShutdownHook(hook); - - logger.info("Press enter to shutdown."); - - try { - System.in.read(); - } catch (IOException e) { - - // Wait forever - Object lock = new Object(); - synchronized(lock) { - lock.wait(); - } - } - - stop(domainManager); - // Remove the hook - Runtime.getRuntime().removeShutdownHook(hook); - } - - private static void stop(Object domainManager) throws Exception { - // Stop the domain manager - if (domainManager == null) { - return; - } - 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 { - DomainManagerLauncher.stop(domainManager); - } catch (Exception e) { - // Ignore - } - } - } -} diff --git a/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/LauncherException.java b/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/LauncherException.java deleted file mode 100644 index 39e8d81139..0000000000 --- a/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/LauncherException.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tuscany.sca.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/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeDaemonLauncher.java b/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeDaemonLauncher.java deleted file mode 100644 index 2756bf2073..0000000000 --- a/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeDaemonLauncher.java +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.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 { - - private 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 createNodeDaemon() throws LauncherException { - return (T)nodeDaemon(); - } - - public static void main(String[] args) throws Exception { - logger.info("Apache Tuscany SCA Node Daemon starting..."); - - // Create a node daemon - NodeDaemonLauncher launcher = newInstance(); - Object daemon = launcher.createNodeDaemon(); - - // Start the node daemon - try { - daemon.getClass().getMethod("start").invoke(daemon); - } catch (Exception e) { - logger.log(Level.SEVERE, "SCA Node Daemon could not be started", e); - throw e; - } - logger.info("SCA Node Daemon started."); - - logger.info("Press enter to shutdown."); - try { - System.in.read(); - } catch (IOException e) { - - // Wait forever - Object lock = new Object(); - synchronized(lock) { - lock.wait(); - } - } - - // Stop the node daemon - try { - daemon.getClass().getMethod("stop").invoke(daemon); - } catch (Exception e) { - logger.log(Level.SEVERE, "SCA Node Daemon could not be stopped", e); - throw e; - } - } - -} diff --git a/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java b/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java deleted file mode 100644 index 44a5430976..0000000000 --- a/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncher.java +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.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 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 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 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: - *
    - *
  • This is a standalone application and there is a deployable composite file on the classpath. - *
  • There is only one contribution which contains the deployable composite file physically in its packaging hierarchy. - *
- * - * @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 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 starting..."); - - // Create a node - NodeLauncher launcher = newInstance(); - String configurationURI = args[0]; - logger.info("SCA Node configuration: " + configurationURI); - Object node = launcher.createNodeFromURL(configurationURI); - - // 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 started."); - - logger.info("Press enter to shutdown."); - try { - System.in.read(); - } catch (IOException e) { - - // Wait forever - Object lock = new Object(); - synchronized(lock) { - lock.wait(); - } - } - - // Stop the node - try { - node.getClass().getMethod("stop").invoke(node); - } catch (Exception e) { - logger.log(Level.SEVERE, "SCA Node could not be stopped", e); - throw e; - } - } - -} diff --git a/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java b/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java deleted file mode 100644 index 6d8bcbe65c..0000000000 --- a/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeLauncherUtil.java +++ /dev/null @@ -1,536 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.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 jarDirectoryURLs = new HashSet(); - List jarURLs = new ArrayList(); - - // 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 jarDirectoryURLs, List 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 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) { - NodeLauncher.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) { - NodeLauncher.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 findResources(String name) throws IOException { - Enumeration resources = super.findResources(name); - Enumeration parentResources = parent.getResources(name); - List allResources = new ArrayList(); - 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/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeMain.java b/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeMain.java deleted file mode 100644 index eafe4ddaa0..0000000000 --- a/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeMain.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.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/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.java b/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.java deleted file mode 100644 index ad4009a1e1..0000000000 --- a/java/sca/modules/node2-launcher/src/main/java/org/apache/tuscany/sca/node/launcher/NodeServletFilter.java +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tuscany.sca.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 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 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 = "org.apache.tuscany.sca.implementation.node.webapp.NodeWebAppServletHost"; - 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/java/sca/modules/pom.xml b/java/sca/modules/pom.xml index aed561953b..7628b7c7ea 100644 --- a/java/sca/modules/pom.xml +++ b/java/sca/modules/pom.xml @@ -151,11 +151,11 @@ implementation-xquery monitor monitor-logging - node2-api - node2-impl - node2-launcher - node2-launcher-osgi - node2-launcher-webapp + node-api + node-impl + node-launcher + node-launcher-osgi + node-launcher-webapp node-manager osgi-runtime policy diff --git a/java/sca/modules/runtime/pom.xml b/java/sca/modules/runtime/pom.xml index b1f427b8f4..cde7c627b8 100644 --- a/java/sca/modules/runtime/pom.xml +++ b/java/sca/modules/runtime/pom.xml @@ -198,13 +198,13 @@ org.apache.tuscany.sca - tuscany-node2-api + tuscany-node-api 1.4-SNAPSHOT org.apache.tuscany.sca - tuscany-node2-launcher + tuscany-node-launcher 1.4-SNAPSHOT diff --git a/java/sca/samples/calculator-distributed/pom.xml b/java/sca/samples/calculator-distributed/pom.xml index 2ca8407957..a0f04d4a1a 100644 --- a/java/sca/samples/calculator-distributed/pom.xml +++ b/java/sca/samples/calculator-distributed/pom.xml @@ -39,13 +39,13 @@ org.apache.tuscany.sca - tuscany-node2-api + tuscany-node-api 1.4-SNAPSHOT org.apache.tuscany.sca - tuscany-node2-launcher + tuscany-node-launcher 1.4-SNAPSHOT diff --git a/java/sca/samples/calculator-distributed/src/main/java/node/LaunchCalculatorNodeA.java b/java/sca/samples/calculator-distributed/src/main/java/node/LaunchCalculatorNodeA.java index 0025c85f79..3ff6c8969a 100644 --- a/java/sca/samples/calculator-distributed/src/main/java/node/LaunchCalculatorNodeA.java +++ b/java/sca/samples/calculator-distributed/src/main/java/node/LaunchCalculatorNodeA.java @@ -20,7 +20,7 @@ package node; import org.apache.tuscany.sca.node.SCAClient; -import org.apache.tuscany.sca.node.SCANode2; +import org.apache.tuscany.sca.node.SCANode; import org.apache.tuscany.sca.node.launcher.NodeLauncher; import org.osoa.sca.ServiceRuntimeException; @@ -29,7 +29,7 @@ import calculator.CalculatorService; public class LaunchCalculatorNodeA { public static void main(String[] args) throws Exception { - SCANode2 node = null; + SCANode node = null; try { NodeLauncher nodeLauncher = NodeLauncher.newInstance(); diff --git a/java/sca/samples/calculator-distributed/src/test/java/calculator/CalculatorDistributedTestCase.java b/java/sca/samples/calculator-distributed/src/test/java/calculator/CalculatorDistributedTestCase.java index 9c3f06ee53..2a6f3af002 100644 --- a/java/sca/samples/calculator-distributed/src/test/java/calculator/CalculatorDistributedTestCase.java +++ b/java/sca/samples/calculator-distributed/src/test/java/calculator/CalculatorDistributedTestCase.java @@ -22,8 +22,8 @@ package calculator; import junit.framework.Assert; import org.apache.tuscany.sca.node.SCAClient; -import org.apache.tuscany.sca.node.SCANode2; -import org.apache.tuscany.sca.node.SCANode2Factory; +import org.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.node.SCANodeFactory; import org.apache.tuscany.sca.node.launcher.DomainManagerLauncher; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -35,10 +35,10 @@ import org.junit.Test; */ public class CalculatorDistributedTestCase { - private static SCANode2 manager; - private static SCANode2 nodeA; - private static SCANode2 nodeB; - private static SCANode2 nodeC; + private static SCANode manager; + private static SCANode nodeA; + private static SCANode nodeB; + private static SCANode nodeC; private static CalculatorService calculatorService; @@ -53,7 +53,7 @@ public class CalculatorDistributedTestCase { manager = managerLauncher.createDomainManager(); manager.start(); - SCANode2Factory nodeFactory = SCANode2Factory.newInstance(); + SCANodeFactory nodeFactory = SCANodeFactory.newInstance(); nodeC = nodeFactory.createSCANodeFromURL("http://localhost:9990/node-config/NodeC"); nodeB = nodeFactory.createSCANodeFromURL("http://localhost:9990/node-config/NodeB"); nodeA = nodeFactory.createSCANodeFromURL("http://localhost:9990/node-config/NodeA"); diff --git a/java/sca/samples/calculator/pom.xml b/java/sca/samples/calculator/pom.xml index df2f8d93dd..4a2216c2e9 100644 --- a/java/sca/samples/calculator/pom.xml +++ b/java/sca/samples/calculator/pom.xml @@ -38,13 +38,13 @@ org.apache.tuscany.sca - tuscany-node2-api + tuscany-node-api 1.4-SNAPSHOT org.apache.tuscany.sca - tuscany-node2-impl + tuscany-node-impl 1.4-SNAPSHOT runtime diff --git a/java/sca/samples/calculator/src/main/java/calculator/CalculatorClient.java b/java/sca/samples/calculator/src/main/java/calculator/CalculatorClient.java index 6dc2cbbe6f..3b2966e96d 100644 --- a/java/sca/samples/calculator/src/main/java/calculator/CalculatorClient.java +++ b/java/sca/samples/calculator/src/main/java/calculator/CalculatorClient.java @@ -20,8 +20,8 @@ package calculator; import org.apache.tuscany.sca.node.SCAClient; -import org.apache.tuscany.sca.node.SCANode2; -import org.apache.tuscany.sca.node.SCANode2Factory; +import org.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.node.SCANodeFactory; /** * This client program shows how to create an SCA runtime, start it, @@ -30,8 +30,8 @@ import org.apache.tuscany.sca.node.SCANode2Factory; public class CalculatorClient { public static void main(String[] args) throws Exception { - SCANode2Factory factory = SCANode2Factory.newInstance(); - SCANode2 node = factory.createSCANodeFromClassLoader("Calculator.composite", CalculatorClient.class.getClassLoader()); + SCANodeFactory factory = SCANodeFactory.newInstance(); + SCANode node = factory.createSCANodeFromClassLoader("Calculator.composite", CalculatorClient.class.getClassLoader()); node.start(); CalculatorService calculatorService = ((SCAClient)node).getService(CalculatorService.class, "CalculatorServiceComponent"); diff --git a/java/sca/samples/calculator/src/test/java/calculator/CalculatorTestCase.java b/java/sca/samples/calculator/src/test/java/calculator/CalculatorTestCase.java index a723af10c6..1b7476534a 100644 --- a/java/sca/samples/calculator/src/test/java/calculator/CalculatorTestCase.java +++ b/java/sca/samples/calculator/src/test/java/calculator/CalculatorTestCase.java @@ -21,8 +21,8 @@ package calculator; import junit.framework.TestCase; import org.apache.tuscany.sca.node.SCAClient; -import org.apache.tuscany.sca.node.SCANode2; -import org.apache.tuscany.sca.node.SCANode2Factory; +import org.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.node.SCANodeFactory; /** * This shows how to test the Calculator service component. @@ -30,11 +30,11 @@ import org.apache.tuscany.sca.node.SCANode2Factory; public class CalculatorTestCase extends TestCase { private CalculatorService calculatorService; - private SCANode2 node; + private SCANode node; @Override protected void setUp() throws Exception { - SCANode2Factory factory = SCANode2Factory.newInstance(); + SCANodeFactory factory = SCANodeFactory.newInstance(); node = factory.createSCANodeFromClassLoader("Calculator.composite", getClass().getClassLoader()); node.start(); diff --git a/java/sca/samples/callback-ws-client/pom.xml b/java/sca/samples/callback-ws-client/pom.xml index 594ad10221..c45691febb 100644 --- a/java/sca/samples/callback-ws-client/pom.xml +++ b/java/sca/samples/callback-ws-client/pom.xml @@ -38,7 +38,7 @@ org.apache.tuscany.sca - tuscany-node2-impl + tuscany-node-impl 1.4-SNAPSHOT diff --git a/java/sca/samples/callback-ws-client/src/main/java/myapp/MyClientImpl.java b/java/sca/samples/callback-ws-client/src/main/java/myapp/MyClientImpl.java index 3d94973880..ece769236c 100644 --- a/java/sca/samples/callback-ws-client/src/main/java/myapp/MyClientImpl.java +++ b/java/sca/samples/callback-ws-client/src/main/java/myapp/MyClientImpl.java @@ -22,8 +22,8 @@ import myserver.MyService; import myserver.MyServiceCallback; import org.apache.tuscany.sca.node.SCAClient; -import org.apache.tuscany.sca.node.SCANode2; -import org.apache.tuscany.sca.node.SCANode2Factory; +import org.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.node.SCANodeFactory; import org.osoa.sca.annotations.Reference; import org.osoa.sca.annotations.Scope; import org.osoa.sca.annotations.Service; @@ -49,14 +49,14 @@ public class MyClientImpl implements MyClient, MyServiceCallback { } public static void main(String[] args) throws Exception { - SCANode2 node = SCANode2Factory.newInstance().createSCANodeFromClassLoader("myapp.composite", MyClientImpl.class.getClassLoader()); + SCANode node = SCANodeFactory.newInstance().createSCANodeFromClassLoader("myapp.composite", MyClientImpl.class.getClassLoader()); node.start(); run(node); System.out.println("Closing the domain"); node.stop(); } - public static void run(SCANode2 node) throws InterruptedException { + public static void run(SCANode node) throws InterruptedException { MyClient myClient = ((SCAClient)node).getService(MyClient.class, "MyClientComponent"); myClient.aClientMethod(); Thread.sleep(5000); // don't exit before callback arrives diff --git a/java/sca/samples/callback-ws-client/src/test/java/myapp/CallbackClientTestCase.java b/java/sca/samples/callback-ws-client/src/test/java/myapp/CallbackClientTestCase.java index f11b0adfe4..fb2f6952c4 100644 --- a/java/sca/samples/callback-ws-client/src/test/java/myapp/CallbackClientTestCase.java +++ b/java/sca/samples/callback-ws-client/src/test/java/myapp/CallbackClientTestCase.java @@ -18,8 +18,8 @@ */ package myapp; -import org.apache.tuscany.sca.node.SCANode2; -import org.apache.tuscany.sca.node.SCANode2Factory; +import org.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.node.SCANodeFactory; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -29,12 +29,12 @@ import org.junit.Test; */ public class CallbackClientTestCase { - private SCANode2 node; + private SCANode node; @Before public void startServer() throws Exception { try { - node = SCANode2Factory.newInstance().createSCANodeFromClassLoader(null, getClass().getClassLoader()); + node = SCANodeFactory.newInstance().createSCANodeFromClassLoader(null, getClass().getClassLoader()); node.start(); } catch (Exception ex) { System.out.println(ex.toString()); diff --git a/java/sca/samples/callback-ws-service/pom.xml b/java/sca/samples/callback-ws-service/pom.xml index 4036b3237a..789f981d49 100644 --- a/java/sca/samples/callback-ws-service/pom.xml +++ b/java/sca/samples/callback-ws-service/pom.xml @@ -38,7 +38,7 @@ org.apache.tuscany.sca - tuscany-node2-impl + tuscany-node-impl 1.4-SNAPSHOT diff --git a/java/sca/samples/callback-ws-service/src/main/java/myserver/CallbackServer.java b/java/sca/samples/callback-ws-service/src/main/java/myserver/CallbackServer.java index 9dfead61db..75ef05bc48 100644 --- a/java/sca/samples/callback-ws-service/src/main/java/myserver/CallbackServer.java +++ b/java/sca/samples/callback-ws-service/src/main/java/myserver/CallbackServer.java @@ -20,8 +20,8 @@ package myserver; import java.io.IOException; -import org.apache.tuscany.sca.node.SCANode2; -import org.apache.tuscany.sca.node.SCANode2Factory; +import org.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.node.SCANodeFactory; /** * This server program shows how to create and start an SCA runtime that @@ -31,7 +31,7 @@ public class CallbackServer { public static void main(String[] args) throws Exception { - SCANode2 node = SCANode2Factory.newInstance().createSCANodeFromClassLoader("callbackws.composite", null); + SCANode node = SCANodeFactory.newInstance().createSCANodeFromClassLoader("callbackws.composite", null); node.start(); try { diff --git a/java/sca/samples/callback-ws-service/src/test/java/myserver/CallbackServerTestCase.java b/java/sca/samples/callback-ws-service/src/test/java/myserver/CallbackServerTestCase.java index 4208f7f6b5..e87667cc3e 100644 --- a/java/sca/samples/callback-ws-service/src/test/java/myserver/CallbackServerTestCase.java +++ b/java/sca/samples/callback-ws-service/src/test/java/myserver/CallbackServerTestCase.java @@ -21,8 +21,8 @@ package myserver; import java.io.IOException; import java.net.Socket; -import org.apache.tuscany.sca.node.SCANode2; -import org.apache.tuscany.sca.node.SCANode2Factory; +import org.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.node.SCANodeFactory; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -32,11 +32,11 @@ import org.junit.Test; */ public class CallbackServerTestCase { - private SCANode2 node; + private SCANode node; @Before public void startServer() throws Exception { - node = SCANode2Factory.newInstance().createSCANodeFromClassLoader("callbackws.composite", null); + node = SCANodeFactory.newInstance().createSCANodeFromClassLoader("callbackws.composite", null); node.start(); } diff --git a/java/sca/samples/customer-dojo/build-dependency.xml b/java/sca/samples/customer-dojo/build-dependency.xml index 8b59283e03..789fa97324 100644 --- a/java/sca/samples/customer-dojo/build-dependency.xml +++ b/java/sca/samples/customer-dojo/build-dependency.xml @@ -49,6 +49,7 @@ + @@ -56,6 +57,8 @@ + + diff --git a/java/sca/samples/domain-management/pom.xml b/java/sca/samples/domain-management/pom.xml index d674decbce..781f77285a 100644 --- a/java/sca/samples/domain-management/pom.xml +++ b/java/sca/samples/domain-management/pom.xml @@ -86,13 +86,13 @@ org.apache.tuscany.sca - tuscany-node2-launcher + tuscany-node-launcher 1.4-SNAPSHOT org.apache.tuscany.sca - tuscany-node2-api + tuscany-node-api 1.4-SNAPSHOT diff --git a/java/sca/samples/domain-management/src/main/java/manager/DistributeAndRunComponents.java b/java/sca/samples/domain-management/src/main/java/manager/DistributeAndRunComponents.java index 7981cdb5c6..380d501ab5 100644 --- a/java/sca/samples/domain-management/src/main/java/manager/DistributeAndRunComponents.java +++ b/java/sca/samples/domain-management/src/main/java/manager/DistributeAndRunComponents.java @@ -71,7 +71,7 @@ import org.apache.tuscany.sca.implementation.node.builder.impl.NodeCompositeBuil 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.node.SCANode2; +import org.apache.tuscany.sca.node.SCANode; import org.apache.tuscany.sca.node.launcher.NodeLauncher; import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; import org.apache.tuscany.sca.workspace.Workspace; @@ -260,7 +260,7 @@ public class DistributeAndRunComponents { System.out.println(print(domainComposite)); // Now start our SCA nodes - List runtimeNodes = new ArrayList(); + List runtimeNodes = new ArrayList(); NodeLauncher launcher = NodeLauncher.newInstance(); for (Component node: cloudComposite.getComponents()) { @@ -286,7 +286,7 @@ public class DistributeAndRunComponents { Contribution dependency = dependencies.get(c); contributions[c] = new org.apache.tuscany.sca.node.launcher.Contribution(dependency.getURI(), dependency.getLocation()); } - SCANode2 runtimeNode = launcher.createNode("http://sample/" + node.getName(), print(runnable), contributions); + SCANode runtimeNode = launcher.createNode("http://sample/" + node.getName(), print(runnable), contributions); // Start the node runtimeNode.start(); @@ -296,7 +296,7 @@ public class DistributeAndRunComponents { System.out.println("Nodes are running, press enter to stop..."); System.in.read(); - for (SCANode2 runtimeNode: runtimeNodes) { + for (SCANode runtimeNode: runtimeNodes) { runtimeNode.stop(); } } diff --git a/java/sca/samples/store-distributed/pom.xml b/java/sca/samples/store-distributed/pom.xml index 5d2256b362..1cd493807e 100644 --- a/java/sca/samples/store-distributed/pom.xml +++ b/java/sca/samples/store-distributed/pom.xml @@ -39,13 +39,13 @@ org.apache.tuscany.sca - tuscany-node2-api + tuscany-node-api 1.4-SNAPSHOT org.apache.tuscany.sca - tuscany-node2-launcher + tuscany-node-launcher 1.4-SNAPSHOT diff --git a/java/sca/tools/maven/maven-osgi-junit/pom.xml b/java/sca/tools/maven/maven-osgi-junit/pom.xml index 5787873d62..278ef80f71 100644 --- a/java/sca/tools/maven/maven-osgi-junit/pom.xml +++ b/java/sca/tools/maven/maven-osgi-junit/pom.xml @@ -45,7 +45,7 @@ org.apache.tuscany.sca - tuscany-node2-launcher-osgi + tuscany-node-launcher-osgi 1.4-SNAPSHOT diff --git a/java/sca/tools/runtime-inspector/pom.xml b/java/sca/tools/runtime-inspector/pom.xml index 49807b209f..6c5e314e15 100644 --- a/java/sca/tools/runtime-inspector/pom.xml +++ b/java/sca/tools/runtime-inspector/pom.xml @@ -45,7 +45,7 @@ org.apache.tuscany.sca - tuscany-node2-impl + tuscany-node-impl 1.4-SNAPSHOT diff --git a/java/sca/tools/runtime-inspector/src/main/java/org/apache/tuscany/sca/tools/inspector/AssemblyInspector.java b/java/sca/tools/runtime-inspector/src/main/java/org/apache/tuscany/sca/tools/inspector/AssemblyInspector.java index 55f83f65b3..ff32d1b48f 100644 --- a/java/sca/tools/runtime-inspector/src/main/java/org/apache/tuscany/sca/tools/inspector/AssemblyInspector.java +++ b/java/sca/tools/runtime-inspector/src/main/java/org/apache/tuscany/sca/tools/inspector/AssemblyInspector.java @@ -18,35 +18,16 @@ */ package org.apache.tuscany.sca.tools.inspector; -import java.beans.BeanInfo; -import java.beans.IntrospectionException; -import java.beans.Introspector; -import java.beans.PropertyDescriptor; -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 javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLOutputFactory; 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.ModelFactoryExtensionPoint; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.node.SCANode2; +import org.apache.tuscany.sca.node.SCANode; import org.apache.tuscany.sca.node.impl.NodeImpl; -import org.w3c.dom.Node; /** @@ -55,7 +36,7 @@ import org.w3c.dom.Node; public class AssemblyInspector { - public String assemblyAsString(SCANode2 node) { + public String assemblyAsString(SCANode node) { StringBuffer assemblyString = new StringBuffer(); // get at the node internals diff --git a/java/sca/tools/runtime-inspector/src/main/java/org/apache/tuscany/sca/tools/inspector/RegistryInspector.java b/java/sca/tools/runtime-inspector/src/main/java/org/apache/tuscany/sca/tools/inspector/RegistryInspector.java index 823322daeb..283d5e3df9 100644 --- a/java/sca/tools/runtime-inspector/src/main/java/org/apache/tuscany/sca/tools/inspector/RegistryInspector.java +++ b/java/sca/tools/runtime-inspector/src/main/java/org/apache/tuscany/sca/tools/inspector/RegistryInspector.java @@ -23,8 +23,7 @@ import java.util.Map; import java.util.Set; import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.node.SCANode2; +import org.apache.tuscany.sca.node.SCANode; import org.apache.tuscany.sca.node.impl.NodeImpl; @@ -33,7 +32,7 @@ import org.apache.tuscany.sca.node.impl.NodeImpl; */ public class RegistryInspector { - public String registryAsString(SCANode2 node) { + public String registryAsString(SCANode node) { StringBuffer extensionPointRegistryString = new StringBuffer("Extension Point Registry \n"); // Get the interesting extension points out of the registry and print them out diff --git a/java/sca/tools/runtime-inspector/src/main/java/org/apache/tuscany/sca/tools/inspector/RuntimeInspector.java b/java/sca/tools/runtime-inspector/src/main/java/org/apache/tuscany/sca/tools/inspector/RuntimeInspector.java index a405264a0d..26080b2e12 100644 --- a/java/sca/tools/runtime-inspector/src/main/java/org/apache/tuscany/sca/tools/inspector/RuntimeInspector.java +++ b/java/sca/tools/runtime-inspector/src/main/java/org/apache/tuscany/sca/tools/inspector/RuntimeInspector.java @@ -35,7 +35,7 @@ import java.util.List; import java.util.Set; import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.node.SCANode2; +import org.apache.tuscany.sca.node.SCANode; import org.apache.tuscany.sca.node.impl.NodeImpl; import org.w3c.dom.Node; @@ -56,7 +56,7 @@ public class RuntimeInspector { } } - public String runtimeAsString(SCANode2 node) { + public String runtimeAsString(SCANode node) { StringBuffer assemblyString = new StringBuffer(); this.out = new PrintWriter(new OutputStreamWriter(System.out), true); diff --git a/java/sca/tools/runtime-inspector/src/test/java/calculator/CalculatorClient.java b/java/sca/tools/runtime-inspector/src/test/java/calculator/CalculatorClient.java index 614b56d489..8001ab7818 100644 --- a/java/sca/tools/runtime-inspector/src/test/java/calculator/CalculatorClient.java +++ b/java/sca/tools/runtime-inspector/src/test/java/calculator/CalculatorClient.java @@ -20,8 +20,8 @@ package calculator; import org.apache.tuscany.sca.node.SCAClient; -import org.apache.tuscany.sca.node.SCANode2; -import org.apache.tuscany.sca.node.SCANode2Factory; +import org.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.node.SCANodeFactory; /** * This client program shows how to create an SCA runtime, start it, @@ -30,7 +30,7 @@ import org.apache.tuscany.sca.node.SCANode2Factory; public class CalculatorClient { public static void main(String[] args) throws Exception { - SCANode2 node = SCANode2Factory.newInstance().createSCANodeFromClassLoader("Calculator.composite", CalculatorClient.class.getClassLoader()); + SCANode node = SCANodeFactory.newInstance().createSCANodeFromClassLoader("Calculator.composite", CalculatorClient.class.getClassLoader()); node.start(); CalculatorService calculatorService = diff --git a/java/sca/tools/runtime-inspector/src/test/java/org/apache/tuscany/sca/tools/inspector/RegistryInspectorTestCase.java b/java/sca/tools/runtime-inspector/src/test/java/org/apache/tuscany/sca/tools/inspector/RegistryInspectorTestCase.java index a8db7f73f3..0710b670cd 100644 --- a/java/sca/tools/runtime-inspector/src/test/java/org/apache/tuscany/sca/tools/inspector/RegistryInspectorTestCase.java +++ b/java/sca/tools/runtime-inspector/src/test/java/org/apache/tuscany/sca/tools/inspector/RegistryInspectorTestCase.java @@ -24,8 +24,8 @@ import junit.framework.TestCase; 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.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.node.SCANodeFactory; import calculator.CalculatorService; @@ -35,11 +35,11 @@ import calculator.CalculatorService; public class RegistryInspectorTestCase extends TestCase { private CalculatorService calculatorService; - private SCANode2 node; + private SCANode node; @Override protected void setUp() throws Exception { - SCANode2Factory nodeFactory = SCANode2Factory.newInstance(); + SCANodeFactory nodeFactory = SCANodeFactory.newInstance(); node = nodeFactory.createSCANode(new File("src/test/resources/Calculator.composite").toURL().toString(), new SCAContribution("TestContribution", new File("src/test/resources").toURL().toString())); diff --git a/java/sca/tutorials/store/catalog-webapp/pom.xml b/java/sca/tutorials/store/catalog-webapp/pom.xml index 49319381ac..80a8861a99 100644 --- a/java/sca/tutorials/store/catalog-webapp/pom.xml +++ b/java/sca/tutorials/store/catalog-webapp/pom.xml @@ -46,7 +46,7 @@ org.apache.tuscany.sca - tuscany-node2-api + tuscany-node-api 1.4-SNAPSHOT runtime @@ -59,7 +59,7 @@ org.apache.tuscany.sca - tuscany-node2-launcher + tuscany-node-launcher 1.4-SNAPSHOT runtime diff --git a/java/sca/tutorials/store/domain/pom.xml b/java/sca/tutorials/store/domain/pom.xml index 41ab070a0c..be3c8c38c9 100644 --- a/java/sca/tutorials/store/domain/pom.xml +++ b/java/sca/tutorials/store/domain/pom.xml @@ -38,7 +38,7 @@ org.apache.tuscany.sca - tuscany-node2-launcher + tuscany-node-launcher 1.4-SNAPSHOT diff --git a/java/sca/tutorials/store/store-client/launch/LaunchStoreClientNode.java b/java/sca/tutorials/store/store-client/launch/LaunchStoreClientNode.java index 8dd1429890..d1a9dfb36c 100644 --- a/java/sca/tutorials/store/store-client/launch/LaunchStoreClientNode.java +++ b/java/sca/tutorials/store/store-client/launch/LaunchStoreClientNode.java @@ -20,7 +20,7 @@ package launch; import org.apache.tuscany.sca.node.SCAClient; -import org.apache.tuscany.sca.node.SCANode2; +import org.apache.tuscany.sca.node.SCANode; import org.apache.tuscany.sca.node.launcher.NodeLauncher; import client.Shopper; @@ -29,7 +29,7 @@ public class LaunchStoreClientNode { public static void main(String[] args) throws Exception { NodeLauncher nodeLauncher = NodeLauncher.newInstance(); - SCANode2 storeClientNode = nodeLauncher.createNodeFromURL("http://localhost:9990/node-config/StoreClientNode"); + SCANode storeClientNode = nodeLauncher.createNodeFromURL("http://localhost:9990/node-config/StoreClientNode"); storeClientNode.start(); SCAClient client = (SCAClient)storeClientNode; diff --git a/java/sca/tutorials/store/store-client/pom.xml b/java/sca/tutorials/store/store-client/pom.xml index b7155ee8cd..bfcc1a912b 100644 --- a/java/sca/tutorials/store/store-client/pom.xml +++ b/java/sca/tutorials/store/store-client/pom.xml @@ -50,13 +50,13 @@ org.apache.tuscany.sca - tuscany-node2-launcher + tuscany-node-launcher 1.4-SNAPSHOT org.apache.tuscany.sca - tuscany-node2-api + tuscany-node-api 1.4-SNAPSHOT diff --git a/java/sca/tutorials/store/store-test/pom.xml b/java/sca/tutorials/store/store-test/pom.xml index 057d3713d8..7eb320a804 100644 --- a/java/sca/tutorials/store/store-test/pom.xml +++ b/java/sca/tutorials/store/store-test/pom.xml @@ -50,13 +50,13 @@ org.apache.tuscany.sca - tuscany-node2-launcher + tuscany-node-launcher 1.4-SNAPSHOT org.apache.tuscany.sca - tuscany-node2-api + tuscany-node-api 1.4-SNAPSHOT diff --git a/java/sca/tutorials/store/store-test/test/StoreSupplierTestCase.java b/java/sca/tutorials/store/store-test/test/StoreSupplierTestCase.java index 26d3d49b78..5efec4ee2c 100644 --- a/java/sca/tutorials/store/store-test/test/StoreSupplierTestCase.java +++ b/java/sca/tutorials/store/store-test/test/StoreSupplierTestCase.java @@ -23,7 +23,7 @@ import junit.framework.Assert; import junit.framework.TestCase; import org.apache.tuscany.sca.node.SCAClient; -import org.apache.tuscany.sca.node.SCANode2; +import org.apache.tuscany.sca.node.SCANode; import org.apache.tuscany.sca.node.launcher.DomainManagerLauncher; import org.apache.tuscany.sca.node.launcher.NodeLauncher; import org.junit.After; @@ -40,10 +40,10 @@ import client.Shopper; */ public class StoreSupplierTestCase { - private SCANode2 domainManager; - private SCANode2 storeSupplierNode; - private SCANode2 storeCatalogsNode; - private SCANode2 storeClientNode; + private SCANode domainManager; + private SCANode storeSupplierNode; + private SCANode storeCatalogsNode; + private SCANode storeClientNode; @Before public void setup() throws Exception { diff --git a/java/sca/vtest/java-api/annotations/destroy/pom.xml b/java/sca/vtest/java-api/annotations/destroy/pom.xml index 9ace2399be..57477d1bbb 100644 --- a/java/sca/vtest/java-api/annotations/destroy/pom.xml +++ b/java/sca/vtest/java-api/annotations/destroy/pom.xml @@ -32,7 +32,7 @@ org.apache.tuscany.sca - tuscany-node2-impl + tuscany-node-impl 1.4-SNAPSHOT diff --git a/java/sca/vtest/java-api/annotations/destroy/src/test/java/org/apache/tuscany/sca/vtest/javaapi/annotations/destroy/DestroyAnnotationTestCase.java b/java/sca/vtest/java-api/annotations/destroy/src/test/java/org/apache/tuscany/sca/vtest/javaapi/annotations/destroy/DestroyAnnotationTestCase.java index 1d10679a8c..f3b2f28200 100644 --- a/java/sca/vtest/java-api/annotations/destroy/src/test/java/org/apache/tuscany/sca/vtest/javaapi/annotations/destroy/DestroyAnnotationTestCase.java +++ b/java/sca/vtest/java-api/annotations/destroy/src/test/java/org/apache/tuscany/sca/vtest/javaapi/annotations/destroy/DestroyAnnotationTestCase.java @@ -25,8 +25,8 @@ 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.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.node.SCANodeFactory; import org.junit.Test; import org.osoa.sca.ServiceRuntimeException; @@ -47,8 +47,8 @@ public class DestroyAnnotationTestCase { */ @Test public void atDestroyProper() throws Exception { - SCANode2Factory nodeFactory = SCANode2Factory.newInstance(); - SCANode2 node = nodeFactory.createSCANode(new File("src/main/resources/proper/AService.composite").toURL().toString(), + SCANodeFactory nodeFactory = SCANodeFactory.newInstance(); + SCANode node = nodeFactory.createSCANode(new File("src/main/resources/proper/AService.composite").toURL().toString(), new SCAContribution("TestContribution", new File("src/main/resources/proper").toURL().toString())); node.start(); @@ -69,9 +69,9 @@ public class DestroyAnnotationTestCase { */ @Test public void atDestroyProtectedMethod() throws Exception { - SCANode2Factory nodeFactory = SCANode2Factory.newInstance(); + SCANodeFactory nodeFactory = SCANodeFactory.newInstance(); try { - SCANode2 node = nodeFactory.createSCANode(new File("src/main/resources/err1/AServiceErr1.composite").toURL().toString(), + SCANode node = nodeFactory.createSCANode(new File("src/main/resources/err1/AServiceErr1.composite").toURL().toString(), new SCAContribution("TestContribution", new File("src/main/resources/err1").toURL().toString())); Assert.fail(); @@ -94,9 +94,9 @@ public class DestroyAnnotationTestCase { */ @Test public void atDestroyPrivateMethod() throws Exception { - SCANode2Factory nodeFactory = SCANode2Factory.newInstance(); + SCANodeFactory nodeFactory = SCANodeFactory.newInstance(); try { - SCANode2 node = nodeFactory.createSCANode(new File("src/main/resources/err2/AServiceErr2.composite").toURL().toString(), + SCANode node = nodeFactory.createSCANode(new File("src/main/resources/err2/AServiceErr2.composite").toURL().toString(), new SCAContribution("TestContribution", new File("src/main/resources/err2").toURL().toString())); Assert.fail(); @@ -119,9 +119,9 @@ public class DestroyAnnotationTestCase { */ @Test public void atDestroyNonVoidReturnType() throws Exception { - SCANode2Factory nodeFactory = SCANode2Factory.newInstance(); + SCANodeFactory nodeFactory = SCANodeFactory.newInstance(); try { - SCANode2 node = nodeFactory.createSCANode(new File("src/main/resources/err3/AServiceErr3.composite").toURL().toString(), + SCANode node = nodeFactory.createSCANode(new File("src/main/resources/err3/AServiceErr3.composite").toURL().toString(), new SCAContribution("TestContribution", new File("src/main/resources/err3").toURL().toString())); Assert.fail(); @@ -144,9 +144,9 @@ public class DestroyAnnotationTestCase { */ @Test public void atDestroyMethodWithArgs() throws Exception { - SCANode2Factory nodeFactory = SCANode2Factory.newInstance(); + SCANodeFactory nodeFactory = SCANodeFactory.newInstance(); try { - SCANode2 node = nodeFactory.createSCANode(new File("src/main/resources/err4/AServiceErr4.composite").toURL().toString(), + SCANode node = nodeFactory.createSCANode(new File("src/main/resources/err4/AServiceErr4.composite").toURL().toString(), new SCAContribution("TestContribution", new File("src/main/resources/err4").toURL().toString())); Assert.fail(); diff --git a/java/sca/vtest/java-api/annotations/init/pom.xml b/java/sca/vtest/java-api/annotations/init/pom.xml index 68e6052b04..b2393947f8 100644 --- a/java/sca/vtest/java-api/annotations/init/pom.xml +++ b/java/sca/vtest/java-api/annotations/init/pom.xml @@ -32,7 +32,7 @@ org.apache.tuscany.sca - tuscany-node2-impl + tuscany-node-impl 1.4-SNAPSHOT diff --git a/java/sca/vtest/java-api/annotations/init/src/test/java/org/apache/tuscany/sca/vtest/javaapi/annotations/init/InitAnnotationTestCase.java b/java/sca/vtest/java-api/annotations/init/src/test/java/org/apache/tuscany/sca/vtest/javaapi/annotations/init/InitAnnotationTestCase.java index 65ccc9838d..0dbccd8611 100644 --- a/java/sca/vtest/java-api/annotations/init/src/test/java/org/apache/tuscany/sca/vtest/javaapi/annotations/init/InitAnnotationTestCase.java +++ b/java/sca/vtest/java-api/annotations/init/src/test/java/org/apache/tuscany/sca/vtest/javaapi/annotations/init/InitAnnotationTestCase.java @@ -25,8 +25,8 @@ 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.apache.tuscany.sca.node.SCANode; +import org.apache.tuscany.sca.node.SCANodeFactory; import org.junit.Test; import org.osoa.sca.ServiceRuntimeException; @@ -50,8 +50,8 @@ public class InitAnnotationTestCase { */ @Test public void atInitProper() throws Exception { - SCANode2Factory nodeFactory = SCANode2Factory.newInstance(); - SCANode2 node = nodeFactory.createSCANode(new File("src/main/resources/proper/AService.composite").toURL().toString(), + SCANodeFactory nodeFactory = SCANodeFactory.newInstance(); + SCANode node = nodeFactory.createSCANode(new File("src/main/resources/proper/AService.composite").toURL().toString(), new SCAContribution("TestContribution", new File("src/main/resources/proper").toURL().toString())); node.start(); @@ -74,9 +74,9 @@ public class InitAnnotationTestCase { */ @Test public void atInitProtectedMethod() throws Exception { - SCANode2Factory nodeFactory = SCANode2Factory.newInstance(); + SCANodeFactory nodeFactory = SCANodeFactory.newInstance(); try { - SCANode2 node = nodeFactory.createSCANode(new File("src/main/resources/err1/AServiceErr1.composite").toURL().toString(), + SCANode node = nodeFactory.createSCANode(new File("src/main/resources/err1/AServiceErr1.composite").toURL().toString(), new SCAContribution("TestContribution", new File("src/main/resources/err1").toURL().toString())); Assert.fail(); @@ -100,9 +100,9 @@ public class InitAnnotationTestCase { */ @Test public void atInitPrivateMethod() throws Exception { - SCANode2Factory nodeFactory = SCANode2Factory.newInstance(); + SCANodeFactory nodeFactory = SCANodeFactory.newInstance(); try { - SCANode2 node = nodeFactory.createSCANode(new File("src/main/resources/err2/AServiceErr2.composite").toURL().toString(), + SCANode node = nodeFactory.createSCANode(new File("src/main/resources/err2/AServiceErr2.composite").toURL().toString(), new SCAContribution("TestContribution", new File("src/main/resources/err2").toURL().toString())); Assert.fail(); @@ -126,9 +126,9 @@ public class InitAnnotationTestCase { */ @Test public void atInitNonVoidReturnType() throws Exception { - SCANode2Factory nodeFactory = SCANode2Factory.newInstance(); + SCANodeFactory nodeFactory = SCANodeFactory.newInstance(); try { - SCANode2 node = nodeFactory.createSCANode(new File("src/main/resources/err3/HelloWorldErr3.composite").toURL().toString(), + SCANode node = nodeFactory.createSCANode(new File("src/main/resources/err3/HelloWorldErr3.composite").toURL().toString(), new SCAContribution("TestContribution", new File("src/main/resources/err3").toURL().toString())); Assert.fail(); @@ -152,9 +152,9 @@ public class InitAnnotationTestCase { */ @Test public void atInitMethodWithArgs() throws Exception { - SCANode2Factory nodeFactory = SCANode2Factory.newInstance(); + SCANodeFactory nodeFactory = SCANodeFactory.newInstance(); try { - SCANode2 node = nodeFactory.createSCANode(new File("src/main/resources/err4/HelloWorldErr4.composite").toURL().toString(), + SCANode node = nodeFactory.createSCANode(new File("src/main/resources/err4/HelloWorldErr4.composite").toURL().toString(), new SCAContribution("TestContribution", new File("src/main/resources/err4").toURL().toString())); Assert.fail(); -- cgit v1.2.3